VBA Range Merge -- run-time error 1004

wd314

New Member
Joined
Mar 24, 2009
Messages
2
I am attempting to merge several worksheets into one range. I have code as follows:
Code:
    ' rHistory is defined as a Range above and contains a Range
    Dim rTemp As Range
    For i = 2 To nNumHistory
        sRangeName = "'Sheet" & i & "'!A1:F100"  ' modified example
        Set rTemp = Range(sRangeName)
        Set rHistory = Union(rHistory, rTemp)
    Next i
However, when the Union procedure attempts to execute, I get the following error:
Run-time error '1004':
Method 'Union' of object '_Global' failed

Any help would be greatly appreciated.
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
Hello and welcome to MrExcel.

I may be wrong but

- shouldn't it be Application.Union

- I think that Union can only be used with ranges on the same sheet.
 
Upvote 0

Forum statistics

Threads
1,191,177
Messages
5,985,140
Members
439,942
Latest member
bkexcel11230

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
Top