2014-02-07 52 views
1

我在VBA方面相當新穎,我有一個用戶表單,用戶可以從下拉菜單中選擇一個值,以從動態更改表中獲取其值。我需要添加驗證,以便用戶只能從動態表中選擇值,否則退出子。任何幫助將不勝感激,謝謝!向用戶表單添加驗證

Private Sub CommandButton1_Click() 

If ComboBox1.Text = "" Then MsgBox "Please Select a Version", vbOKOnly + vbExclamation, "Entry Error" 


Worksheets("New Revision ").Range("B6").Value = ComboBox1.Value 

Unload Me 



End Sub 

Private Sub UserForm_Initialize() 

    If Range("converter").Count = 1 Then 
     ComboBox1.Value = "01" 
    Else 
     ComboBox1.List = Application.Transpose(Range("converter")) 
    End If 



End Sub 

回答

0

我需要添加驗證,以便用戶只能從動態表

選擇的值,我認爲這是你想要的嗎?

設置ComboBoxfmStyleDropDownList

Private Sub UserForm_Initialize() 
    ComboBox1.Style = fmStyleDropDownList 
    If Range("converter").Count = 1 Then 
     ComboBox1.AddItem "0" 
    Else 
     ComboBox1.List = Application.Transpose(Range("converter")) 
    End If 
End Sub 

這種風格將確保用戶必須從列表中選擇一個項目。

+0

是的,這正是我需要的!謝謝! – user3281827

+0

歡迎您:) –