Ich verwende derzeit VBA in Excel 2010 und habe eine Pivot-Tabelle erstellt, die ich basierend auf bestimmten Dingen formatieren möchte. Ich versuche, die +/- Tasten aus der Tabelle mitDrill Indikatoren VBA Pivot Tabelle
entfernt zu bekommen, aber das funktioniert aus irgendeinem Grund nicht.
Hilfe wäre sehr willkommen!
Sub PivotTable_Creation_And_Formatting()
'PURPOSE: Creates a brand new Pivot table on a new worksheet from data in the ActiveSheet
Sheets("Sheet2").Select
Dim sht As Worksheet
Dim pvtCache As PivotCache
Dim pvt As PivotTable
Dim pf As PivotField
Dim StartPvt As String
Dim SrcData As String
Dim LastRow As Long
LastRow = Cells(Rows.Count, "A").End(xlUp).Row
'Determine the data range you want to pivot
SrcData = ActiveSheet.Name & "!" & Range(Cells(1, "A"), Cells(LastRow, "E")).Address
'Create a new worksheet
Set sht = Sheets("HOLDERS (CORP)")
'Where do you want Pivot Table to start?
StartPvt = sht.Range("A1").Address
'Create Pivot Cache from Source Data
Set pvtCache = ActiveWorkbook.PivotCaches.Create(_
SourceType:=xlDatabase, _
SourceData:=SrcData)
'Create Pivot table from Pivot Cache
Set pvt = pvtCache.CreatePivotTable(TableDestination:=sht.Range(StartPvt), _
TableName:="HoldersPivotTable")
pvt.PivotFields("SECURITY SHORT DESCRIPTION").Orientation = xlRowField
'Add item to the Row Labels
pvt.PivotFields("HOLDERS").Orientation = xlRowField
'Add item to the Row Labels
pvt.PivotFields("POSITION").Orientation = xlRowField
'Add item to the Row Labels
pvt.PivotFields("LATEST CHANGE").Orientation = xlRowField
'Add item to the Row Labels
pvt.PivotFields("FILE DT").Orientation = xlRowField
pvt.ColumnGrand = False
pvt.RowGrand = False
'Show in Tabular Form
pvt.RowAxisLayout xlTabularRow
For Each pf In pvt.PivotFields
pf.Subtotals(1) = True
pf.Subtotals(1) = False
Next pf
Sheets("HOLDERS (CORP)").Select
Columns("A:E").Select
Selection.Columns.AutoFit
Columns("C:C").ColumnWidth = 13.43
Columns("A:E").HorizontalAlignment = xlLeft
Columns("B:E").Interior.Color = RGB(141, 180, 226)
Range("A1").Interior.Color = RGB(141, 180, 226)
With Range("A1:E1").Borders
.LineStyle = xlContinuous
.Weight = xlMedium
End With
ActiveSheet.PivotTables("HoldersPivotTable").ShowDrillIndicators = False
Range("B1").Select
End Sub
Funktioniert es, wenn Sie es manuell tun oder ein Makro aufzeichnen hat? Die Schaltflächen "+/-" sind deaktiviert, wenn keine Pivot-Tabelle ausgewählt ist, daher müssen Sie sie möglicherweise auswählen oder nach der Zeile ".CreatePivotTable" versuchen – Slai