I can not get my listbox to populate range correctly

rharri1972

Board Regular
Joined
Nov 12, 2021
Messages
132
Office Version
  1. 2019
Platform
  1. Windows
I have a listbox on userform1 with a listbox1.
I am trying to reference worksheet "Customers_List" range A1:D30.
It will only show A1:A30 and this is after I put A1:D30 in rowsource in the property box but I don't know if I should have code in the form or listbox or not.
Very confused. I haven't even referenced the sheet for it to be pulling Colum A...

any help?
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Change as required.
Code:
Private Sub UserForm_Initialize()
Dim lr As Long
lr = Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row    '<----- Change sheet reference
    With ListBox1
        .ColumnCount = 4
        .ColumnWidths = "20;20;20;20"    '<----- Change to desired column widths
        .RowSource = "A1:D" & lr
    End With
End Sub
 
Upvote 0
Change as required.
Code:
Private Sub UserForm_Initialize()
Dim lr As Long
lr = Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row    '<----- Change sheet reference
    With ListBox1
        .ColumnCount = 4
        .ColumnWidths = "20;20;20;20"    '<----- Change to desired column widths
        .RowSource = "A1:D" & lr
    End With
End Sub
Thank you Jolivanes. Works perfectly.
 
Upvote 0
Thank you Jolivanes. Works perfectly. Should I enter anything into the rowsource property box to link it just to that worksheet? The reason I ask is that, the listbox is pulling information from the "Customers List" worksheet and I notice if the worksheet tab changes positions, meaning, the Customers List was the second tab in the workbook, the listbox takes information from whatever worksheet is in that second position.
 
Upvote 0
Try so
Code:
Private Sub UserForm_Initialize()
Dim lr As Long
lr = Sheets("Customer List").Cells(Rows.Count, 1).End(xlUp).Row    '<----- Change sheet reference
    With ListBox1
        .ColumnCount = 4
        .ColumnWidths = "20;20;20;20"    '<----- Change to desired column widths
        .List = Worksheets("Customer List").Range("A1").CurrentRegion.Value
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,985
Messages
6,122,603
Members
449,089
Latest member
Motoracer88

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