Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

How to compare string value in excel vba ? for example texbox1.text = A and textbox2.text = AAA, so texbox1.text < textbox2.text therefore msgbox will display A < AAA. how to achieve this ?

share|improve this question
 
What have you tried so far? You know you can do something like Msgbox textbox1.text & "<" & textbox2.text -- but you will need to make some If statements or other conditional logic to display the proper sign (<, >, or =). –  David Zemens 21 hours ago
 
Basically what I want is to compare 2 textbox value. If texbox1 value is smaller than texbox2 then a message box will show texbox1 value is less than textbox value. I know how to compare them if there are integer value however in this case the value is string and can be in the range of A - ZZZ. –  user1902849 21 hours ago
 
You can use the same logical operators on text strings, per my previous comment. For example, If textbox1.text < textboxt2.text Then ... etc. –  David Zemens 19 hours ago

1 Answer

Are the textbox strings in reference to Columns?

If so, you just need one If statement to check the condition:

Untested

If Columns(textbox1.Text).Column < Columns(textbox2.Text).Column Then
    Msgbox "" & UCase(textbox1.Text) & "<" & UCase(textbox2.Text) & ""
End If

You'd need to add some error handling though to handle situations where the text didn't match a column reference.

Also, if this is in reference to columns, in Excel 2010 the maximum column is XFD or column number 16,384...

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.