VBA Link to Named Range in Another Workbook for Userform dropdown

Jaye Cavallo

New Member
Joined
Mar 10, 2022
Messages
47
Office Version
  1. 2016
Platform
  1. Windows
Hello,

I am hoping to create a userform in one Excel workbook with a link to the named range in another Excel workbook. So, the first Excel file would have userform that would have a combobox that is be populated with elements of the named range in a different excel file. I have to share my Excel workbook with many co-workers. I have to share a new Excel workbook everytime the elements of the named range change. I would like the Excel file with the userform point to the named range on a shared drive, so all I would need to do is update the elements of the named range and the change would be reflected in all of the workbooks of my co-workers.

I have the below, but receive a subscript out of range error. Any help would be appreciated.

Dim rngDepartment As Range
Dim wb As Workbook

Set wb = Application.Workbooks("options.xlsm")

wb.Activate

Dim ws As Worksheet
Set ws = Worksheets("Options")

For Each rngDepartment In wb.Range("Department")
With Me.cboDepartment
.AddItem rngDepartment.value
End With
Next rngDepartment
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
This is a bit of a guess, but give it a try anyway...

VBA Code:
Dim rngDepartment As Range
Dim wb As Workbook

Set wb = Application.Workbooks("options.xlsm")

wb.Activate

Dim ws As Worksheet
Set ws = wb.Worksheets("Options")

For Each rngDepartment In ws.Range("Department")
With Me.cboDepartment
.AddItem rngDepartment.value
End With
Next rngDepartment

If it doesn't work, what line of code is highlighted when it errors?
 
Upvote 0
Solution
This is a bit of a guess, but give it a try anyway...

VBA Code:
Dim rngDepartment As Range
Dim wb As Workbook

Set wb = Application.Workbooks("options.xlsm")

wb.Activate

Dim ws As Worksheet
Set ws = wb.Worksheets("Options")

For Each rngDepartment In ws.Range("Department")
With Me.cboDepartment
.AddItem rngDepartment.value
End With
Next rngDepartment

If it doesn't work, what line of code is highlighted when it errors?

Thank you. Your solution work as long as the files are in the same local directory. I have to figure out the path to the network drive.
 
Upvote 0
Thank you. Your solution work as long as the files are in the same local directory. I have to figure out the path to the network drive.
You're welcome. Thanks for the feedback.

A couple of ideas about your network's file path:
  1. Your IT Dept. could map a network drive as a local drive. As long as everyone has the same mapped drive letter for the network drive, the macro should work.
  2. Try recording a macro and then open your network file. The macro may show you the recorded network file path. This doesn't always work de[ending on your type of network config.
 
Upvote 0

Forum statistics

Threads
1,226,059
Messages
6,188,634
Members
453,487
Latest member
LZ_Code

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