<font face=Courier New>
' The same as IsNumeric() but skips the text like "1D2" and skips the boolean values.
' If NumOnly=True (default is False) then strings are not recognised as numeric at all.
' If UseComma=True (default is True) then comma can be the thousands separator in the text.
' Usage: Debug.Print IsNum("1,234"), IsNum("12,34"), IsNum("1,234,56"), IsNum("1,234,567.3")
Function IsNum(TxtOrNum, _
Optional NumOnly As Boolean = False, _
Optional UseComma As Boolean = True _
) As Boolean
Select Case VarType(TxtOrNum)
Case 2 To 6, 14
' Any type of numbers
IsNum = True
Case 8
' vbString
If Not NumOnly Then
If Len(TxtOrNum) > 40 Then Exit Function
If InStr(UCase(TxtOrNum), "D") > 0 Then Exit Function
Dim v, b As Boolean, iDot As Long, iComma As Long, d As Double
Static ThSep As String ' <- depends on localization
iDot = InStr(TxtOrNum, ".")
iComma = InStrRev(TxtOrNum, ",")
If iDot > 0 And iComma > iDot Then Exit Function
If UseComma Then
For Each v In Split(Mid$(TxtOrNum, 1, IIf(iDot > 0, iDot - 1, 40)), ",")
If b Then
If Len(v) <> 3 Or Not IsNumeric(v) Then Exit Function
Else
b = True
If Len(v) = 0 Or Not IsNumeric(v) Then Exit Function
End If
Next
Else
If iComma > 0 Then Exit Function
End If
' -> Use the localization language separators (can be skipped for US settings)
If iComma > 0 Then
If Len(ThSep) = 0 Then ThSep = Mid(Format(1000, "#,###"), 2, 1)
TxtOrNum = Replace(TxtOrNum, ",", ThSep)
End If
If iDot > 0 Then Mid$(TxtOrNum, iDot) = Mid(1.2, 2, 1)
' <-
On Error Resume Next
d = TxtOrNum
IsNum = Err = 0
End If
End Select
End Function</FONT>