Good Day to all,
So I have a UserForm which has 3 listboxes which I want populated with information from 3 separate sheets when the useform is loaded.
I can populate one listbox easily, but when i try to do multiple listboxes in the same userform I run into problems
The following is what I use to arrange listbox1 and populate listbox1
Private Sub Arrange_ListBox1()
Dim oneCell As Range
LastRow = Sheet11.Cells(Rows.Count, "A").End(xlUp).Row
With UserForm1.ListBox1
For Each oneCell In Sheet11.Range("A2").Resize(LastRow, 1)
.AddItem
.List(ListRow, 0) = Cells(oneCell.Row, 1).Value
.List(ListRow, 1) = Cells(oneCell.Row, 2).Value
.List(ListRow, 2) = Cells(oneCell.Row, 3).Value
ListRow = ListRow + 1
Next oneCell
End With
MyArray = Array("Single Parent", "Both Parents")
UserForm1.TextBox4.Text = ListRow - 1
End Sub
I have this code in a module
This code to initialize the userform
Private Sub UserForm_Initialize()
Dim oneCell As Range, LastRow As Long
Dim MyArray As Variant
Dim I As Integer
ListBox1.ColumnCount = 3
ListBox1.ColumnWidths = "65;65;65"
LastRow = Sheet11.Cells(Rows.Count, "A").End(xlUp).Row
With ListBox1
For Each oneCell In Sheet11.Range("A2").Resize(LastRow, 1)
.AddItem
.List(ListRow, 0) = Cells(oneCell.Row, 1).Value
.List(ListRow, 1) = Cells(oneCell.Row, 2).Value
.List(ListRow, 2) = Cells(oneCell.Row, 3).Value
ListRow = ListRow + 1
Next oneCell
End With
End Sub
Bookmarks