Why is text >5

dee101

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

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"

Oaktree

MrExcel MVP
Joined
Jun 20, 2002
Messages
8,053
Office Version
  1. 365
Try:

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

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
63,302
Office Version
  1. 365
Platform
  1. Windows
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...
 

juster21

Well-known Member
Joined
Jun 3, 2005
Messages
867
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.
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
63,302
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

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.
 

RalphA

Well-known Member
Joined
May 14, 2003
Messages
3,829
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.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,995
Messages
5,834,779
Members
430,321
Latest member
yemisimi11

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
Top