19

I have to find out if my cells text is a numeric value and wanted to use an elegant non VBA method that doesn't impede on its current state or value.

What I've found is that the ISNUMBER() function only works if the cells are number formatting or has no spaces if text formatting e.g.:

number as text examples

For the first three I've used =ISNUMBER(...) and my last attempt is =ISNUMBER(TRIM(...)).

The only method I've used that doesn't use VBA is to override my current values using text to columns then use the =ISNUMBER() function.

Note: I am proficient with VBA and Excel and understand I could create a user-defined function. But I don't want to as this imposes a macro required workbook or an add-in to be installed, which I can and have done in some cases.

I will appreciate any advice, thoughts (even if they tell me it can't be done) or VBA solutions (won’t be marked as answer however).

5
  • 4
    FWIW an alternative to ISNUMBER is the rarely used N. Something like this =NOT(ISERR(N(--A1)))
    – brettdj
    Apr 30, 2013 at 3:54
  • 1
    @brettdj thanks for that! For an answer that uses the least number of charaters and is quick and dirty I've now got =N(-A1). Didn't know that existed either.
    – glh
    Apr 30, 2013 at 4:00
  • What is the purpose of the hyphen(s) in front of the cell reference? And why do you each have a different number of hyphens? May 21, 2018 at 8:25
  • 1
    @youcantryreachingme it's a minus sign. it changes the sign of a number. It's an excel trick to automatically convert a numeric string into a numeral. I can't speak for brettdj but I'm guessing they used -- out of habit, as it's commonly used in more complex SUMPRODUCT formulations and things of that nature. using -- converts a numeric string to a number while preserving its sign (ie. positive numerals stay positive, negatives stay negative).
    – Alex M
    Oct 5, 2020 at 21:24
  • Thanks Alex. Cool trick. Oct 6, 2020 at 21:38

6 Answers 6

38

Try multiplying the cell value by 1, and then running the IsNumber and Trim functions, e.g.,:

=IsNumber(Trim(A1)*1)

3
  • 2
    +1 for speed and a good anwser. It sucks when things are right in your face but you can't see them!
    – glh
    Apr 30, 2013 at 1:23
  • 1
    Also I've found out that you dont even need to use trim. My regards.
    – glh
    Apr 30, 2013 at 1:24
  • 2
    @glh sometimes it just takes another set of eyes to see what's right in front of ya. :) Apr 30, 2013 at 1:27
5

Assuming the value you want to convert is in A1 you can use the following formula:

=ISNUMBER(VALUE(TRIM(CLEAN(A1)))

Here the functions clean and trim are removing whitespace and none printable characters. The function value converts a string to a number, and with the converted string we can check if the value is a number.

1
  • 4
    +1. As a quick and dirty I like =VALUE(A1) as my data won't have the need for CLEAN(). I didn't know the VALUE() function existed. Just to note the TRIM() does nothing as spaces are ignored anyway.
    – glh
    Apr 30, 2013 at 3:55
4

The shortest answer I've got to my question is:

=N(-A1)

Thanks brettdj

3

I know this post is old but I found this very useful in this case I had a formula that returned (333), even though it is a number and ISNUMBER will say it is a number even though I did not want an answer if it had characters other than digits. The following worked for me.

=IF(AND(ISNUMBER(--(MID(A1,ROW(INDIRECT("1:"&LEN(A1))),1)))),"Is Number","")

It works if there is ANY characters other than digits. If you just want a true false drop the IF

=AND(ISNUMBER(--(MID(A1,ROW(INDIRECT("1:"&LEN(A1))),1))))

As David Zemens stated

=IsNumber(Trim(A1)*1)

Works but if there is a "-" or the number is in parentheses it will say it is a number.

I hope this helps you or others.

0

if anyone needs to filter cells that contain anything that is not numeric:

=AND(SUMPRODUCT(--ISNUMBER(--MID(A1,ROW(INDIRECT("1:"&LEN(A1))),1)))=LEN(A1),A1<>"")

decimals and negatives result FALSE

0

I'm pretty late to the party, but, possibly the easiest, or shortest genuine test (note that the N function converts the number) is =ISNUMBER(--A1).

Using the examples you posted above...

Testing values using ISNUMBER

As with a lot of Excel shortcuts, the '--' forces Excel to assume the value afterward is a number, then all spaces are ignored. It's as if you had typed --123 directly into a box (-- obviously gives a positive number).

The third example also shows that other textual values in the string don't simply cause an error output for ISNUMBER.

Number ISNUMBER() Format Comments
123456 TRUE Numeric Plain number
123456 TRUE Text Number as text
123456A FALSE Text Number with 'A' tagged on the end
123456 TRUE Text Number prefixed with four spaces

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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