I am using a 'Generate' button on my worksheet. When I click on the button, a popup (form) come, which contains two comboboxes. Basis the selection in the first combobox, the second combobox option list is populated.
For the first combobox, when I hardcode the item values it works fine. The form code is as follows:
Private Sub UserForm_Initialize()
With ComboBox_DL
.AddItem "DL1"
.AddItem "DL2"
End With
End Sub
I tried to make this item list dynamic by fetching the combobox item values from a column the in the excel worksheet using the following form code:
Private Sub UserForm_Initialize()
With ComboBox_DL
For Each c In ActiveSheet.Range(Range("AE"), Range("AE").End(xlDown))
.AddItem c.Value
Next
End With
End Sub
But the above code throws error: Run time error '1004': Method 'Range' of object '_Global' failed
I modified the code adding sheet details:
With ComboBox_DL
For Each c In ThisWorkbook.Worksheets("Business_Input_Data").Range(Range("AE"), Range("AE").End(xlDown))
.AddItem c.Value
Next
It still throws the same error.
Can someone help please? Also, I want to know how to look up the values corresponding to the selection in combobox1 and populate the list in combobox2?