Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

You receive a "Runtime error 1004" error message when you try to copy and to paste filtered data programmatically in an Excel 2003 workbook


View products that this article applies to.

Symptoms

When you try to copy and to paste filtered data programmatically in a Microsoft Office Excel 2003 workbook, you receive one of the following error messages:
Runtime error 1004: Paste method of worksheet class failed.
Runtime error 1004: Copy method of Range Class Failed.
You receive one of these error messages even though the data is pasted to the workbook.

Note This issue does not occur when the data is not filtered.

↑ Back to the top


Cause

This issue may occur if either of the following conditions is true:
  • The Microsoft Visual Basic for Applications (VBA) macro copies and pastes one whole row in an Excel 2003 workbook.
  • The Microsoft VBA macro copies and pastes a range of 2,516 rows or more rows in an Excel 2003 workbook.

↑ Back to the top


Workaround

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.

To work around this issue if your VBA macro copies and pastes a single whole row, change the VBA macro code to copy only the section of the row that contains data. For example, use VBA macro code that is similar to the following code:
Range(Range("A" & ActiveCell.Row), Range("IV" & ActiveCell.Row).End(xlToLeft)).Select
To work around this issue if your VBA macro copies and pastes a range of 2,516 rows or more rows, change your VBA macro code to loop to copy and to paste smaller ranges of data until the range that you want is copied and pasted.

↑ Back to the top


Keywords: KB905164, kbprb, kbtshoot, kbautomation, kbprogramming, kbvba

↑ Back to the top

Article Info
Article ID : 905164
Revision : 5
Created on : 7/27/2006
Published on : 7/27/2006
Exists online : False
Views : 238