【发布时间】:2014-11-21 14:59:34
【问题描述】:
我刚学VBA,还不完全熟悉。
只有当数据透视表不存在时,我才想创建一个具有动态范围的数据透视表。如果表已经存在,那么枢轴突需要刷新。
到目前为止我有这个:
Sub CreatingPivot()
Dim PCache As PivotCache, LastRow As Long, pt As PivotTable
Dim ws As Worksheet
On Error Resume Next
Set ws = Sheets("Pivot")
If Err.Number <> 0 Then
Worksheets("Sheet1").Activate
Set PCache = ActiveWorkbook.PivotCaches.Create(SourceType:=1, SourceData:=Range("A1").CurrentRegion.Address)
Worksheets.Add
ActiveSheet.Name = "Pivot"
ActiveWindow.DisplayGridlines = False
Set pt = ActiveSheet.PivotTables.Add(PivotCache:=PCache, TableDestination:=Range("A1"), TableName:="PivotTable1")
Else
Sheets("Pivot").RefreshTable
End If
End Sub
【问题讨论】:
标签: vba excel pivot pivot-table