Link to home
Start Free TrialLog in
Avatar of Michael
MichaelFlag for United States of America

asked on

Copy/Paste Excel Named Ranges on inactive sheet

As part of a larger macro (already working), I would like to copy the data from the Start range on Sheet2 to the Finish range on the same sheet.  The ranges are the same size and are on an inactive sheet.  The code I have gives me Run-time error '1004': Method 'Range' of object '_Worksheet' failed.  I am including the pertinent code.  I am sure I am missing something stupid.  Any help is greatly appreciated.

Dim sourceSht As Worksheet, outputSht As Worksheet
Dim sourceRange As Range
Dim start As Range
Dim finish As Range

'Set the active sheet to the current sheet
Set sourceSht = ActiveSheet

'Set the output to Sheet2
Set outputSht = ActiveWorkbook.Sheets("Sheet2")

'Set the start variable to the Start range on Sheet 2
Set start = outputSht.Range("Start")

'Set the finish variable to the Finish range on Sheet 2
Set finish = outputSht.Range("Finish")

'Turn off screen updating
Application.ScreenUpdating = False

'Copy the cells from the Sheet2 Start range and copy them to the Sheet 2 Finish range
start.Copy (finish)

Open in new window

Avatar of Rgonzo1971
Rgonzo1971

Hi,

pls try (line 13 sourceSht instead of outputSht)

Dim sourceSht As Worksheet, outputSht As Worksheet
Dim sourceRange As Range
Dim start As Range
Dim finish As Range

'Set the active sheet to the current sheet
Set sourceSht = ActiveSheet

'Set the output to Sheet2
Set outputSht = ActiveWorkbook.Sheets("Sheet2")

'Set the start variable to the Start range on Sheet 2
Set start = sourceSht.Range("Start")

'Set the finish variable to the Finish range on Sheet 2
Set finish = outputSht.Range("Finish")

'Turn off screen updating
Application.ScreenUpdating = False

'Copy the cells from the Sheet2 Start range and copy them to the Sheet 2 Finish range
start.Copy finish

End Sub

Open in new window

regards
Avatar of Michael

ASKER

Same error (plus that is not where the data is).
ASKER CERTIFIED SOLUTION
Avatar of Professor J
Professor J

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Michael

ASKER

Same error.

BTW: Debugger indicated issue is in line 10.
please see the attached file.

i have put the macro in the workbook. i have the two named ranges start and finish

and when u run the macro, it will copy the start range and will paste it in finish range.

no error is there.

please let me know if you get any error in this workbook.
Book1.xlsm
Avatar of Michael

ASKER

PJJ--

Thank you for the workbook; it brought to my attention that my named ranges had not been saved.  Once that happened, your previous code worked.