A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
Hi,
sceanario:
create a new pivot table in sheet2
data in sheet1
try this...
Sub Add_New_PivotTable()
'May 29, 2017
Dim ws1 As Worksheet
Set ws1 = Sheets(**"Sheet1")' << data in sheet1 / '**usd cash liabilities'
Dim ws2 As Worksheet
Set ws2 = Sheets**("Sheet2") ' << pivot table in sheet2 / '**usd Result'
'
'## delete old pivot table from sheet2/if exists
On Error Resume Next
ws2.PivotTables(1).TableRange2.Clear
'
Dim pc As PivotCache
Dim pt As PivotTable
'## create pivot cache
Set pc = ActiveWorkbook.PivotCaches.Create(xlDatabase, ws1.Range("A1:R100")) '<< data in sheet1
'## create pivot table
Set pt = ws2.PivotTables.Add(PivotCache:=pc, Tabledestination:=ws2.Range("A3")) '<< pivot table / top left cell
pt.Name = "PivotTable1"
'....
'next code here....
'.......