Hello,
I am trying to filter data from one sheet and copy/paste that filtered data over into a summary sheet. I have 2 criteria that, if met, need to go into two separate summary tables. I am able to get the data filtered and copied, however, when it pastes into the respective tables, it is overwriting the total row at the bottom of the tables. I need the data that is copied to go into the bottom of the tables, but above the last row of the tables so that the total rows are not affected.
I am trying to filter data from one sheet and copy/paste that filtered data over into a summary sheet. I have 2 criteria that, if met, need to go into two separate summary tables. I am able to get the data filtered and copied, however, when it pastes into the respective tables, it is overwriting the total row at the bottom of the tables. I need the data that is copied to go into the bottom of the tables, but above the last row of the tables so that the total rows are not affected.
VBA Code:
Option Explicit
Sub FilterAndCopy()
Application.ScreenUpdating = False
Application.EnableEvents = False
Application.Calculation = xlCalculationManual
Dim lngLastRow As Long
Dim col As Integer
Dim ws1 As Worksheet, ws2 As Worksheet
Set ws1 = Sheets("WH Locations")
Set ws2 = Sheets("Summary")
lngLastRow = ws1.Cells(Rows.Count, "H").End(xlUp).Row
With Range("A31", "H" & lngLastRow)
.AutoFilter
.AutoFilter Field:=8, Criteria1:="C"
.Offset(1, 0).Resize(.Rows.Count - 1).Copy Destination:=ws2.ListObjects("Table2")
.AutoFilter Field:=8, Criteria1:="D"
.Offset(1, 0).Resize(.Rows.Count - 1).Copy Destination:=ws2.ListObjects("Table3")
.AutoFilter
End With
Application.ScreenUpdating = True
Application.EnableEvents = True
Application.Calculation = xlCalculationAutomatic
End Sub