|
Sub 数据透视表()
'
' 数据透视表 Macro
' 宏由 浩海技术 录制,时间: 2008-12-18
'
' 快捷键: Ctrl+t
Dim Sht As Worksheet, Arr
Dim wk As Workbook
Set wk = ActiveWorkbook
n = Sheets.Count
ReDim Arr(n)
For Each Sht In Sheets
Sht.Activate
r = r + 1
Arr(r) = "'" & Sht.Name & "'!R1C1:R24C4"
wk.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
Arr(r)).CreatePivotTable TableDestination:="", TableName:= _
"数据透视表" & i, DefaultVersion:=xlPivotTableVersion10
ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells(3, 1)
ActiveSheet.Cells(3, 1).Select
With ActiveSheet.PivotTables("数据透视表" & i).PivotFields("业务员")
.Orientation = xlRowField
.Position = 1
End With
With ActiveSheet.PivotTables("数据透视表" & i).PivotFields("结算方式")
.Orientation = xlColumnField
.Position = 1
End With
ActiveSheet.PivotTables("数据透视表" & i).AddDataField ActiveSheet.PivotTables("数据透视表" & i _
).PivotFields("金额"), "求和项:金额", xlSum
With ActiveSheet.PivotTables("数据透视表" & i).PivotFields("付款单位")
.Orientation = xlPageField
.Position = 1
End With
ActiveSheet.Name = Sht.Name & "表"
Next
End Sub |
|