View Single Post
  #29   Report Post  
Posted to microsoft.public.excel.programming
Rick Rothstein \(MVP - VB\)[_1607_] Rick Rothstein \(MVP - VB\)[_1607_] is offline
external usenet poster
 
Posts: 1
Default Required Field for 7 Numeric digits only

' New Function to handle
Public Function MyNumeric(byval MyValue As String) As Boolean
Dim LoopCount As Long
MyNumeric = False
For LoopCount = 1 To Len(MyValue)
If Asc(Mid(MyValue, LoopCount, 1)) 48 And Asc(Mid(MyValue,
LoopCount, 1)) < 58 Then
MyNumeric = True
Else
MyNumeric = False
Exit For
End If
Next LoopCount
End Function


From one of my other posts in this thread (and noting that your MyNumeric
function is really a "digits only" function as, unlike the IsNumeric
function, it will not handle floating point values), here is a much shorter
equivalent function...

Function IsDigitsOnly(Value As String) As Boolean
IsDigitsOnly = Len(Value) 0 And Not Value Like "*[!0-9]*"
End Function

Oh, and one point about your function... it reports False if the value
passed into it contains a 0... I'm guessing you meant to write =48 rather
than 48 in your If-Then statement.

Rick