Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Logic test in "If then else" statement in error 1

Status
Not open for further replies.

dls999

Technical User
Dec 4, 2002
3
US
Hi,
I have written an "if then else" statement in VBA for Excel XP.

FR3, FR2 and FormL are String Variables

If FR3 = "$" Then
If FR2 > "M" Then
FormL = "N"
Else
FormL = "L"
End If
GoTo Skip_2nd_Test
End If

Assume FR3 = "$"

The problem is: if FR2 is defined as "a" or any letter that should be less than "M", or FALSE, it still falls through as TRUE. I can't figure it out. As I am stepping through the macro, I can put my cursor over the value and it will display what the computer sees it as. And it clearly shows FR2 = "a" and it compares it to "M", but still drops down to FormL = "N" instead of "L".

The same statements put in spreadsheet form work fine. Do you have any Ideas?

Thank you
Dan S.
dshinkel@tucsonelectric.com
 
The test in VBA is case-sensitive. the code for "a" is 97 while the code for "A" is 65. The code for "N" is 78.

So, "a" > "N" because 97 > 78
and &quot;A&quot; < &quot;N&quot; because 65 < 78

String comparisons in an Excel formula in cells are NOT case-sensitive. (Exception: See the EXACT function.)

 
If you use the 'Option Compare Text' statement at the start of your code module (in the declarations section) then the comparison is made non-case sensitive


________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top