Listbox not loading from Named Range

music_al

Board Regular
Joined
Nov 26, 2008
Messages
133
Code:
Private Sub UserForm_Initialize()
    'Set the range of the Agency table
    With Worksheets("Reference")
        Set rgAgencies = .Range(.Cells(2, 23), .Cells(Agency_Count, 23))
    End With
    
    ActiveWorkbook.Names.Add Name:="Agency_List", RefersTo:=rgAgencies
    Me.list_Agencies.RowSource = Worksheets("Reference").Range("Agency_List").Address


End Sub

The named range (Agency_List) is in the REFERENCE worksheet. When the Reference worksheet is active and I run the form, the listbox loads with the list.

However, when the CANDIDATE worksheet is active, the form opens but the listbox on the form will not load. The form will be initialised when I am in the CANDIDATE worksheet.

What am I doing wrong ?
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
How about
Code:
Private Sub UserForm_Initialize()
    'Set the range of the Agency table
    With Worksheets("Reference")
        Me.ListBox1.List = Application.Transpose(.Range(.Cells(2, 23), .Cells(6000, 23)))
    End With
    
End Sub
 
Upvote 0
Try using the worksheet argument of .Address

Code:
Me.list_Agencies.RowSource = Worksheets("Reference").Range("Agency_List").Address(,,,True)
 
Upvote 0
You can shorten it to this...

Code:
Private Sub UserForm_Initialize()
    'Set the range of the Agency table
    Me.list_Agencies.RowSource = ""
    With Worksheets("Reference")
        Me.list_Agencies.List = .Range(.Cells(2, 23), .Cells(Agency_Count, 23)).Value
    End With
End Sub
 
Last edited:
Upvote 0
Address on its own will only return a range reference, it won't include the worksheet.

If you definitely want to use RowSource try this.
Code:
Private Sub UserForm_Initialize()
    'Set the range of the Agency table
    With Worksheets("Reference")
        Set rgAgencies = .Range(.Cells(2, 23), .Cells(Agency_Count, 23))
    End With
    
    ActiveWorkbook.Names.Add Name:="Agency_List", RefersTo:=rgAgencies
    Me.list_Agencies.RowSource = Worksheets("Reference").Range("Agency_List").Address(External:=True)

End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,213,489
Messages
6,113,953
Members
448,535
Latest member
alrossman

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