2016-08-31 9 views
0

メインページのコンボボックスから選択した約130枚のブックがあります。私はコンボボックスに、シート名を持つ名前付き範囲からrowsourceを使用して値を設定します。リストからシート名の1つを選択するとうまくいきます。何も入力せずにsubmitを押すとうまく閉じます。私は、ユーザーがリストにない何かを入力するケースをカバーしたい。私はVBAに何か言ってみたい、sWが指定された範囲のものと等しくない場合は、「エラー」などのメッセージボックスを表示します。ここでは以下の私のコードは私のノートで、次のとおりです。コンボボックスのテキストがリストにないエラー処理VBA


'if submit button is pressed go to selected worksheet or close the userform: 
    Private Sub Submit_Click() 
    Dim sWs As String 
    'the string is the text from combobox, called 'Title', selected on front page: 
    sWs = Me.Title.Value 
     'if nothing is selected then close the userform: 
     If sWs = ("") Then 
     End 
     End If 
     'If an item is selected from the dropdown list then show that worksheet and close the userform: 
     Worksheets(sWs).Select 
     End 
     End Sub 

'If exit button is pressed close the userform: 
    Private Sub ExitButton_Click() 
    End 
    End Sub 

私は、ブールを使用する必要があると思うので、私はそれが偽のときに何をすべきかを指定しますが、どのように確認することはできません書いてください。申し訳ありませんが、私はちょっとした騒ぎです。

アイデア?

答えて

0

選択した項目のリストインデックスをチェックしてみ、-1何かを示すだろうがそれが有効ではありません入力された

'if submit button is pressed go to selected worksheet or close the userform: 

    Private Sub Submit_Click() 
    Dim sWs As String 

    'the string is the text from combobox, called 'Title', selected on front page: 
    If Me.Title.ListIndex = - 1 Then 
    MsgBox "Invalid Entry" 
    End 
    End If 

     sWs = Me.Title.Value 

     'if nothing is selected then close the userform: 
     If sWs = ("") Then 
     End 
     End If 

     'If an item is selected from the dropdown list then show that worksheet and close the userform: 
     Worksheets(sWs).Select 
     End 
     End Sub 

'If exit button is pressed close the userform: 
    Private Sub ExitButton_Click() 
    End 
    End Sub 
関連する問題