Adding won't work???

M

Michael Vaughan

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??
 
G

Guest

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.
 
N

Norman Jones

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.
 
B

Bob Phillips

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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top