Macro Select visible cells after auto filter - except header

bbran19

New Member
Joined
Jan 30, 2012
Messages
49
Office Version
  1. 365
Platform
  1. Windows
Is there any way to select visible cells after auto-filter EXCEPT the header row? I need to copy and paste into a new worksheet but I don't want to copy the header row.
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
See if this helps:
Rich (BB code):
   With Sheets("Sheet1")
        With .Cells(1, 1).Resize(10, 10)
            .AutoFilter Field:=1, Criteria1:="<>"
            .Offset(1).Resize(9).Specialcells(xlcelltypevisible).Copy
        End With
    End With
The blue 10 is for the number of rows in the area being filtered, including header row
Offset(1) goes to the 'next' row but we reduce the count of rows in the area by 1 since excluding header row (i.e. 10 - 1 = 9)
Then copy the visible cells for that area only
 
Last edited:
Upvote 0
Assuming you want to filter a Sheet named "Sheet1" and copy those rows into a Sheet named "Sheet2"
And you want to filter the values in Column "A" which have the value "Pending"

Use this script.

Modify the sheet names marked in Red if your sheet names are not as mentioned above.
And modify the filter value and column to search as needed.

Code:
Sub Filter_Me()
'Modified 10-6-17 1:00 PM EDT
Application.ScreenUpdating = False
Dim Lastcolumn As Long
Dim CopySheet As String
Dim PastSheet As String
CopySheet = [COLOR=#ff0000]"Sheet1[/COLOR]"
PasteSheet = "[COLOR=#ff0000]Sheet2[/COLOR]"
Lastcolumn = Sheets(CopySheet).Cells(1, Columns.Count).End(xlToLeft).Column
Lastrow = Sheets(PasteSheet).Cells(Rows.Count, "A").End(xlUp).Row + 1
    
    
    With Sheets(CopySheet).Range(Cells(1, 1), Cells(Cells(Rows.Count, "A").End(xlUp).Row, Lastcolumn))
        .AutoFilter Field:=[COLOR=#ff0000]1[/COLOR], Criteria1:="[COLOR=#ff0000]Pending[/COLOR]"
        .Offset(1).Resize(.Rows.Count - 1).SpecialCells(xlCellTypeVisible).Copy Sheets(PasteSheet).Cells(Lastrow, 1)
    End With
Sheets(CopySheet).AutoFilterMode = False
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Assuming you want to filter a Sheet named "Sheet1" and copy those rows into a Sheet named "Sheet2"
And you want to filter the values in Column "A" which have the value "Pending"

Use this script.

Modify the sheet names marked in Red if your sheet names are not as mentioned above.
And modify the filter value and column to search as needed.

Code:
Sub Filter_Me()
'Modified 10-6-17 1:00 PM EDT
Application.ScreenUpdating = False
Dim Lastcolumn As Long
Dim CopySheet As String
Dim PastSheet As String
CopySheet = [COLOR=#ff0000]"Sheet1[/COLOR]"
PasteSheet = "[COLOR=#ff0000]Sheet2[/COLOR]"
Lastcolumn = Sheets(CopySheet).Cells(1, Columns.Count).End(xlToLeft).Column
Lastrow = Sheets(PasteSheet).Cells(Rows.Count, "A").End(xlUp).Row + 1
    
    
    With Sheets(CopySheet).Range(Cells(1, 1), Cells(Cells(Rows.Count, "A").End(xlUp).Row, Lastcolumn))
        .AutoFilter Field:=[COLOR=#ff0000]1[/COLOR], Criteria1:="[COLOR=#ff0000]Pending[/COLOR]"
        .Offset(1).Resize(.Rows.Count - 1).SpecialCells(xlCellTypeVisible).Copy Sheets(PasteSheet).Cells(Lastrow, 1)
    End With
Sheets(CopySheet).AutoFilterMode = False
Application.ScreenUpdating = True
End Sub

This is awesome!!! I didn't see a thank you on here, but thank you for posting this solution!!!

I received a run-time error 1004 "Application-defined or object-defined error" on this line:

With Sheets(CopySheet).Range(Cells(1, 1), Cells(Cells(Rows.Count, "A").End(xlUp).Row, Lastcolumn))

And I am trying to use your Filter / Copy / Paste with more than 1 AutoFilter criteria and my 2nd criteria is actually a defined variable.

With Sheets(CopySheet).Range(Cells(1, 1), Cells(Cells(Rows.Count, "A").End(xlUp).Row, Lastcolumn))
.AutoFilter Field:=1, Criteria1:="Pending"
.AutoFilter Field:=2, Criteria1:=DateToday

Can you help with the error and maybe post an example for multiple criteria?
 
Upvote 0
This is not a proper way:

.AutoFilter Field:=2, Criteria1:=DateToday

If should be:
.AutoFilter Field:=2, Criteria1:=Date

But not sure that is only problem.

I think you should start a new posting and explain in detail what you need.

<strike>
</strike>
 
Upvote 0

Forum statistics

Threads
1,223,237
Messages
6,170,930
Members
452,367
Latest member
TePunaBloke

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