Why is text >5

dee101

Active Member
Joined
Aug 21, 2004
Messages
282
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

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Try:

If IsNumeric(Range("A1")) And Range("A1") > 5 Then MsgBox "Greater than 5"
 
Upvote 0
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...
 
Upvote 0
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.
 
Upvote 0
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.
 
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,214,647
Messages
6,120,722
Members
448,987
Latest member
marion_davis

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