I am trying to have my VBA code automatically filter for any values that exist for the last week but I am getting an error message back when my code runs. Not sure what the issue is, Ive looked all ove and this appears to work for others but for some reason i get "Run-time error '1004'.
Sub Last_Week()
Dim pt As PivotTable
Dim x As Date
Dim y As Date
Dim x2 As String
Dim y2 As String
Set pt = ActiveSheet.PivotTables("PivotTable4")
x = (Date - 7) - Application.WorksheetFunction.Weekday(Date, 3)
y = x + 6
x2 = Month(x) & "/" & Day(x) & "/" & Year(x)
y2 = Month(y) & "/" & Day(y) & "/" & Year(y)
With pt.PivotFields("Load_Date")
.ClearAllFilters
.PivotFilters.Add Type:=xlDateBetween, Value1:=x2, Value2:=y2
End With
pt.RefreshTable
'pt.PivotFields("Load_Date").PivotItems("").Visible = False
End Sub
Bookmarks