Adding Collections To ListBoxes

k209310

Active Member
Joined
Aug 12, 2002
Messages
382
Hello

Is it possible to add a VBA collection to a list box?

Thanks

Chris
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
If you have created the collection you can loop around it adding the items, like this:

Code:
Dim Item As Variant
For Each Item In MyCollection
    ListBox1.AddItem Item
Next Item

Replace MyCollection with your variable.
 
Upvote 0
Im looping through an access table to read company names. When needed i add the names to collection. I then add the collection to a list box on a form in excel using the code you kindly provided.

However i also have to produce a list of the names that appear on one or two lines that are seperate by the ';' character for use in third party software. ie Name1;Name2;Name3 etc.

Does this make sense?
 
Upvote 0
I suppose:

Code:
Dim Item As Variant 
Dim MyStr As String
MyStr = ""
For Each Item In MyCollection 
    If MyStr = "" Then
        MyStr = MyStr & Item
    Else
        MyStr = MyStr & ";" & Item
    End If
Next Item
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top