ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Dynamically Assign Objects to Form Objects. (https://www.excelbanter.com/excel-programming/318721-dynamically-assign-objects-form-objects.html)

The Vision Thing

Dynamically Assign Objects to Form Objects.
 
I have ten listboxes on a form, ddlwb1, ddlwb2 etc. I want to loop through
them and dynamically assign them to an object like so:

For i = 1 To 10
Set objDdl = ddlwb & i
'do something else with objDdl
Next

Obviously this doesn't work, but I vaguely recall a command that will make
it work, though for the life of me I can't remember what.

Thanks,
Wayne C.



Tom Ogilvy

Dynamically Assign Objects to Form Objects.
 
For i = 1 To 10
Set objDdl = Userform1.Controls("ddlwb" & i)
'do something else with objDdl
Next

--
Regards,
Tom Ogilvy

"The Vision Thing" wrote in message
...
I have ten listboxes on a form, ddlwb1, ddlwb2 etc. I want to loop

through
them and dynamically assign them to an object like so:

For i = 1 To 10
Set objDdl = ddlwb & i
'do something else with objDdl
Next

Obviously this doesn't work, but I vaguely recall a command that will make
it work, though for the life of me I can't remember what.

Thanks,
Wayne C.





The Vision Thing

Dynamically Assign Objects to Form Objects.
 
Thank you Tom, worked like a charm.

Wayne C.






All times are GMT +1. The time now is 02:15 AM.

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