IsNumeic("5,4") returns TRUE

Status
Not open for further replies.

Mackeral

Board Regular
Joined
Mar 7, 2015
Messages
232
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

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Please do not post the same question multiple times. Questions of a duplicate nature will be locked or deleted, per #12 of the Forum Rules and points 6 & 7 of the Guidelines.
 
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,215,446
Messages
6,124,900
Members
449,194
Latest member
JayEggleton

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