Popilating a luser form listbox in vba

Peter Thompson

Active Member
Joined
Dec 15, 2008
Messages
262
Hello,

I have been trying to run the code below to get a list box in a user formto be populated from a named range (called Requestors) in a worksheet (Report_Sheet) but I keep getting errors when I try and run it. The top few lines work fine but when it goes to the with statement it gets an error.

Can anyone see whats going wrong?

Private Sub UserForm_Initialize()
Dim vListSource As Variant

Dim wksRepSheet As Worksheet
Set wksRepSheet = Worksheets("Report_Sheet")

With wksRepSheet.Names("Requestor")
vListSource = .RefersToRange.Value
End With

frmBriefing.ListBox1.List = vListSource

End Sub
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Doesn't Refers to Range return the address of the named range.

Anyway, try this.
Code:
frmBriefing.ListBox1.List = Range("Requestor").Values
Or this.
Code:
frmBriefing.ListBox1.RowSource = "Requestor"
 
Last edited:
Upvote 0
or

Code:
Private Sub UserForm_Initialize()
Dim vListSource As Variant

Dim wksRepSheet As Range
Set wksRepSheet = ThisWorkbook.Names("Requestor").RefersToRange

With wksRepSheet
vListSource = .Value
End With

frmBriefing.ListBox1.List = vListSource

End Sub
 
Upvote 0
Thanks,

Norje - your first suggestion didnt work, but the second one worked fine.

Comfe - your suggestion also worked.

The rowsource option appears easier. Is there any disadvantge to using this approach rather than the variant apprach?
 
Upvote 0

Forum statistics

Threads
1,224,583
Messages
6,179,671
Members
452,937
Latest member
Bhg1984

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