I keep getting an compile error with the script below. Am I doing something wrong?
Code:
Sub PivotTest1()
Dim pvt1 As PivotTable
Dim pf1 As String
Dim pf1_Name As String
Set pvt1 = ActiveSheet.PivotTables("PivotTable3")
pf1 = "(Annual) Adj Close"
pf1_Name = "Annual Close"
pvt1.PivotFields("Month").Orientation = xlHidden
pvt1.PivotFields ("Year")
.Orientation = xlRowField
.Position = 2
pvt1.PivotFields("Monthly Close").Orientation = xlHidden
pvt1.AddDataField pvt1.PivotFields("(Annual) Adj Close"), pf1_Name, xlSum
'Is below not needed?
With pvt1.PivotFields("Annual Close")
.Caption = "Annual Close"
.Function = xlAverage
.NumberFormat = "0.00"
End With
End Sub