请问如何用VBA自动编写数据透析表
vba吧
全部回复
仅看楼主
level 2
柒墨1999 楼主
2024年07月22日 00点07分 1
level 6
Dim PivCachA As PivotCache
Dim PivTableA As PivotTable
Dim PivFielA As PivotField
Dim R1
Call Start
WsC.Cells.ClearContents
Set PivCachA = WbA.PivotCaches.Create(SourceType:=xlDatabase, SourceData:="AgingList", Version:=5)
Set PivTableA = PivCachA.CreatePivotTable(TableDestination:=WsC.Range("A1"), TableName:="Aging", DefaultVersion:=5)
With PivTableA
.PivotFields("Company Code").Orientation = xlPageField
.PivotFields("Company Code").Position = 1
.PivotFields("Customer Code").Orientation = xlRowField
.PivotFields("Customer Code").Position = 1
.PivotFields("Customer Name").Orientation = xlRowField
.PivotFields("Customer Name").Position = 2
With .PivotFields("Duration")
.Orientation = xlColumnField
.Position = 1
.PivotItems("Undue").Position = 1
.PivotItems("1-30D").Position = 2
.PivotItems("31-60D").Position = 3
.PivotItems("61-90D").Position = 4
.PivotItems("91-180D").Position = 5
.PivotItems("181-365D").Position = 6
.PivotItems(">365D").Position = 7
End With
.AddDataField .PivotFields("Amount(USD)"), "Amount(USD) ", xlSum
.RowAxisLayout xlTabularRow
.ColumnGrand = False
For Each PivFielA In .PivotFields
For R1 = 1 To UBound(PivFielA.Subtotals)
PivFielA.Subtotals(R1) = False
Next R1
Next PivFielA
.PivotFields("Company Code").ClearAllFilters
.PivotFields("Company Code").CurrentPage = "AU10"
End With
2024年07月24日 09点07分 2
谢谢大佬
2024年09月14日 16点09分
@柒墨1999 补充一下,WsC是工作表,WbA是工作簿
2024年09月16日 01点09分
1