Trying to get row source in VBA Listbox

Eric Penfold

Active Member
Joined
Nov 19, 2021
Messages
424
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
I have code to get a range into form listbox but it says run time error 13??

VBA Code:
Private Sub UserForm_Initialize()

    Dim wb     As Workbook
    Dim ws     As Worksheet
    Dim LRow   As Long

    Set wb = ActiveWorkbook
    Set ws = wb.ActiveSheet
    LRow = ws.Cells(Rows.Count, 1).End(xlUp).Row
    
    Me.SuppliersName.RowSource = ws.Range("B1:B" & LRow)
    Me.SuppliersName.ColumnHeads = True
    
End Sub
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Try this:
VBA Code:
Private Sub UserForm_Initialize()

    Dim wb     As Workbook
    Dim ws     As Worksheet
    Dim LRow   As Long

    Set wb = ActiveWorkbook
    Set ws = wb.ActiveSheet
    LRow = ws.UsedRange.Rows.Count
    
    Me.SuppliersName.ListFillRange = ws.Range("B1:B" & LRow).Address
    Me.SuppliersName.ColumnHeads = True
    
End Sub
 
Upvote 0
Solution
You'll want to include the sheet name in the rowsource as well as the cell addresses:

VBA Code:
Me.SuppliersName.RowSource = "'" & ws.name & "'!B1:B" & LRow
 
Upvote 0

Forum statistics

Threads
1,215,079
Messages
6,123,000
Members
449,092
Latest member
masterms

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