Mini12,
I think in fact you want something a little more dynamic - ie code along the lines of:
Public Sub MakePivotTable()
Dim pt As PivotTable, ptField As PivotField
Dim WSD As Worksheet, PTOutput As Worksheet
Dim PTCache As PivotCache
Dim PRange As Range
Dim finalRow As Long, finalCol As Long
Set WSD = Worksheets("Data")
Set PTOutput = Worksheets("Pivot")
With WSD
Set PRange = .Range(.Cells(1, "A"), .Cells(.Cells(.Rows.Count, "A").End(xlUp).Row, .Cells(1, .Columns.Count).End(xlToLeft).Column))
End With
Set PTCache = ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:=PRange)
Set pt = PTCache.CreatePivotTable(TableDestination:=Sheets.Add.Cells(3, 1), TableName:="SamplePivot")
With pt
.ManualUpdate = True
.AddFields RowFields:=Array("ID")
For Each ptField In .PivotFields
If InStr(UCase(ptField.Name), " POINTS") Then
.AddDataField ptField, , xlSum
End If
Next ptField
.ManualUpdate = False
End With
End Sub
The above will create the PT and iterate all fields adding any containing " Points" to the Data Field section.
Note in the above for testing I altered the destination of the PT to be a new sheet created at run-time (change as necessary).
Bookmarks