我有一个包含TextBox的userform。我创建了一个If
函数来验证用户是否输入了字母。我在代码上遇到运行时错误13。如果我能正确地做出if逻辑,请帮助我。
Private Sub cmd_Submit_Click()
'it will not accept any ASCII variables from 0 to 65
If Name_Box.Text < Asc(65) Then
MsgBox "Enter A to Z"
'Shall not contain any ASCII characters past 90
ElseIf Name_Box.Text > Asc(90) Then
MsgBox "Enter A to Z"
Else
End If
End Sub
答案 0 :(得分:1)
尝试此功能:
Private Sub cmd_Submit_Click()
For i = 1 To Len(Name_Box.Text)
If Asc(Mid(Name_Box.Text, i, 1)) < 65 Or Asc(Mid(Name_Box.Text, i, 1)) > 90 Then
MsgBox "Enter A to Z"
Exit For
End If
Next i
End Sub