pimp_mentality
New Member
- Joined
- Oct 15, 2015
- Messages
- 46
Hey guys, need some assistance
I have a UserForm form which currently, when opened it displays all data in the workbook (5 columns). This is the code I am using to accomplish this.
What I would like to do now is have a second listbox which populates with data from columns, say A and B only from sheet2 when the user form is open.
Any suggestions.
ALSO
the above code is suppose to display 5 columns (A-E, these are the only columns with data) however I notice on initialization column D does not show in the list box. any help in rectifying this issues would also be appreciated
I have a UserForm form which currently, when opened it displays all data in the workbook (5 columns). This is the code I am using to accomplish this.
Code:
Private Sub UserForm_Initialize()
Dim oneCell As Range, LastRow As Long
Dim MyArray As Variant
Dim i As Integer
ListBox1.ColumnCount = 5
ListBox1.ColumnWidths = "180;250;180;0;100"
LastRow = Sheet1.Cells(Rows.Count, "A").End(xlUp).Row
With ListBox1
For Each oneCell In Sheet1.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
.List(ListRow, 4) = Cells(oneCell.Row, 5).Value
ListRow = ListRow + 1
Next oneCell
End With
End Sub
Any suggestions.
ALSO
the above code is suppose to display 5 columns (A-E, these are the only columns with data) however I notice on initialization column D does not show in the list box. any help in rectifying this issues would also be appreciated
Last edited: