ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Run-Time Error 1004 (https://www.excelbanter.com/excel-programming/305189-re-run-time-error-1004-a.html)

Tom Ogilvy

Run-Time Error 1004
 
Possibly you could make five template sheets and copy them five at a time.

I have heard that copying sheets can cause memory problems. The above is a
work around that can allow you to do more copies - as it appears the
problematic action is doing the copy, and not how much is copied.

--
Regards,
Tom Ogilvy


"Alex" wrote in message
...
Hi,

Can anyone please workout why I'm getting a Run-Time Error 1004 (Copy

method of worksheet class failed) in code after 30 sheets have been copied?
Code works fine up until then. Is there a limit on how many sheets can be
copied to new workbook. This is confusing because if your open a new
file, it can have up to 255 sheets. All my code is doing is running through
a list of names and for each copying a template sheet into a new workbook.
I have 50 names which I need to create the same template sheet for each name
and store in one new workbook. For some reason can't get past 30 sheets.

Appreciate any help with this.
Alex

XL2003 VBA


' loop
While (Ctr) < EmpCtr
CrtEmpName = Workbooks(DataFile).Sheets(DataSht).Cells(rCtr,

1).Value ' Master file containing employee names sheet

' copy template to new workbook on first occurance
If ShtCtr = 0 Then
Sheets(CalcSht).Copy ' Template sheet to copy
ActiveWorkbook.Sheets(CalcSht).Activate ' New workbook

created with tempate sheet copied
CalcFile = ActiveWorkbook.Name '
Else
R-T Error -- Sheets(CalcSht).Copy

After:=Workbooks(CalcFile).Sheets(ShtCtr)

End If
ActiveSheet.Name = CrtEmpName

Workbooks(DataFile).Sheets(CalcSht).Activate ' Master file

containing template sheet
rCtr = rCtr + 1
Ctr = Ctr + 1
ShtCtr = ShtCtr + 1
Wend







All times are GMT +1. The time now is 01:06 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com