I have a number of worksheets that are used as source data for pivot tables (one per table). Ideally I would like for my vba to add a new sheet for the pivot table and rename it accordingly. Right now the code adds a new sheet based on how many sheets there are. More specifically, "TableDestination:="A hard-coded sheet number",...
Would appreciate some help on making this line more dynamic as I will not always know how many sheets the workbook already has. Thanks!
Would appreciate some help on making this line more dynamic as I will not always know how many sheets the workbook already has. Thanks!
Code:
'Pivot Table
Sheets.Add
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"SourceWorksheet", Version:=xlPivotTableVersion14).CreatePivotTable _
TableDestination:="Sheet23!R3C1", TableName:="Source_PIVOT", DefaultVersion _
:=xlPivotTableVersion14
'Rename pivot table sheet
ActiveSheet.Name = "Source_PIVOT"
Sheets("Source_PIVOT").Select
Cells(3, 1).Select