Ich verwende VBA, um eine Pivot-Tabelle zu erstellen. Die Tabelle hat einige Filter und ich kann nicht mehrere Elemente aus dem Filter auswählen.Auswählen mehrerer Elemente in Excel-Pivot-Tabellenfilter
nahm ich ein Makro und verwendet die gleichen Funktionen wie der Systemcode erzeugt, aber ich bin immer
"Run-time error '1004': Unable to set the CurrentPage Property of the PivotField Class"
Unten ist der Code, der die Pivot-Tabelle zu erstellen, das funktioniert:
Dim objTable As PivotTable
Dim objField As PivotField
' Select the sheet and first cell of the table that contains the data.
ActiveWorkbook.Sheets("All Projects - iNexus").Select
Range("A1").Select
' Create the PivotTable object based on the Employee data on Sheet1.
Set objTable = ActiveSheet.PivotTableWizard
' Specify row and column fields.
Set objField = objTable.PivotFields("Product")
objField.Orientation = xlRowField
Set objField = objTable.PivotFields("SPA Value Category")
objField.Orientation = xlColumnField
' Specify a data field with its summary
' function and format.
Set objField = objTable.PivotFields("2014 FY Value ($)")
objField.Orientation = xlDataField
objField.Function = xlSum
objField.NumberFormat = "$ #,##0"
Set objField = objTable.PivotFields("2015 FY Value ($)")
objField.Orientation = xlDataField
objField.Function = xlSum
objField.NumberFormat = "$ #,##0"
ActiveSheet.Name = "iNexus Pivot"
' Rename the pivot table
With Sheets("iNexus Pivot")
.PivotTables(1).Name = "PivotTable2"
End With
With Sheets("iNexus Pivot").PivotTables("PivotTable2").DataPivotField
.Orientation = xlColumnField
End With
Dies ist Code, den ich aus dem aufgezeichneten Makro bekam mehrere Artikel aus dem aufgezeichneten Makro wählen:
ActiveSheet.PivotTables("PivotTable2").PivotFields("Project Status"). _
CurrentPage = "(All)"
With ActiveSheet.PivotTables("PivotTable2").PivotFields("Project Status")
.PivotItems("A").Visible = False
.PivotItems("B").Visible = False
.PivotItems("C").Visible = False
End With
ActiveSheet.PivotTables("PivotTable2").PivotFields("Project Status"). _
EnableMultiplePageItems = True
Sowohl CurrentPage als auch PivotItems scheinen die Ursache des Problems zu sein, meine VBA-Fähigkeiten sind sehr begrenzt und ich kann das Problem nicht beheben.
Danke. Schätze die Hilfe.
Ist das Projektstatusfeld ein "Report Filter" oder ein "Row Label" (oder "Column Label"). Der Code ist je nachdem etwas unterschiedlich. –
@ScottHoltzman: In diesem speziellen Fall ist es ein Bericht Filter, aber ich habe auch einen Spaltenfilter. Ich nehme an, der Unterschied zwischen Bericht, Zeile und Spalte ist nicht zu groß. – Yuvaraj