IsNumeric("5,4") returns TRUE.

Mackeral

Board Regular
Joined
Mar 7, 2015
Messages
237
Office Version
  1. 365
Platform
  1. Windows
I don't know why Isnumeric("5,4") is considered a number, but to fix it I wrote the following:
VBA Code:
Function Is_Numeric(Orig_To_Test) As Boolean
    ' Does "To_Test" a number?
    ' 1/21/12 Modified. WML
    ' 5/9/20 Add more test conditions. WML

    Prog = "Is_Numeric"
        
    To_Test = Orig_To_Test
    
    Knt = 0
    For I = 1 To Len(To_Test)
        Char = Mid(To_Test, I, 1)
        If Not (IsNumeric(Char) Or Char = ".") Then
            GoTo Error
        End If
        If Char = "." Then Knt = Knt + 1
    Next I

    Is_Numeric = True
    If Knt < 2 Then Exit Function
    
Error:
    IsNumeric = False
    Msg1 = "The Input String is NOT a number:"
    Msg2 = Quote(Orig_To_Test)
    Call Msg_Err(Prog, Msg1, Msg2, False)
    Stop
    
End Function ' Is_Number

You can mess around with how you handle the error message.
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
IsNumeric("3,4") is True for the same reason that IsNumeric("3,400") is True. It ignores thousands separators.

Does this function do what you want?
VBA Code:
Function Is_Numberic(aString As String, Optional NonNumericMessage As String = "") As Boolean
    Is_Numberic = Not (aString Like "*[!0-9.]*")
   
    Is_Numberic = Not CBool(InStr(1, Replace(aString, ".", vbNullString, , 1), ".")) Imp Is_Numberic

    If (Not Is_Numberic) And (NonNumericMessage <> vbNullString) Then
        MsgBox NonNumericMessage
    End If
End Function
 
Last edited:
Upvote 0
Perhaps ISNumber does what you want :
VBA Code:
Is_Numeric = Application.IsNumber(Orig_To_Test)
 
Upvote 0

Forum statistics

Threads
1,216,082
Messages
6,128,700
Members
449,464
Latest member
againofsoul

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