Michael
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)
ASKER
Same error (plus that is not where the data is).
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Same error.
BTW: Debugger indicated issue is in line 10.
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
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
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.
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.
pls try (line 13 sourceSht instead of outputSht)
Open in new window
regards