Copy filtered data with vba

JoeyGaspard

Board Regular
Joined
Jul 22, 2019
Messages
147
I am using the following code to filter and delete data, I would like to be able to copy the filtered data, but instead of the "EntireRow", I want to copy range A:E of the filtered set only instead of deleting, to cell A1 of another worksheet and turn off the filter so I can do it again with a different code, can someone help me on how to do that? Thanks in Advance!!

With Sheets("Data")

.AutoFilterMode = False

With .Range("A1", .Range("A" & Rows.Count).End(xlUp))

.AutoFilter 1, "95802"

On Error Resume Next

.Offset(1).SpecialCells(12).EntireRow.Delete

End With

.AutoFilterMode = False

End With
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
How about
VBA Code:
Sub JoeyGaspard()
   With Sheets("Data")
      .AutoFilterMode = False
      .Range("A1").AutoFilter 1, "95802"
      .AutoFilter.Range.Columns("A:E").Offset(1).Copy Sheets("Sheet1").Range("A1")
      .AutoFilterMode = False
   End With
End Sub
 
Upvote 0
How about
VBA Code:
Sub JoeyGaspard()
   With Sheets("Data")
      .AutoFilterMode = False
      .Range("A1").AutoFilter 1, "95802"
      .AutoFilter.Range.Columns("A:E").Offset(1).Copy Sheets("Sheet1").Range("A1")
      .AutoFilterMode = False
   End With
End Sub
I did not work, it didnt error out, but it did not do the copy/paste
 
Upvote 0
Do you have any blank rows in your data?
 
Upvote 0
If you step through the code using F8 until you get to this line
VBA Code:
.AutoFilter.Range.Columns("A:E").Offset(1).Copy Sheets("Sheet1").Range("A1")
then look at the data, is it filtered correctly & are there any visible rows?
 
Upvote 0
If you step through the code using F8 until you get to this line
VBA Code:
.AutoFilter.Range.Columns("A:E").Offset(1).Copy Sheets("Sheet1").Range("A1")
then look at the data, is it filtered correctly & are there any visible rows?
Well, I removed the code, copied and pasted it back in, and now for some reason this one line is turned red and says : Compile Error: Expected list separtor or )

.AutoFilter.Range.Columns("A:E").Offset(1).Copy Sheets("USCold").Range("A1)
 
Upvote 0
You're missing a " before the final )
 
Upvote 0
You're missing a " before the final )
OK, I found the problem, the new data file I have has the columns slightly rearranged, I need to filter by Column "C" instead of Column "A", so I changed that here, but it is still filtering Column "A" ??


With Sheets("Data")
.AutoFilterMode = False
.Range("C1").AutoFilter 1, "95802"
.AutoFilter.Range.Columns("A:E").Offset(1).Copy Sheets("NOCSTx").Range("A1")
.AutoFilterMode = False
 
Upvote 0
It needs to be
VBA Code:
 .Range("A1").AutoFilter 3, "95802"
 
Upvote 0

Forum statistics

Threads
1,215,256
Messages
6,123,915
Members
449,132
Latest member
Rosie14

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