I have the following code in a UserForm. I'm attempting to add a certain subset of the comboboxes on the form to a collection, and then loop through that collection. It seems to be adding the value of the combobox to the collection rather than the control object itself...? What identifier or property do I need to use to be able to access the .Text
property of the combobox object after it is added to the collection?
'Put comboboxes in a collection
Dim oColl As Collection
Set oColl = New Collection
Dim cb As Control
For Each cb In Me.Controls
If TypeName(cb) = "ComboBox" Then
' I suspect it may be this line going wrong:
If IsNumeric(cb.Text) Then oColl.Add (cb)
End If
Next
' Trying to loop through the collection of comboboxes
' I've tried to declare ctrl as MSForms.ComboBox, ComboBox, Control, Object,
' and Variant, results are the same...
Dim ctrl As MSForms.ComboBox
Dim i As Integer
For i = 1 To oColl.count
For Each ctrl In oColl
' This line produces an object required error on ctrl
If CInt(ctrl.Text) = line Then