Requesting help with setting up a macro to autofilter multiple criteria, copying visible data only, and selecting and pasting sections of the data at a time into another worksheet in the file.
Here is a previous post that works for single criteria:
https://www.mrexcel.com/forum/excel...le-cells-after-auto-filter-except-header.html
I am using the code below and getting this error
"Run-time error '1004':
Application-defined or object-defined error"
Sub Filter()
Dim DateToday As Date
DateToday = Date$
Application.ScreenUpdating = True
Dim Lastcolumn As Long
Dim CopySheet As String
Dim PastSheet As String
CopySheet = "Absent_General"
PasteSheet = "Absent"
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:=13, Criteria1:="Absent"
.AutoFilter Field:=14, Criteria1:=DateToday
.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
I am using criteria DateToday as a variable assigned with today's date. I need to search the data on the first worksheet named 'Absent_General' and paste it into the 'Absent' worksheet. In the original code, it only used 1 criteria for filtering, copying the sections, and pasting. I need to add 2 criteria with the code:
.AutoFilter Field:=13, Criteria1:="Absent"
.AutoFilter Field:=14, Criteria1:=DateToday
And its not working. Any help / advice would be greatly appreciated!
Here is a previous post that works for single criteria:
https://www.mrexcel.com/forum/excel...le-cells-after-auto-filter-except-header.html
I am using the code below and getting this error
"Run-time error '1004':
Application-defined or object-defined error"
Sub Filter()
Dim DateToday As Date
DateToday = Date$
Application.ScreenUpdating = True
Dim Lastcolumn As Long
Dim CopySheet As String
Dim PastSheet As String
CopySheet = "Absent_General"
PasteSheet = "Absent"
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:=13, Criteria1:="Absent"
.AutoFilter Field:=14, Criteria1:=DateToday
.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
I am using criteria DateToday as a variable assigned with today's date. I need to search the data on the first worksheet named 'Absent_General' and paste it into the 'Absent' worksheet. In the original code, it only used 1 criteria for filtering, copying the sections, and pasting. I need to add 2 criteria with the code:
.AutoFilter Field:=13, Criteria1:="Absent"
.AutoFilter Field:=14, Criteria1:=DateToday
And its not working. Any help / advice would be greatly appreciated!