It's not really clear to me what you're overall workflow is here - ie are you constantly adding a new Pivot or is it your intention to use a single dynamic range as the source for the Pivot ?
In terms of automating the addition of fields to the PT, in basic terms:
Dim PT As PivotTable, lngField As Long
Application.ScreenUpdating = False
Set PT = Sheets("Sheet2").PivotTables("PivotTable1")
With PT
.ManualUpdate = True
For lngField = 1 To .PivotFields.Count Step 1
If lngField = 1 Then
.AddFields .PivotFields(lngField).Name
Else
.AddDataField(.PivotFields(lngField)).Function = xlSum
End If
Next lngField
.ManualUpdate = False
End With
Set PT = Nothing
Application.ScreenUpdating = True
adjust as necessary... in terms of determining the data source that should be straightforward enough I think ?
Bookmarks