ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   add a range of items to a combobox (https://www.excelbanter.com/excel-programming/287809-add-range-items-combobox.html)

spence[_3_]

add a range of items to a combobox
 
is it possible to add all the items in a range
named "Users" to a combo box with one line of code
instead of having to do a
with combobox
.clear
.additem
.additem
.additem
.additem
.additem
.additem
end with
for like 20 to maybe over 50 items.

spence[_3_]

add a range of items to a combobox
 
actually i did it in the properties for the combobox
i named the range and set the ListRows property to "RANGE
NAME" and made the name refer to "=offset(Range,0,0 COUNTA
(A:A),1) so i can add to it. but thatnx for the code, i
will keep it for reference.
-----Original Message-----
You can use a FOR-NEXT loop. See the example below.


Sub add_to_combobox()
Dim tmp As Integer
Dim my_range
Set my_range = Range("A1:A50") 'you can change this
With combobox
.Clear
For tmp = 1 To my_range.Cells.Count
.AddItem my_range.Cells(tmp).Value
Next
End With
End Sub


----- spence wrote: -----

is it possible to add all the items in a range
named "Users" to a combo box with one line of code
instead of having to do a
with combobox
.clear
.additem
.additem
.additem
.additem
.additem
.additem
end with
for like 20 to maybe over 50 items.

.


Tim Zych[_4_]

add a range of items to a combobox
 
ComboBox1.List = Range("Users").Value


"spence" wrote in message
...
is it possible to add all the items in a range
named "Users" to a combo box with one line of code
instead of having to do a
with combobox
.clear
.additem
.additem
.additem
.additem
.additem
.additem
end with
for like 20 to maybe over 50 items.





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

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