Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 71
Default Adding won't work???

Hello Everyone,

I loaded up a few variables from some cells in a sheet. BAdult and BChild.
They contain numbers. But, when I put in this code to crosscheck that they
don't exceed a value of 12. It is not working because instead of adding
them, it puts them together.

If BAdult + BChild 20 Then MsgBox "Max people in Business Class is
12!", vbInformation, "Compartment Error": BAdult.SetFocus: Exit Sub

The values of BAdult is 6 and BChild is 8, it is bringing up the MsgBox
because it is saying the value is 68, instead of 14?? How can I add these
two variables instead of concanting them??


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 983
Default Adding won't work???

How are BAdult and BChild Declared. They should be
Dim BAdult as Integer
Dim BChild as Integer

If you have not declared them then by default they will be of type variant
which is not numeric. You could convert them to numbers using

CInt(BAdult) + CInt(BChild)

But you are better off to declare them explicitly with the Dim Statement.

"Michael Vaughan" wrote:

Hello Everyone,

I loaded up a few variables from some cells in a sheet. BAdult and BChild.
They contain numbers. But, when I put in this code to crosscheck that they
don't exceed a value of 12. It is not working because instead of adding
them, it puts them together.

If BAdult + BChild 20 Then MsgBox "Max people in Business Class is
12!", vbInformation, "Compartment Error": BAdult.SetFocus: Exit Sub

The values of BAdult is 6 and BChild is 8, it is bringing up the MsgBox
because it is saying the value is 68, instead of 14?? How can I add these
two variables instead of concanting them??



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Adding won't work???

Hi Michael,

How have you dimmed the BAdult and BChild variables?

I could concatenate if I dimmed them as strings; otherwise the expected sum
was returned.

---
Regards,
Norman



"Michael Vaughan" wrote in message
...
Hello Everyone,

I loaded up a few variables from some cells in a sheet. . They contain
numbers. But, when I put in this code to crosscheck that they don't
exceed a value of 12. It is not working because instead of adding them,
it puts them together.

If BAdult + BChild 20 Then MsgBox "Max people in Business Class is
12!", vbInformation, "Compartment Error": BAdult.SetFocus: Exit Sub

The values of BAdult is 6 and BChild is 8, it is bringing up the MsgBox
because it is saying the value is 68, instead of 14?? How can I add these
two variables instead of concanting them??




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Adding won't work???

Michael,

Did you use the Text property of the Range? If so, try the Value property
instead.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Michael Vaughan" wrote in message
...
Hello Everyone,

I loaded up a few variables from some cells in a sheet. BAdult and

BChild.
They contain numbers. But, when I put in this code to crosscheck that

they
don't exceed a value of 12. It is not working because instead of adding
them, it puts them together.

If BAdult + BChild 20 Then MsgBox "Max people in Business Class is
12!", vbInformation, "Compartment Error": BAdult.SetFocus: Exit Sub

The values of BAdult is 6 and BChild is 8, it is bringing up the MsgBox
because it is saying the value is 68, instead of 14?? How can I add these
two variables instead of concanting them??




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
adding time in a work schedule Chris Excel Worksheet Functions 5 April 30th 10 05:26 AM
Adding new work sheet to end of workbook Frank Driscoll Excel Discussion (Misc queries) 3 December 15th 08 05:47 PM
adding cells in different work sheets dmedina Excel Discussion (Misc queries) 3 October 18th 05 07:24 PM
Adding Work Days only in a function? Mark Excel Worksheet Functions 4 March 29th 05 03:50 AM
Excel 97 - Adding Every 8th Row - Formula should work, but doesn't Damaeus Excel Worksheet Functions 12 January 23rd 05 04:52 PM


All times are GMT +1. The time now is 05:50 AM.

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

About Us

"It's about Microsoft Excel"