vba创建自定义页透视表,多重和计算区域透视表的创建
注意
手动打开要统计的工作簿,且工作簿中的格式都相同,并且没有其他多余的表,代码需要根据自己的需求自行调整,会有比较大的功能差异
完整代码
Sub 创建自定义页透视表()
'
'排序表,创建自定义页透视表
'
'
'ActiveWorkbook.ActiveSheet.PivotTables (1)
Dim arr() As Workbook, yearArr() As String, dataArr() As Variant
Dim startCell As Range, dataRange As Range, foundCell As Range
Dim n, k, startRow, startCol, endRow, endCol
Dim docName, PathStr As String, className
Set startCell = Application.InputBox("请选择第一个类名所在单元格:", "操作提示!", "$B$3", , , , , 8)
className = startCell.Formula
n = Workbooks.Count
k = 1
'Workbooks(1).Sheets(1).Name
ReDim arr(1 To n)
ReDim yearArr(1 To n)
ReDim dataArr(1 To n)
'查找多张表的同类数据源
For i = 1 To n
Set arr(i) = Workbooks(i) '要统计的所有工作簿