Copy/paste filtered cells to another sheet

ANE0709

Board Regular
Joined
Feb 2, 2022
Messages
65
Office Version
  1. 365
Platform
  1. Windows
I have headers in row 1. I am trying to use VBA to filter sheet 1, copy visible cells from A-D not including the headers, and paste in next available row of sheet 3. The code ive used before isnt working this time and im not sure why. Best guess is this time B-C have drop down lists, not sure if that matters.

Sheets("Sheet 1").Select
Selection.AutoFilter
ActiveSheet.Range("$A$1:$FX$100").AutoFilter Field:=3, Criteria1:= _
"=Inactive", Operator:=xlOr, Criteria2:="=Transferred"
Range("A1:D" & lastRow).Offset(1).SpecialCells(xlCellTypeVisible).Select
Selection.copy
Sheets("Sheet 3").Select
Range("A" & Rows.Count).End(xlUp).Offset(1).Select
ActiveSheet.Paste
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Try:
Rich (BB code):
Sub test()
    Dim LastRow As Long
    With Sheets("Sheet 1")
        LastRow = .Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
        .Range("A1").CurrentRegion.AutoFilter Field:=3, Criteria1:="=Inactive", Operator:=xlOr, Criteria2:="=Transferred"
        .Range("A2:D" & LastRow).SpecialCells(xlCellTypeVisible).Copy Sheets("Sheet 3").Cells(Sheets("Sheet 3").Rows.Count, "A").End(xlUp).Offset(1)
    End With
End Sub
Double check if it should be "Sheet 3" or "Sheet3" (without the space).
 
Upvote 0
Solution
Try:
Rich (BB code):
Sub test()
    Dim LastRow As Long
    With Sheets("Sheet 1")
        LastRow = .Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
        .Range("A1").CurrentRegion.AutoFilter Field:=3, Criteria1:="=Inactive", Operator:=xlOr, Criteria2:="=Transferred"
        .Range("A2:D" & LastRow).SpecialCells(xlCellTypeVisible).Copy Sheets("Sheet 3").Cells(Sheets("Sheet 3").Rows.Count, "A").End(xlUp).Offset(1)
    End With
End Sub
Double check if it should be "Sheet 3" or "Sheet3" (without the space).
the debug says this line is an error, just not sure why

Range("A1:D" & lastRow).Offset(1).SpecialCells(xlCellTypeVisible).Select
 
Upvote 0
That line of code doesn't exist in the macro I suggested.
 
Upvote 0
ah, ok. i misunderstood what you wanted me to do. yours worked! thanks!
 
Upvote 0
You are very welcome. :)
 
Upvote 0

Forum statistics

Threads
1,215,064
Messages
6,122,941
Members
449,094
Latest member
teemeren

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