|
这段代码是创建数据透视表的代码,我想问红色的代码是什么作用?为什么要这三行红色代码??
Dim ws As Worksheet
Dim ptcache As PivotCache
Dim pt As PivotTable
Dim prange As Range
Set ws = Sheet1
For Each pt In Sheet2.PivotTables
pt.TableRange2.Clear
Next pt
Set ptcache = ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:=Sheet1.Range("a1").CurrentRegion.Address)
Set pt = ptcache.CreatePivotTable(tabledestination:=Sheet2.Range("a3"), tablename:="透视表1")
pt.ManualUpdate = True
pt.AddFields RowFields:="项目", ColumnFields:="Data"
For Each prange In ws.Range(ws.Cells(1, 2), ws.Cells(1, 256).End(xlToLeft))
With pt.PivotFields(prange.Value)
.Orientation = xlDataField
.Name = " " & prange
.Function = xlSum
End With
Next prange
pt.ManualUpdate = False
pt.ManualUpdate = True |
|