![]()
Option Explicit Sub pivottb() Dim pt As PivotTable Dim pc As PivotCache Set pc = ThisWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:=ThisWorkbook.Worksheets("sheet1").Range("a1").CurrentRegion) Worksheets.Add Set pt = ActiveSheet.PivotTables.Add(PivotCache:=pc, Tabledestination:=ActiveSheet.Range("a1")) With pt .PivotFields("name").Orientation = xlRowField .PivotFields("age").Orientation = xlDataField .PivotFields("sale").Orientation = xlColumnField .PivotFields("profit").Orientation = xlPageField End With With pt.PivotFields("sale") .Caption = "count of net sales" .Function = xlCount End With End Sub
Bookmarks