我試圖獲取一個輸入框來驗證用戶將輸入的條目。驗證輸入框的條目
我使用下面的腳本,但不能得到驗證工作,任何幫助將不勝感激。
Sub inputbox()
Dim Manager As Long
On Error Resume Next
Application.DisplayAlerts = False
Manager = Application.inputbox(Prompt:="Please enter a manager.", Title:="Pick A Manager Name", Type:=1)
On Error GoTo 0
Application.DisplayAlerts = True
If Manager = "" Then
Exit Sub
ElseIf Manager <> Ben, Cameron, Chris, Martin, Peter Then
MsgBox "Incorrect Name, pick a new one!"
Else
MsgBox "Your input was " & Manager
End If
End Sub
我喜歡使用數組,我應該抓住那個。您可以使用'If IsError(Application.Match(Trim(sTxt),aManagers,False))Then',如果條目不在數組中,則返回true。 – Simon1979
感謝您的提示!對於其他讀者:它應該是'Application.WorksheetFunction.Match()' – PatricK