ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Assign variable ListBox names (https://www.excelbanter.com/excel-programming/376968-assign-variable-listbox-names.html)

chris[_2_]

Assign variable ListBox names
 
I have a user form with three list boxes. Is there a "For" statement
(similar to below) that will loop through each of the three list boxes
and execute a "with" command?

For x = 1 to 3
With UserForm1.ListBox(x)
.additem = A
.additem = B
End With
next x

Any help is greatly appreciated, thank you!


Tom Ogilvy

Assign variable ListBox names
 
For x = 1 to 3
With UserForm1.Controls("ListBox" & i)
.additem = A
.additem = B
End With
next x

--
Regards,
Tom Ogilvy



"chris" wrote in message
oups.com...
I have a user form with three list boxes. Is there a "For" statement
(similar to below) that will loop through each of the three list boxes
and execute a "with" command?

For x = 1 to 3
With UserForm1.ListBox(x)
.additem = A
.additem = B
End With
next x

Any help is greatly appreciated, thank you!




chris[_2_]

Assign variable ListBox names
 
Is it safe to assume that the "i" should be an "x"? I am also
receiving a Run-time error '438'. Any ideas for a solution?

Thanks!

Tom Ogilvy wrote:
For x = 1 to 3
With UserForm1.Controls("ListBox" & i)
.additem = A
.additem = B
End With
next x

--
Regards,
Tom Ogilvy



"chris" wrote in message
oups.com...
I have a user form with three list boxes. Is there a "For" statement
(similar to below) that will loop through each of the three list boxes
and execute a "with" command?

For x = 1 to 3
With UserForm1.ListBox(x)
.additem = A
.additem = B
End With
next x

Any help is greatly appreciated, thank you!




All times are GMT +1. The time now is 06:21 AM.

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