Why is text >5

dee101

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

Oaktree

MrExcel MVP
Joined
Jun 20, 2002
Messages
7,941
Try:

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

Joe4

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

Forum statistics

Threads
1,082,139
Messages
5,363,363
Members
400,731
Latest member
Jackserver

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top