Problem comparing 2 variables

Assamita

Board Regular
Joined
Sep 23, 2011
Messages
131
Hi. I have a macro that looks for 2 numbers and compare if they are the same.
It's failing and I'm not sure why. In order to test it I've added the following 2 message boxes:

MsgBox salesorder1 & "=" & salesorder2
MsgBox salesorder1 = salesorder2

And this is the result:

4mZEaAM.png


tslLIls.png


Why is it not identifying it as the same? both are assigned by a Range.Value method. salesorder2 is a number stored as text (aligned to the left, and requires a ' to vlookup it), and salesorder1 will usually have a ' at the front. I've tried both options with the same results.

Thank you
 
Last edited:

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
They may be different data types. Try the following:

Code:
MsgBox TypeName(salesorder1)
MsgBox TypeName(salesorder2)

If they're the same (and they're both strings) then it's possible salesorder2 has a trailing space - check that. This should yield a True however:

Code:
MsgBox Trim$(CStr(salesorder1)) = Trim$(CStr(salesorder2))

WBD
 
Upvote 0
They are both strings, if I use the ' in front of salesorder1. Your code worked, though, so I'll use that. Thank you very much.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,176
Members
453,021
Latest member
Justyna P

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