# Why is text >5

#### dee101

##### Active Member
Why does this macro show the message box when text is put in cell A1
I did not think text is >5, do you have to check to see if A1 is a number first? If so how would you do it?
Thanks

Sub Macro1()
If Range("A1") > 5 Then
MsgBox "Greater than 5"
End If
End Sub

### Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Try:

If IsNumeric(Range("A1")) And Range("A1") > 5 Then MsgBox "Greater than 5"

I find this very interesting...

Does anyone have a technical explanation why Excel interprets text to be greater than 5?

Just trying to learn a little more how Excel thinks...

jmiskey said:
I find this very interesting...

Does anyone have a technical explanation why Excel interprets text to be greater than 5?

Just trying to learn a little more how Excel thinks...
The low-tech answer is Excel interprets the text as a number b/c of the math operator ">". Somewhere deep in the belly of Excel it makes the link between "A1" and ">5" and makes that numeric automatically. Sorry, but that's the best I can explain it.

The low-tech answer is Excel interprets the text as a number b/c of the math operator ">".
I don't think that is it. In playing around, it appears that in the grand scheme of things, Excel "orders" text after numbers.

For example, if you pick a column in Excel, and enter various numeric entries, and various text entries, and then sort it, you will see that all the numeric entries appear before the text entries.

So I guess it is just Excel's order of operation.

good point.

Thanks, that "fixed" it

Starting from ASCII character 0 (the NULL character), all the way to ASCII character 127, Excel sorts all the characters from character 0 to charaxxter 31, and character 127, first. Then, it sorts all the punctuation marks and other non-numeric and non-alphabetic charaxters, then, all the numerics (the ten digits, 0, 1, 2...9, and, finally, the 26 upper-case and the 26 lower-case letters of the alphabet. The letters are sorted in a non-case sensitive mode. For instance, if you sort A,B,a,c, you will get A,a,B,b. And, if you sort a,A,b,B, you will get a,A,b,B.

In closing, I don't know why Microsoft chose to go against the conventional method of sorting, stricktly in accordance with the ASCII code, and it was painful for me to find out this fact, through the help of others. So, I want to share this knowledge here. And, if anybody is really interested in doing the actual sort, send me a PM, include your email address, and I will get in touch with you on this.

Replies
7
Views
165
Replies
8
Views
149
Replies
4
Views
172
Replies
0
Views
107
Replies
12
Views
511

1,203,071
Messages
6,053,375
Members
444,658
Latest member
lhollingsworth

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

### Which adblocker are you using?

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

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