robinsdale
Programmer
Hi, I have a Excel97 VBA form with a number of comboboxes that I want to populate with values in a sheet. My goal is to have one procedure to handle populating all of the comboboxes, which I would call with parameters such as:
1. name of the combobox to be populated
2. name of the sheet holding the values
Currently, the following code populates a specific combobox:
=============
CboItem.Clear
nSuppNum = .Range("A3"
.Value
With Sheets("Supplies"
.Select
If .Range("B5"
.Value = "" Then
CboItem.AddItem ("No Supplies Entered"
CboItem.Text = "No Supplies Entered"
Exit Function
End If
CboItem.Clear
nSuppNum = .Range("A3"
.Value
For i = 1 To nSuppNum
cRecRange = "B" & LTrim(Str(4 + i))
.Range(cRecRange).Select
If UCase(.Range(cRecRange).Value) <> "" Then
cSuppName = .Range(cRecRange).Value
CboItem.AddItem (cSuppName)
End If
Next
End With
==========
To create a common function for populating comboboxes, I would need to replace the word "CboItem" with a combobox name passed as a parameter. My Question: is this possible to do in VBA? The FAQ doesn't seem to have any solutions. In Visual FoxPro, I can do this using macro-expansion (the "&"
and a double period after the object name variable:
WITH THISFORM
.&cmCbo..DisplayValue = "Foobar"
ENDWITH
I apologize if I've asked a question previously dealt with...
Regards,
Robyn
1. name of the combobox to be populated
2. name of the sheet holding the values
Currently, the following code populates a specific combobox:
=============
CboItem.Clear
nSuppNum = .Range("A3"
With Sheets("Supplies"
.Select
If .Range("B5"
CboItem.AddItem ("No Supplies Entered"
CboItem.Text = "No Supplies Entered"
Exit Function
End If
CboItem.Clear
nSuppNum = .Range("A3"
For i = 1 To nSuppNum
cRecRange = "B" & LTrim(Str(4 + i))
.Range(cRecRange).Select
If UCase(.Range(cRecRange).Value) <> "" Then
cSuppName = .Range(cRecRange).Value
CboItem.AddItem (cSuppName)
End If
Next
End With
==========
To create a common function for populating comboboxes, I would need to replace the word "CboItem" with a combobox name passed as a parameter. My Question: is this possible to do in VBA? The FAQ doesn't seem to have any solutions. In Visual FoxPro, I can do this using macro-expansion (the "&"
WITH THISFORM
.&cmCbo..DisplayValue = "Foobar"
ENDWITH
I apologize if I've asked a question previously dealt with...
Regards,
Robyn