When copying filtered rows to another sheet I get an error

timpepu

Board Regular
Joined
Mar 4, 2008
Messages
89
Hi ! When I try to copy filtered row s to another sheet I get an error ,Run-time-error'1004' ,copy method of range class failed

Here is the code and I want also heeaders

Sub Macro3()
Dim Wb As Workbook
Dim ws As Worksheet
Set Wb = ThisWorkbook
Set ws = Wb.Sheets("HCBODM")

Range("A1:R1").Select
Selection.AutoFilter
' done

With ws
.AutoFilterMode = False
With .Range("A1:r40000")
.AutoFilter Field:=8, Criteria1:="<>CC*" _
, Operator:=xlOr, Criteria2:="CQN*"
.SpecialCells(xlCellTypeVisible).copy Destination:=Sheets("Taul2").Range("A1")
End With
End With
End Sub
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
can you try the below? i simulated your data and the below worked for me.

Code:
Sub Macro3()
Dim Wb As Workbook
Dim ws As Worksheet
Set Wb = ThisWorkbook
Set ws = Wb.Sheets("HCBODM")
With ws
.AutoFilterMode = False
With .Range("A1:R" & .Range("A" & .Rows.Count).End(xlUp).Row)
.AutoFilter Field:=8, Criteria1:="<>CC*" _
, Operator:=xlOr, Criteria2:="CQN*"
.SpecialCells(xlCellTypeVisible).Copy Destination:=Sheets("Taul2").Range("A1")
End With
End With
End Sub
 
Upvote 0
can you try the below? i simulated your data and the below worked for me.

Code:
Sub Macro3()
Dim Wb As Workbook
Dim ws As Worksheet
Set Wb = ThisWorkbook
Set ws = Wb.Sheets("HCBODM")
With ws
.AutoFilterMode = False
With .Range("A1:R" & .Range("A" & .Rows.Count).End(xlUp).Row)
.AutoFilter Field:=8, Criteria1:="<>CC*" _
, Operator:=xlOr, Criteria2:="CQN*"
.SpecialCells(xlCellTypeVisible).Copy Destination:=Sheets("Taul2").Range("A1")
End With
End With
End Sub

It works Thanks
 
Upvote 0

Forum statistics

Threads
1,215,776
Messages
6,126,830
Members
449,343
Latest member
DEWS2031

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