VBA interesting problem. 100 is not greater than 39

anxoperez

Active Member
Joined
Oct 3, 2007
Messages
254
I just spent 2 hours figuring out why excel Visual Basic considers 100 not greater than 39. I realized it is due to the fact that 100 has 3 digits and 39 has only 2.

If I write it as

"039"

Then excel DOES consider 100 greater than 039.

The problem is: now it considers 20 SMALLER than 039!

The solution to this problem would be to add a ZERO in front of all my 2-digit data. As you can imagine, that would be a huge endeavor and perhaps not even possible.

I think this is the wierdest problem. I hope someone can help.

here's the part of the code that applies:

If ActiveCell.Value = "" And ActiveCell.Offset(0, 1).Value > "039" Then
ActiveCell.Offset(0, 4).Select
 
You are testing these values, not as numbers, but as text.

If your values are text-formatted-numbers then it is testing the Length of the numbers,
not the values.

using the "+0" (without the quotes) makes Excel treat text as numbers (sometimes..).
 
Upvote 0

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top