On a spreadsheet I am developing, I have placed four OLE ListBoxes. They are named, origianlly enough, lstData1 -> lstData4.
In my code, I would like to create an array that references these objects. The following code snippet works just fine:
Dim myListBoxes(4)
Set myListBoxes(1) = Worksheets("Control".lstData1
Set myListBoxes(2) = Worksheets("Control".lstData2
Set myListBoxes(3) = Worksheets("Control".lstData3
Set myListBoxes(4) = Worksheets("Control".lstData4
But, as you can tell, this is bad, ugly code!
First, exactly what type is the myListBoxes array?
Second, how can I loop through the controls on my worksheet to to this automatically?
This code snippet allowed me to find the LisBox objects:
Set wsCont = Worksheets("Control"
With wsCont.Shapes
For i = 1 To .count
For j = 1 To 4
If (.Item(i).Name = ("lstData" & Format(j))) Then
*** Set myListBoxes(j) = .Item(i)
End If
Next j
Next
End With
but the line marked *** doesn't work.
You suggestions gratefully welcomed!
Thanks.
In my code, I would like to create an array that references these objects. The following code snippet works just fine:
Dim myListBoxes(4)
Set myListBoxes(1) = Worksheets("Control".lstData1
Set myListBoxes(2) = Worksheets("Control".lstData2
Set myListBoxes(3) = Worksheets("Control".lstData3
Set myListBoxes(4) = Worksheets("Control".lstData4
But, as you can tell, this is bad, ugly code!
First, exactly what type is the myListBoxes array?
Second, how can I loop through the controls on my worksheet to to this automatically?
This code snippet allowed me to find the LisBox objects:
Set wsCont = Worksheets("Control"
With wsCont.Shapes
For i = 1 To .count
For j = 1 To 4
If (.Item(i).Name = ("lstData" & Format(j))) Then
*** Set myListBoxes(j) = .Item(i)
End If
Next j
Next
End With
but the line marked *** doesn't work.
You suggestions gratefully welcomed!
Thanks.