When I run this code, it creates a pivot table on a new sheet. How do I get it so the sheet is always called "HHH Pivot Table"? The sheet number is not always the same.
VBA Code:
'HHH Overtime Check
Sheets("Combined Time").Select
Dim rng2 As Range
Dim sht2 As Worksheet
Dim pTable2 As PivotTable
Set rng2 = ActiveSheet.Cells(1, 1).CurrentRegion
Set sht2 = ActiveWorkbook.Worksheets.Add
Set pTable2 = ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
rng2.Address, Version:=8).CreatePivotTable(TableDestination:= _
sht2.Cells(1, 1), TableName:="PivotTable" & Format(Time, "hhmmss"))
With pTable2
With .PivotFields("DOB")
.Orientation = xlPageField
End With
With .PivotFields("PR Code")
.Orientation = xlPageField
Dim P2 As PivotItem
.EnableMultiplePageItems = True
For Each P2 In .PivotItems
If P2 = "HHH" Then
P2.Visible = True
Else
P2.Visible = False
End If
Next P2
End With
With .PivotFields("SSN")
.Orientation = xlRowField
.Subtotals(1) = False
End With
.PivotFields("Reg Hours").Orientation = xlDataField
End With