Copy method of worksheet class failed (Run-time Error 1004)

Jamaal09

New Member
Joined
May 17, 2014
Messages
6
Hey guys,

Im using Excel 2013 and I'm getting an issue in vba I can't figure out. (This is something I've done several dozen time before) But everytime I try to copy a sheet in a workbook,
select_all_icon.jpg
page_white_copy.png


<code style="margin: 0px; padding: 0px; font-style: inherit; font-weight: inherit;">Sheets("Sheet1").Copy After:=WB.Sheets(WB.Sheets.Count)</code></pre>

I recently copied in this sheet from another workbook, and deleted all of it's formula names, but I can't copy any other sheets now either.
the Run time Error 1004: Copy method of Worksheet Class failed pops up. What is weird is that I put in a msgbox and
select_all_icon.jpg
page_white_copy.png


<code style="margin: 0px; padding: 0px; font-style: inherit; font-weight: inherit;">MsgBox (WB.Sheets.Count)</code></pre>

returns a "1" though the sheet has about a dozen sheets within it. Anything I'm missing? Ive saved the workbook and even saved it as another name.


the sheet I imported has a sheet number of 77 while the previous last sheet was 23, could this be a cause?
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Update: Fixed, it looks like when I was setting WB = thisworkbook and a few other methods it was refering to my Personal workbook. I changed it to activeworkbook and its working now. No clue why it did that. Any thoughts?
 
Upvote 0
Hi Jamaal09,

ThisWorkBook refers to the workbook in which the code making that reference is stored.

So for code stored in your Personal.xlsb file, ThisWorkbook.Sheets.Count will return the number of Sheets in Personal.xlsb - not the number of Sheets in the ActiveWorkbook.
 
Upvote 0

Forum statistics

Threads
1,215,758
Messages
6,126,709
Members
449,331
Latest member
smckenzie2016

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