D
Derek Gadd
Hi,
I want to use a function to populate some control form combo boxes on
a worksheet. However, I'm not sure how to pass the combo box name to
the function or even if this is the right approach. I suspect the line
where I define "MyCombo" is wrong but what should I have instead? My
code reads:
Sub xx()
MyCombo = Sheets("Entry sheet").ComboBox1
' Add unique items to dropdown box
Call FillCombo(MainCategory, MyCombo)
' etc
End Sub
And then my function:
Function FillCombo(Category As Collection, MyCombo As ComboBox)
Dim Item
With Sheets("Entry sheet").ComboBox1
.Clear
.AddItem "<All>"
For Each Item In Category
.AddItem Item
Next Item
.Text = "<All>"
End With
End Function
I want to use a function to populate some control form combo boxes on
a worksheet. However, I'm not sure how to pass the combo box name to
the function or even if this is the right approach. I suspect the line
where I define "MyCombo" is wrong but what should I have instead? My
code reads:
Sub xx()
MyCombo = Sheets("Entry sheet").ComboBox1
' Add unique items to dropdown box
Call FillCombo(MainCategory, MyCombo)
' etc
End Sub
And then my function:
Function FillCombo(Category As Collection, MyCombo As ComboBox)
Dim Item
With Sheets("Entry sheet").ComboBox1
.Clear
.AddItem "<All>"
For Each Item In Category
.AddItem Item
Next Item
.Text = "<All>"
End With
End Function