• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

How to populate a listbox?

usr7501

New Member
Hello,

Is it possible to populate a listbox? If so how is it done in Excel?
 

Attachments

  • Book1.xlsx
    10.2 KB · Views: 4
Go to Data Tab
Click Data Validation
Click Data Validation (again)
Under Settings Tab
Click drop arrow under "Allow"
Select "List"
Under the source click the blue square on the right
then highlight all the list.
click OK.

See sample.

Hopefully this is the one you are looking for.
 

Attachments

  • Book1.xlsx
    11.1 KB · Views: 2
If your list of Fruit can have duplicates, you may want to consider using this approach which ensures that each fruit is only listed once

Code:
Sub PopulateListruta4()
    
    ' Create dictionary
    Dim dict As Object
    Set dict = CreateObject("Scripting.Dictionary")

    Dim cell As Range, sItem As String
    ' Go through each item in range
    For Each cell In [Fruits]
        sItem = Trim(cell.Value)
        ' check if item already exists in dictionary
        If dict.Exists(sItem) = False Then
            ' If doesn't exist then add to dictionary and combobox
            dict.Add sItem, 1
            Sheet1.Shapes("Listruta 4").ControlFormat.AddItem sItem
        End If
    Next

    ' Clean up dictionary as we no longer need it
    Set dict = Nothing

End Sub

or see attached file:
 

Attachments

  • Test.xlsm
    18.4 KB · Views: 3
Last edited:
Back
Top