This is the layout I want: but this is what currently I get:
来自此代码:
Private Sub KPIDashboardTable()
Sheets("KPI Dashboard List").Activate
Dim objTable As PivotTable, objField As PivotField, Ws As Worksheet
ActiveWorkbook.Sheets("KPI Dashboard List").Range("A1").Select
Set Ws = Sheets.Add
Ws.Name = "KPI Dashboard List Table"
Set objTable = Sheets("KPI Dashboard List").PivotTableWizard(TableDestination:=Ws.Cells(3, "A"))
objTable.PivotCache.MissingItemsLimit = xlmissingItemNone
objTable.PivotCache.Refresh
Set objField = objTable.PivotFields("DATE OPENED")
objField.Orientation = xlRowField
Set objField = objTable.PivotFields("KPI")
objField.Orientation = xlDataField
objField.Function = xlSum
objField.Position = 1
Set objField = objTable.PivotFields("KPI")
objField.Orientation = xlDataField
Dim pf As PivotField
Set pf = ActiveSheet.PivotTables(1).PivotFields("DATE OPENED")
pf.DataRange.Cells(1).Group Start:=True, End:=True, Periods:=Array(False, False, _
False, False, True, False, False)
Range("B2").Value = "KPI Dashboard"
Range("A2:O2").Font.Bold = True
Range("A2:O2").Interior.Color = vbYellow
End Sub
如何更改数据透视表的方向?
答案 0 :(得分:0)
您需要添加:
With objTable.DataPivotField
.Orientation = xlColumnField
.Position = 1
End With