object pointers

  • Thread starter Thread starter rando4
  • Start date Start date
R

rando4

I'm new to VBA. I'm trying to make an object pointer so I can
dynamically populate some ComboBoxes. Here is what doesn't work:


Code:
--------------------
Public Sub showForm()
UserForm1.Show
Sheet1.Activate

For i = 1 To 4
a = "UserForm1.ComboBox" & i
a.ColumnCount = 1
a.RowSource = "A2:A11"
Next i

End Sub
--------------------


I've tryed switching data types with "as object" with no luck.
Searching for this on the web is crazy. It seems everyone wants some
pointers on using excel. :)
 
Public Sub showForm()
Dim a as Object
For i = 1 To 4
set a = Userform1.Controls("Combobox" & i)
a.ColumnCount = 1
a.RowSource = "Sheet1!A2:A11"
Next i
UserForm1.Show
End Sub
 
Hello Rando4,

Neither Visual Basic nor Visual Basic for Applications use objec
pointers in the traditional sense of a pointer. I have made the change
to the code to do what you want.

By the way, do you want all for ComboBoxes to be filled with the sam
range data?



Code
-------------------
Public Sub showForm()
Dim CB as Object

UserForm1.Show
Sheet1.Activate

For i = 1 To 4
Set CB = UserForm1.Controls("ComboBox" & i)
With CB
.ColumnCount = 1
.RowSource = "Sheet1!$A$2:$A$11"
End With
Next i

End Sub
 
Back
Top