I have a listbox with 3 values and multi select option enabled. Based on the values selected, I want to populate a combobox by referring to certain ranges in excel sheet. The code below works if only one value is selected from listbox. I know it will not work for multiple selections, but I am unable to write code to loop through the list of selections and then add corresponding ranges to combo box.
So, if I select customer1 and customer2, i want the values in ranges d3:d34 AND c4:c24 populated in the combobox. similarly for other combinations too. However, if one of the values is unselected, corresponding values should be cleared from the combobox.
If I were to save all the selected items in listbox in an array, how do i do a "search" or "find" for each of the values stored in the array?
Please suggest how I could revise this code.
Thank you!
Private Sub Combobox1_DropButtonClick()
Dim curSelected As String
Dim i As Integer
For i = 0 To Listbox1.ListCount - 1
If Listbox1.Selected(i) Then
curSelected = Listbox1.List(i)
If curSelected = "customer1" Then
ChooseDeals.List = Sheets("Sheet3").Range("d4:d34").Value
ElseIf curSelected = "customer2" Then
ChooseDeals.List = Sheets("Sheet3").Range("c4:c24").Value
ElseIf curSelected = "customer3" Then
ChooseDeals.List = Sheets("Sheet3").Range("e4:e20").Value
End If
End If
Next i
End Sub