|
VBA。
Sub yanjie()
Dim ws As Worksheet, pc As PivotCache, pt As PivotTable, pf As PivotField, pi As PivotItem
Application.ScreenUpdating = False
Set ws = Sheet2
Sheet1.Activate
For Each pt In ws.PivotTables
pt.TableRange2.Clear
Next
Set pc = ThisWorkbook.PivotCaches.Add(xlDatabase, Range("A1").CurrentRegion.Address)
Set pt = pc.CreatePivotTable(ws.Range("A13"), "透视表1")
pt.RowGrand = False
pt.ManualUpdate = True: pt.AddFields [c1:d1], "Data"
Set pf = pt.PivotFields(CStr([a1]))
With pf
.Orientation = xlDataField
.Name = "客户数"
.Function = xlCount
End With
Set pf = pt.PivotFields(CStr([c1]))
With pf
.Orientation = xlDataField
.Name = "销量"
.Function = xlSum
End With
pt.ManualUpdate = False
pt.ManualUpdate = True
Set pf = pt.RowFields(CStr([c1]))
pf.LabelRange.Group Start:=0, End:=True, by:=3
For Each pi In pf.PivotItems
pi.Name = pi.Name & "吨"
Next pi
pf.Orientation = xlColumnField
pt.DataPivotField.Position = 2
pt.ManualUpdate = False
pt.ManualUpdate = True
ws.Activate
MsgBox "透视表创建好了"
Application.ScreenUpdating = True
End Sub
这个也太难做了。 |
|