wsnyder
Board Regular
- Joined
- Sep 23, 2018
- Messages
- 223
- Office Version
- 365
- Platform
- 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.
Thanks,
-w
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