Question

I am fairly new at VBA and I have a userform that the user can select a value from a dropdown that gets its value from a dynamically changing table. I need to add validation so that the user can only select the values from the dynamic table, otherwise exit sub. Any help would be greatly appreciated thanks!

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 
Was it helpful?

Solution

I need to add validation so that the user can only select the values from the dynamic table

I think this is what you want?

Set the style of the ComboBox to fmStyleDropDownList

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

This will ensure that the user has to select an item from the list.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top