Function AllDigits(s)
AllDigits = s Like WorksheetFunction.Rept("[0-9]", Len(s))
End Function
Noting that you can use the # sign in place of [0-9] when searching for
digits, you do not have to call out to the Worksheet to use its REPT
function...
VB has the String function that you can use instead.
Function AllDigits(s)
AllDigits = s Like String(Len(s), "#")
End Function
If, however, you are more used to using [0-9] instead of the # sign and want
to continue doing so, you can still do this using native
VB functions
only...
Function AllDigits(s)
AllDigits = s Like Replace(String(Len(s), "x"), "x", "[0-9]")
End Function
where you can use any character in place of the "x" characters I used.
Because of this, we can simplify this code by using a space instead of the
"x" and then noting that
VB has a Space function which returns the number of
space specified in its argument...
Function AllDigits(s)
AllDigits = s Like Replace(Space(Len(s)), " ", "[0-9]")
End Function
--
Rick (MVP - Excel)
"Dana DeLouis" wrote in message
...
... all the character to be 0 - 9?
Hi. One of many ideas if you want to use 'Like'
Function AllDigits(s)
AllDigits = s Like WorksheetFunction.Rept("[0-9]", Len(s))
End Function
Sub TestIt()
Debug.Print AllDigits("123.45")
Debug.Print AllDigits("678")
End Sub
Returns:
False
True
= = = = = = =
HTH :)
Dana DeLouis
On 2/10/2010 12:21 PM, Dreiding wrote:
Using Excel 2003, here is example code that doesn't work. What am I
doing
wrong?
My isNumeric test returns "True", but there an "A" in my string.
Am I not checking for all the character to be 0 - 9?
Sub Test1()
Debug.Print isNumeric("A00101")
End Sub
Function isNumeric(ByVal sInput As String) As Boolean
If sInput Like "*[0-9]" Then
isNumeric = True
Else
isNumeric = False
End If
End Function
Thanks,
- Pat