ListBox Does Not Populate

wsnyder

Board Regular
Joined
Sep 23, 2018
Messages
223
Office Version
  1. 365
Platform
  1. Windows
Hi all,

Using Excel 365.

I'm trying to populate a ListBox on a UserForm from a ListObject.
But when I run it, the ListBox is empty.

Do you see anything wrong in the code?
There is 1 worksheet with 1 Table.

VBA Code:
Private Sub frmRegion_Initialize()

'Populate list values

    'Objects
        Dim wb As Workbook
        Dim ws As Worksheet
        Dim lo As ListObject
        Dim arr As Variant
        Dim myList() As String
    
    'Variables
        Dim i As Long
    
    'Initialize
        Set wb = ThisWorkbook
        Set ws = wb.Worksheets(1)
        Set lo = ws.ListObjects(1)
        arr = lo.DataBodyRange
        ReDim myList(1 To UBound(arr))
    
    'Populate ComboBox from array
        For i = LBound(myList) To UBound(myList)
           myList(i) = arr(i)
        Next i
        
    'Assign array to combo box
        lstRegion.List = myList

End Sub

Thanks,
-w
 
It's the simplest way of doing it. Although if you only have 1 column, I'd tend to use a combobox instead.
 
Upvote 0

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
It's the simplest way of doing it. Although if you only have 1 column, I'd tend to use a combobox instead.
Thanks,

Does ComboBox have a multi-select property?
I tried cboBox first, but I did not see the multi-select.

Thanks,
-w
 
Upvote 0
No it doesn't, so you will need to stick with a list box.
 
Upvote 0

Forum statistics

Threads
1,214,957
Messages
6,122,466
Members
449,086
Latest member
kwindels

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