Guten Tag
Ich habe folgenden VBA code, der mir ermöglicht, Daten aus einer Pivottabelle nach dem Pivotfeld "Basin" zu durchlaufen und in ein anderes Tabellenblatt auszulesen:
Modul1:
Sub Macro1()
'
' Macro1 Macro
'
'
ActiveSheet.PivotTables("PivotTable1").PivotFields("Basin").CurrentPage = _
"(All)"
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Basin")
.PivotItems("AM GAL").Visible = False
.PivotItems("AM BRE").Visible = False
.PivotItems("AM SES").Visible = False
.PivotItems("AM MED").Visible = False
.PivotItems("AM LOR").Visible = False
.PivotItems("AM API ESP").Visible = False
.PivotItems("AM API IT").Visible = False
.PivotItems("AM LIE").Visible = False
.PivotItems("AM EH").Visible = False
.PivotItems("AM GEN").Visible = False
.PivotItems("AM ATL").Visible = False
.PivotItems("AM OST").Visible = False
.PivotItems("AM POL").Visible = False
.PivotItems("AM SAG").Visible = False
.PivotItems("AM PIO").Visible = False
.PivotItems("AM SKO").Visible = False
End With
Range("D13").Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
Sheets.Add After:=ActiveSheet
ActiveSheet.Paste
ActiveSheet.Paste
Application.CutCopyMode = False
Range("A2").Select
Sheets("Pivot").Select
ActiveSheet.PivotTables("PivotTable1").PivotFields("Basin").CurrentPage = _
"(All)"
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Basin")
.PivotItems("AM AST").Visible = False
.PivotItems("AM GAL").Visible = True
End With
Range("D13").Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
ActiveSheet.Next.Select
ActiveSheet.Paste
ActiveSheet.Previous.Select
End Sub
Modul2:
ub PivotLoop()
Dim Pvtable As PivotTable
Dim PTItem As PivotItem
Summary_Start = 2
Set Pvtable = Worksheets("Pivot").PivotTables(1)
For Each PTItem In Pvtable.PivotFields("Basin").PivotItems
Pvtable.PivotFields("Basin").CurrentPage = PTItem.Name
For i = 3 To 6
Sheets("GAP").Range("D" & i + Grange & ":K" & i + Grange).Copy
Sheets("Summary").Range("A" & Summary_Next + Summary_Start) = PTItem.Name
Sheets("Summary").Range("B" & Summary_Next + Summary_Start).PasteSpecial Paste:=xlPasteValues
Grange = Grange + 3
Summary_Start = Summary_Start + 18
Next i
Grange = 0
Summary_Start = 2
Summary_Next = Summary_Next + 1
Next PTItem
End Sub
---
Ich möchte nun aber nicht mehr nach "Basin" die Pivottabelle durchlaufen lassen, sondern nach "ProductGroup".
Was muss ich dementsprechend in dem VBA code ändern?
Vielen Dank für jegliche Hilfe.
Scenario |
Market Division |
|
|
Budget Draft 3 2015 |
1st choice pure |
|
|
MRF_4_2015Q3 |
Q3 |
|
|
Account Group |
(All) |
|
|
Commercial Unit |
(All) |
|
|
Basin |
(All) |
|
|
Account Group CA/LA |
(All) |
|
|
|
|
|
|
|
|
|
Scenario & Period (Quarter) |
|
|
|
Budget Draft 3 2015Q3 |
Market Division |
Customer Aggregate 3 |
ProductGroup |
Weight (ton) |
IN |
EP |
HP |
185 |
|
|
HRNP |
10000 |
|