how to initialize more than one Listboxes in the same user form

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.
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
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
 
Last edited:

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Noticed you have disappeared. If your still wanting an answer try this:

Code:
Private Sub UserForm_Initialize()
Dim i As Long
Dim b As Long
b = 0
Dim lastrow As Long
Dim lastrowa As Long
Dim lastrowb As Long
lastrow = Sheet1.Cells(Rows.Count, "A").End(xlUp).Row
lastrowa = Sheet2.Cells(Rows.Count, "A").End(xlUp).Row - 1
lastrowb = Sheet2.Cells(Rows.Count, "B").End(xlUp).Row
ListBox1.ColumnCount = 5
ListBox1.ColumnWidths = "100;100;100;100;100"
ListBox2.ColumnCount = 2
ListBox2.ColumnWidths = "100;100"
Data = Range("A2:E" & lastrow)
ListBox1.List = Data

    For i = 1 To lastrowb
        With ListBox2
            .AddItem
            .List(b, 0) = Sheets(2).Cells(i, 1).Value
            .List(b, 1) = Format(Sheets(2).Cells(i, 2).Value, "hh:mm:ss")
                b = b + 1
        End With
               
    Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,248
Messages
6,171,027
Members
452,374
Latest member
keccles

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