피벗 테이블을 만들었으며 피벗 테이블의 다른 두 열 사이의 차이 (값)를 인쇄 할 열을 추가하려고합니다. 필자는 피벗 테이블 작성과 관련한 제 코드 부분을 제공 할 것입니다. 그것이 분명하기 때문에, 나는 그것의 마지막 부분에서 무언가를 시도했지만, 아무것도 인쇄하지 않을 것이다. 그것은 실행되지만 아무것도 인쇄하지 않습니다. 피벗 테이블이 올바르게 인쇄되지만 새 열은 인쇄되지 않습니다.피벗 테이블에 계산 된 필드 추가
Dim DSheet As Worksheet
Dim PCache As PivotCache
Dim PTable As PivotTable
Dim PRange As Range
Application.DisplayAlerts = True
Set DSheet = Worksheets("Budget_Report")
Set PRange = DSheet.Range(Cells(1, 27), Cells.SpecialCells(xlCellTypeLastCell))
Set PCache = ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:=PRange)
Set PTable = PCache.CreatePivotTable(TableDestination:=DSheet.Cells(15, 1), TableName:="PivotTable1")
With ActiveSheet.PivotTables("PivotTable1")
With .PivotFields("T-Lane")
.Orientation = xlRowField
.Position = 1
.Subtotals(1) = True
.Subtotals(1) = False
End With
With .PivotFields("Monthly Cost FCST")
.Orientation = xlDataField
.Position = 1
.Function = xlAverage
.NumberFormat = "0.00"
.Caption = "Monthly Cost Forecast"
End With
With .PivotFields("Monthly Vol FCST")
.Orientation = xlDataField
.Position = 2
.Function = xlAverage
.NumberFormat = "0.00"
.Caption = "Monthly Vol Forecast"
End With
With .PivotFields("Monthly $/SU FCST")
.Orientation = xlDataField
.Position = 3
.Function = xlAverage
.NumberFormat = "0.00"
.Caption = "Monthly $/SU Forecast"
End With
With .PivotFields("Monthly Cost Actuals")
.Orientation = xlDataField
.Position = 4
.Function = xlSum
.NumberFormat = "0.00"
.Caption = "Monthly Cost Actual"
End With
With .PivotFields("Monthly Vol Actuals")
.Orientation = xlDataField
.Position = 5
.Function = xlSum
.NumberFormat = "0.00"
.Caption = "Monthly Vol Actual"
End With
With .PivotFields("Monthly $/SU Actuals")
.Orientation = xlDataField
.Position = 6
.Function = xlAverage
.NumberFormat = "0.00"
.Caption = "Monthly $/SU Actual"
End With
.CalculatedFields.Add "Diff", "= 'Monthly Cost FCST'- 'Monthly Cost Actuals'"
End With
체크 https://stackoverflow.com/a/26970322/7889129 – Maddy
매크로 레코더가 제작 한 것이보고하고 적응하려고 했습니까? – QHarr