×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Why is my Worksheet.copy method failing?

Why is my Worksheet.copy method failing?

Why is my Worksheet.copy method failing?

(OP)
I am writing a VBA application in Excel to analize data from some testing.  I have a formatted template worksheet that needs to be copied for each line of data read into the workbook.  Everything works great until the 33 pass through the copy command at which point I get the error message:

Run-Time Error '1004'
Copy method of Worksheet class failed

The command that I think is failing is:

Worksheets("Template1").Copy before:=Worksheets(1)

This command copies the Template1 sheet and places the copy at the beginning of the worksheets list.

Any thoughts on why the method is failing after running smoothly 32 times?

Ed

RE: Why is my Worksheet.copy method failing?

Out of memory?

RE: Why is my Worksheet.copy method failing?

(OP)
I don't think it is a memory issue.  I'm wondering if it is a bug in the software.  If I insert a new worksheet for each data record instead of copying a template, the program runs fine.  I now have to format each sheet as it's inserted, which just takes longer to run.  Thanks.

Ed

RE: Why is my Worksheet.copy method failing?

It works fine 40 times (or more) here, so maybe it is in some other part of your code?

Cheers,
Joerd

Please see FAQ731-376: Eng-Tips.com Forum Policies for tips on how to make the best use of Eng-Tips.

RE: Why is my Worksheet.copy method failing?

(OP)
There isn't anything else in the code that looks suspicious to me.  I've rewritten portions of the code to insert a blank worksheet and format it appropriately.  There were some issues with named cells that I've taken care of, so I think the problem as been solved.

Thanks for your suggestions.

Ed

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources