Public Function IsNumbersOnly(chkStr As String) As Boolean '检测字符串是否全部由数字组成 Dim i As Long Const AllNumbers = "0123456789" IsNumbersOnly = True For i = 1 To Len(chkStr) If InStr(AllNumbers, Mid(chkStr, i, 1)) = 0 Then IsNumbersOnly = False Exit Function End If Next i End Function
Public Function NumberPos(chkStr As String) As Long '检测字符串中第一个数字的位置 '函数值为0时,表示字符串中不包含数字 Dim i As Long For i = 1 To Len(chkStr) If Mid(chkStr, i, 1) Like "[0-9]" Then NumberPos = i Exit Function End If Next i End Function
Public Function NoNumbers(chkStr As String) As Boolean ' 检测字符串中是否不含数字 Dim i As Long NoNumbers = True For i = 1 To Len(chkStr) If Mid(chkStr, i, 1) Like "[0-9]" Then NoNumbers = False Exit Function End If Next i End Function
Public Function CutStr(chkStr As String) As String '截取字符串中第一个数字前的字符 Dim i As Long For i = 1 To Len(chkStr) If Mid(chkStr, i, 1) Like "[0-9]" Then CutStr = Left(chkStr, i - 1) Exit Function End If Next i CutStr = chkStr End Function