Hey guys, what I'm trying to do is easy but I'm unsure as how to do it as I've never learnt VBA properly and I skipped all my readings on how to use loops! So I usually take the long way to do things, which for a vba expert would laugh at! Consider the code below. I have 27 combo boxes and I want all the combo boxes to populate data from a range. But I have to manually add this code to every single combo box which is timely. Is there a shorter way that could achieve what I'm after? I'm sure there is
ComboBox1.SetFocus
Dim c As Range
With Sheets("Sheet1")
For Each c In .Range("A:A", .Range("A" & Rows.Count).End(xlUp))
If c.Value <> "" Then ComboBox1.AddItem c.Value
Next c
End With
Dim c1 As Range
With Sheets("Sheet1")
For Each c1 In .Range("A:A", .Range("A" & Rows.Count).End(xlUp))
If c1.Value <> "" Then ComboBox2.AddItem c1.Value
Next c1
End With
Dim c2 As Range
With Sheets("Sheet1")
For Each c2 In .Range("A:A", .Range("A" & Rows.Count).End(xlUp))
If c2.Value <> "" Then ComboBox3.AddItem c2.Value
Next c2
End With
Dim c3 As Range
With Sheets("Sheet1")
For Each c3 In .Range("A:A", .Range("A" & Rows.Count).End(xlUp))
If c3.Value <> "" Then ComboBox4.AddItem c3.Value
Next c3
End With
I've just used 4 combo boxes as an example of what I'm doing, but surely there is a quicker way so I don't have to do this for all 27!
Please help