PIVT2

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

Dim rngData As Range

Dim LastRow As Long


Dim LastCol As Long
Dim pvtItm As PivotItem
Dim ListFields(0 To 5) As String
Dim PivotTable_Name(0 To 3) As String
Dim i As Integer
Dim j As Integer
Dim k As Integer

''read line if problem change PivotTable_Name(n) = "PivotTable" & "n" to


PivotTable_Name(n) = "PivotTable" & n (take the " out of the n) –

**For k = 0 To 3
For n = 0 To 3
PivotTable_Name(n) = "PivotTable" & "n"
Next n

wsPvtTbl.PivotTables.Add PivotCache:=PvtTblCache,
TableDestination:=wsPvtTbl.Cells(3, 1 + 4 * k), TableName:=PivotTable_Name(k),
DefaultVersion:=xlPivotTableVersion11
Set PvtTbl = wsPvtTbl.PivotTables(PivotTable_Name(k))**

PvtTbl.ManualUpdate = True

For j = 0 To LastCol - 1
ListFields(j) = wsData.Cells(1, j + 1)
Next j

'add row, column and page (report filter) fields:


Set pvtFld = PvtTbl.PivotFields(ListFields(1))
pvtFld.Orientation = xlPageField

Set pvtFld = PvtTbl.PivotFields(ListFields(2))


pvtFld.Orientation = xlRowField

For i = 3 To LastCol - 1
With PvtTbl.PivotFields(ListFields(i))
.Orientation = xlDataField
.Function = xlSum
.NumberFormat = "#,##0"
.Position = i - 2
End With
Next i
PvtTbl.ManualUpdate = False
Next k

End Sub

You might also like