Today’s post is about another very useful vba function called “IsNumeric” function. This function evaluates whether the argument is a number or not. So if all the characters are numeric then IsNumeric function will return True. If any character of the argument is not numeric then the function will return false. However the function will still return true if you use dot(.) as a decimal point or comma (,) as a thousand separator.
IsNumeric is a built-in VBA function. However it is not available in worksheets. You can only use it in the VBA programs. (In VBA editor)
The syntax of the function is as follows. There is one parameter for this function.
IsNumeric(chars)
Parameter is required.
IsNumeric function returns
True - If the argument can be evaluated as number
False - If the argument can not be evaluated as number.
Keep in mind that IsNumeric("4,56") will return true. But IsNumeric("4/56") or IsNumeric("4^56") will return false.
Now let’s look at some examples.
Example 1
Sub IsNumericFunctionExample1() Dim S As String S = "156" Debug.Print IsNumeric(S) End Sub |
Example 2
Sub IsNumericFunctionExamples2() Dim S As Variant S = "45.2" Debug.Print IsNumeric(S) End Sub |
Example 3
Sub IsNumericFunctionExample3() Dim S As String S = "www" Debug.Print IsNumeric(S) End Sub |
Example 4
Sub IsNumericFunctionExample4() Dim S As String S = "ww33w" Debug.Print IsNumeric(S) End Sub |
Example 5
Sub IsNumericFunctionExample5() Dim S As String S = "4,565" Debug.Print IsNumeric(S) End Sub |
Example 6
Sub IsNumericFunctionExample6() Dim S As String S = "4/56" Debug.Print IsNumeric(S) End Sub |