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

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
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,215,050
Messages
6,122,868
Members
449,097
Latest member
dbomb1414

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