I have a macro that creates a pivot table and adds a filter called "PR Code". Everything works perfect, but is there a way to include the filter criteria in the VBA code? I only want to select PR Codes = 9J9 & 9AJ.
VBA Code:
'Overtime Check
Sheets("Combined Time").Select
Dim rng1 As Range
Dim sht1 As Worksheet
Dim pTable1 As PivotTable
Set rng1 = ActiveSheet.Cells(1, 1).CurrentRegion
Set sht1 = ActiveWorkbook.Worksheets.Add
sht1.Name = "Overtime Pivot"
Set pTable1 = ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
rng1.Address, Version:=8).CreatePivotTable(TableDestination:= _
sht1.Cells(1, 1), TableName:="PivotTable" & Format(Time, "hhmmss"))
With pTable1
With .PivotFields("DOB")
.Orientation = xlPageField
End With
With .PivotFields("PR Code")
.Orientation = xlPageField
End With
With .PivotFields("SSN")
.Orientation = xlRowField
.Subtotals(1) = False
End With
.PivotFields("Reg Hours").Orientation = xlDataField
End With
Columns("A:B").Select
Selection.Copy
Columns("D:E").Select
ActiveSheet.Paste
End Sub