Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default Adding the values of 2 textboxes

I have textbox1 and textboxchange.
I have code which says:

Cells(1,2).value=textbox1 - textboxchange

This works fine, however this doesnt:
Cells(2,2).value=textbox1 + textboxchange

I simply get the value of textbox1 eg 23 plus the value of textbox change on
the end eg. if txtboxchange=3 the the result is 231.
I'm completly stumped by this. Thanks
--
Cheers,
Ben

Remove your.tonsils to reply
"You only live once but if you do it right once is enough!"


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default Adding the values of 2 textboxes

The + is concatenating the two values since the default
data type for a textbox is a string. You need to cast the
textbox value to a number. Try this...

Cells(2, 2).Value = CLng(textbox1) + CLng(textboxchange)
-----Original Message-----
I have textbox1 and textboxchange.
I have code which says:

Cells(1,2).value=textbox1 - textboxchange

This works fine, however this doesnt:
Cells(2,2).value=textbox1 + textboxchange

I simply get the value of textbox1 eg 23 plus the value

of textbox change on
the end eg. if txtboxchange=3 the the result is 231.
I'm completly stumped by this. Thanks
--
Cheers,
Ben

Remove your.tonsils to reply
"You only live once but if you do it right once is

enough!"


.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default Adding the values of 2 textboxes

As Melanie said...use CDbl rather than CLng
-----Original Message-----
The + is concatenating the two values since the default
data type for a textbox is a string. You need to cast

the
textbox value to a number. Try this...

Cells(2, 2).Value = CLng(textbox1) + CLng(textboxchange)
-----Original Message-----
I have textbox1 and textboxchange.
I have code which says:

Cells(1,2).value=textbox1 - textboxchange

This works fine, however this doesnt:
Cells(2,2).value=textbox1 + textboxchange

I simply get the value of textbox1 eg 23 plus the value

of textbox change on
the end eg. if txtboxchange=3 the the result is 231.
I'm completly stumped by this. Thanks
--
Cheers,
Ben

Remove your.tonsils to reply
"You only live once but if you do it right once is

enough!"


.

.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 88
Default Adding the values of 2 textboxes

Hi Ben,

Ben Allen wrote:
I have textbox1 and textboxchange.
I have code which says:

Cells(1,2).value=textbox1 - textboxchange

This works fine, however this doesnt:
Cells(2,2).value=textbox1 + textboxchange

I simply get the value of textbox1 eg 23 plus the value of textbox change on
the end eg. if txtboxchange=3 the the result is 231.
I'm completly stumped by this. Thanks


the values of the textbox are in the string format.
For calculation they must be converted with the
CDbl Function into numeric values.

Cells(1, 2).Value = CDbl(textbox1 ) - CDbl(textboxchange)
Cells(2, 2).Value = CDbl(textbox1 ) + CDbl(textboxchange)

--
Mit freundlichen Grüssen

Melanie Breden
- Microsoft MVP für Excel -

http://excel.codebooks.de (Das Excel-VBA Codebook)

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Axes values changes autmatically / textboxes lose formatting Anand Nichkaode Charts and Charting in Excel 5 March 28th 08 04:30 PM
Adding numerical values based on multiple values in another column Kazmaniac Excel Worksheet Functions 6 April 4th 07 08:53 PM
tab between several textboxes Kim Excel Worksheet Functions 0 May 9th 05 04:08 PM
textboxes libby Excel Programming 5 April 13th 04 06:32 PM
Add values of textboxes together Candee[_10_] Excel Programming 4 December 5th 03 07:05 PM


All times are GMT +1. The time now is 10:34 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"