run-time error 1004 when copying filtered data

FellowExcellor

Board Regular
Joined
May 17, 2005
Messages
59
Hi

Have the code below that takes a sheet refrence from the activesheet, goes to that sheet, filters data and then copies and pastes data from that sheet into the original sheet.

However everytime I run this macro, I get the error: run-time error 1004,
Copy method of range class failed.

Sub Importweeklydata()
Dim i As String, j As Long
Range("b2:g5000").Clear
i = Range("A1").Value
Sheets(i).Columns("G:G").AutoFilter Field:=1, Criteria1:="WE" 'filters on WE in the sheet
j = Sheets(i).Cells(Rows.Count, 1).End(xlUp).Row 'finds last populated row
Sheets(i).Range("A" & Application.WorksheetFunction.Max(1, j - 1000) & ":f" & j).Copy Sheets("Weekly Data").Range("b2")
Sheets(i).Columns("G:G").AutoFilter 'unfilters the sheet
End Sub

When I debug it takes me to the line:

Sheets(i).Range("A" & Application.WorksheetFunction.Max(1, j - 1000) & ":f" & j).Copy Sheets("Weekly Data").Range("b2")


As a test, I tried manually copying and pasting the some procedure as above using the following recorded macro and get a similar error: "Paste method of worksheet class failed"

Sub testing()
Range("B2:F203").Select
Selection.ClearContents
Sheets("Evolution Group").Select
Columns("G:G").Select
Selection.AutoFilter
Selection.AutoFilter Field:=1, Criteria1:="WE"
Range("B804").Select
Range("A2342").Select
ActiveWindow.SmallScroll Down:=4
Range("A1342:F2342").Select
Range("A2342").Activate
Selection.Copy
Sheets("Weekly Data").Select
Range("B2").Select
ActiveSheet.Paste
Sheets("Evolution Group").Select
Selection.AutoFilter Field:=1
ActiveWindow.ScrollWorkbookTabs Sheets:=-14
Sheets("Weekly Data").Select
Range("A22").Select
End Sub

Again debugging takes me two the line: ActiveSheet.Paste

It seems the errors are occuring because I am copying filtered data. If I don't use the filter, the copy and paste seems to work fine in both cases.

Does anyone know why this is happening and what I can do about it?

Thanks

FE
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"

Forum statistics

Threads
1,214,991
Messages
6,122,628
Members
449,095
Latest member
bsb1122

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