【问题】:我们在工作中,有时候要判断人家输入单元格是内容中的数据是首字母含有字母还是内容其中含有字母。
下面给出三个自定义函数,可以用
'函数1:判断输入的内容首字母是不是字母
Function 是否字母(ByVal n)
Dim iA As Integer
iA = Asc(n)
If (iA >= 65 And iA <= 90) Or (iA >= 97 And iA <= 122) Then
是否字母 = True
Else
是否字母 = False
End If
End Function
.
'函数2:判断输入的内容首字母是不是字母
Private Function isABC(ByVal a)
If a Like "[A-Za-z]*" Then
isABC = True
Else
isABC = False
End If
End Function
.
'函数3:判断输入的内容中是否含有字母
Private Function isABCin(a)
If a Like "*[A-Za-z]*" Then
isABCin = True
Else
isABCin = False
End If
End Function
=====下面是应用1====
Sub testFun()
Cells(1, 3) = isABC(Range("a1"))
Cells(2, 3) = 是否字母(Range("a1"))
Cells(3, 3) = isABCin(Range("a1"))
End Sub
=====下面是应用2====
Sub testFun()
Cells(1, 3) = isABC(Range("a1"))
Cells(2, 3) = 是否字母(Range("a1"))
Cells(3, 3) = isABCin(Range("a1"))
End Sub
=====下面是应用3====
Sub testFun2()
With Sheets("Sheet2")
If isABC(Range("a2")) Then
Debug.Print "程序继续"
Else
MsgBox "你输入的内容有误,将要退出程序"
Exit Sub
End If
End With
End Sub
====今天学习到此====