Union of named ranges not working

mumps

Well-known Member
Joined
Apr 11, 2012
Messages
13,475
Office Version
  1. 2013
  2. 2010
Platform
  1. Windows
I have three named ranges as seen in the macro below. The macro generates the error: Run-time error '1004': Method' Range' of object' _Worksheet' failed with the line in yellow highlighted on Debug. Would anyone have any suggestions as to the cause of the error?
Rich (BB code):
Private Sub Worksheet_Change(ByVal Target As Range)
    Application.ScreenUpdating = False
    Application.EnableEvents = False
    Dim fnd As Range, rng As Range
    Set rng = Union(Range("MondayE"), Range("MondayG"), Range("MondayI"))
    If Not Intersect(Target, rng) Is Nothing Then
        Set fnd = Sheets("Lists").Range("A:A").Find(Target.Value, LookIn:=xlValues, lookat:=xlWhole)
        If Not fnd Is Nothing Then
            fnd.Resize(2).Copy Range(Target.Address)
        End If
    End If
    Application.EnableEvents = True
    Application.ScreenUpdating = False
End Sub
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Does it work without the quotes in that line?
 
Upvote 0
try changing that line to this and see if resolves the issue

VBA Code:
Set rng = Range("MondayE,MondayG,MondayI")

note: example assumes all three named ranges are on the same sheet


Dave
 
Last edited:
Upvote 0
I think I would change the error line to:

VBA Code:
Set rng = Union(MondayE, MondayG, MondayI)
 
Upvote 0
Thank you both for your suggestions. Unfortunately, they both still produce errors.
note: example assumes all three named ranges are on the same sheet
The named ranges are on a different sheet. I tried activating the sheet before that line of code runs and it still errors out. Is there any way of handling this issue?
 
Upvote 0
Union does require all the ranges to be on the same sheet.
 
Upvote 0
I tried Union in my original post without success. All the named ranges are on a sheet called "Lists".
 
Upvote 0
Thanks for the link. I have used Union successfully on many occasions but using it with named ranges that are located on a different sheet is generating the error. I tried changing the scope to "Workbook" but the error is still there.
 
Upvote 0
What is the scope of the 3 named ranges ? If any are a scope of sheet what is the sheet name they are referring to ?
What is the sheet name the event macro is on ?

eg If I run the below with Sheet1 active
- a workbook rngD
- worksheet (sheet2) rngD
- rngA & rngG workbook scope but on sheet2
it needs to look like this:
Rich (BB code):
    Set rngComb = Union(Range("rngA"), Range("Sheet2!rngD"), Range("rngG"))
 
Upvote 0

Forum statistics

Threads
1,215,069
Messages
6,122,954
Members
449,095
Latest member
nmaske

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