Example uses macro recorder
Here is my data (column A,B,C)
Name | Month | Salary | |||
Frank | Jan | 20 | |||
Frank | Feb | 22 | |||
Frank | Mar | 33 | |||
Bob | Jan | 30 | |||
Bob | Feb | 35 | |||
Bob | Mar | 35 |
and here is my simple macro:
Sub Macro1()
'
' Macro1 Macro
'
'
Range("A1:C7").Select
Sheets.Add
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"Sheet1!R1C1:R7C3", Version:=xlPivotTableVersion14).CreatePivotTable _
TableDestination:="Sheet5!R3C1", TableName:="PivotTable2", DefaultVersion _
:=xlPivotTableVersion14
Sheets("Sheet5").Select
Cells(3, 1).Select
With ActiveSheet.PivotTables("PivotTable2").PivotFields("Name")
.Orientation = xlRowField
.Position = 1
End With
ActiveSheet.PivotTables("PivotTable2").AddDataField ActiveSheet.PivotTables( _
"PivotTable2").PivotFields("Salary"), "Sum of Salary", xlSum
End Sub
No comments:
Post a Comment