|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub qs() '2024/6/28透视法
Application.ScreenUpdating = False
Sheet1.Range("s:z").Clear
Dim hc As PivotCache '定义缓存
Dim ts As PivotTable '定义透视表
ar = Sheet1.Range("b1") '行标签可用数组
Set hc = ThisWorkbook.PivotCaches.Create(xlDatabase, Sheet1.Range("a1").CurrentRegion, 4)
Set ts = hc.CreatePivotTable(Sheets("Sheet1").[s1], "表1", True, 4)
With ts
.AddFields ar, "产品" '.AddFields ar, "评级"(ar为行字段,评级为列地段)
.AddDataField .PivotFields("金额"), "金额求和", xlSum
.ColumnGrand = False '列禁用合计
.RowGrand = False '行禁用合计
.RowAxisLayout xlTabularRow '经典布局
End With
Range("S2:Z1800").Copy
Range("H1").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Sheet1.Range("s:z").Clear
Application.ScreenUpdating = True
End Sub |
评分
-
1
查看全部评分
-
|