ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   object pointers (https://www.excelbanter.com/excel-programming/343746-object-pointers.html)

rando4

object pointers
 

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. :)


--
rando4
------------------------------------------------------------------------
rando4's Profile: http://www.excelforum.com/member.php...o&userid=28315
View this thread: http://www.excelforum.com/showthread...hreadid=478994


Tom Ogilvy

object pointers
 
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
--------------------

--
Regards,
Tom Ogilvy

"rando4" wrote in
message ...

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. :)


--
rando4
------------------------------------------------------------------------
rando4's Profile:

http://www.excelforum.com/member.php...o&userid=28315
View this thread: http://www.excelforum.com/showthread...hreadid=478994




Leith Ross[_109_]

object pointers
 

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

-------------------


Sincerely,
Leith Ros

--
Leith Ros
-----------------------------------------------------------------------
Leith Ross's Profile: http://www.excelforum.com/member.php...fo&userid=1846
View this thread: http://www.excelforum.com/showthread.php?threadid=47899



All times are GMT +1. The time now is 07:19 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com