|
- Sub 数据透视表样式()
- Dim rng As Range
- Set rng = Range("A1").CurrentRegion
- Worksheets("Sheet1").PivotTableWizard SourceType:=xlDatabase, SourceData:=rng, _
- TableDestination:=Range("G4"), TableName:="我的表1", _
- RowGrand:=True, ColumnGrand:=True
- '--------------------------------------------------------------Range("G4")是你要放透视表的位置
- '--------------------------------------------------------------以上是建立透视表的样式,下面就可以录制宏来达到你的要求了
- With ActiveSheet.PivotTables("我的表1").PivotFields("姓名")
- .Orientation = xlRowField
- .Position = 1
- End With
- With ActiveSheet.PivotTables("我的表1").PivotFields("课程")
- .Orientation = xlColumnField
- .Position = 1
- End With
- ActiveSheet.PivotTables("我的表1").AddDataField ActiveSheet.PivotTables("我的表1"). _
- PivotFields("成绩"), "求和项:成绩", xlSum
- End Sub
复制代码
试试吧 |
|