Sub 自动识别创建数据透视表()
Dim rng As Range
Dim PTC As PivotCache
Dim PVT As PivotTable
Dim pdata As String
ActiveCell.CurrentRegion.Select
Set rng = Selection
ActiveWindow.ScrollColumn = 1
Set PTC = ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:=rng, Version:=xlPivotTableVersion15)
Sheets.Add
pdata = ActiveSheet.Name & "!R3C1"
Set PVT = PTC.CreatePivotTable(TableDestination:=pdata, TableName:="数据透视表", DefaultVersion:=xlPivotTableVersion15)
Range("A3").Activate
End Sub
按钮封装版下载地址:
https://download.csdn.net/download/tzx200911911/21713914?spm=1001.2014.3001.5503
参考文献:
VBA创建数据透视表 备用连接:[转载]VBA创建数据透视表