Runtime Error 1004 copy method of Worksheet class failed

L

Legacy 433589

Guest
Hey everyone!

I have a workbook that keeps throwing the title error when attempting to copy a worksheet from one workbook to another. This error is so common that, in order to make sure I got it right in the thread title, I used Google's autocomplete. But whenever I look it up, the resolutions always refer to a workbook trying to copy a worksheet back into itself multiple times. There's no mention of any other error mode, and none of the items I can find on it seem to express a solid understanding of what is actually happening to trigger this error.

My workbook has many hidden sheets, many locked sheets and two routines for development that will unhide/unlock everything, and hide/lock it back up for releasing to the user base. (It's a really big piece of sausage...) I mention this because when unlocked/unhidden the code works fine - it only throws the error when it's all locked up and some of the articles do mention hidden objects as a potential source of the problem.

This is a re-type from my other pc screen rather than a copy and paste, but the snippet of code it errors on is:

Code:
Workbooks(JCWID).Activate
sheetcount = ActiveWorkbook.Worksheets.count
If sheetcount > 42 Then
         For x = 43 to sheetcount
                  [B]Workbooks(JCWID).Sheets(x).Copy After:=Workbooks(FileID).Sheets(Workbooks(FileID).Sheets.count)[/B]
         Next x
End If

If the formatting holds, the bold line is where it errors (the copy line, of course).

If anyone has any ideas for a solution or even a bad workaround, I would very much appreciate it! If more information is required, I stand ready to respond.
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Ack! Did I touch the third rail? Do I smell funny? Please, if you're reading this and you have any ideas about it...
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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