Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 50067

VBA Userform ComboBox: Content of ComboBox based off of Conditional Statement

$
0
0
I am looking to manipulate the content in the dropdown menu of a ComboBox. If x is 1, I want the content of the dropdown menu to be only "A". If x = 2, I want the content of the ComboBox to be "A" and "B". Etc. Any help????


Or.... is there a smarter way of doing this???


Private Sub UserForm_Initialize()
Dim x As Integer
x = Application.WorksheetFunction.CountIfs(Range("b3:b2002"), ComboBox2.Text)

With ComboBox1
If x >= 1 Then
ComboBox1.List = Array("A")
ElseIf x >= 2 Then
ComboBox1.List = Array("A", "B")
ElseIf x >= 3 Then
ComboBox1.List = Array("A", "B", "C")
End If
.ListIndex = -1
End With

With ComboBox2
.AddItem "1"
.AddItem "2"
.AddItem "3"
End With

End Sub

Viewing all articles
Browse latest Browse all 50067

Trending Articles