Hello!
I am attempting to create a dynamic code to create a Pivot Table. I run multiple reports at work and each needs the same Pivot Table, so I'm trying to save myself some time.
The issue I'm encountering is the SourceData. I cannot designate a particular Table because that will change from report to report. I attempted to replace the source with a range, but that did not work.
Any assistance would be greatly appreciated!
I am attempting to create a dynamic code to create a Pivot Table. I run multiple reports at work and each needs the same Pivot Table, so I'm trying to save myself some time.
The issue I'm encountering is the SourceData. I cannot designate a particular Table because that will change from report to report. I attempted to replace the source with a range, but that did not work.
Any assistance would be greatly appreciated!
Code:
Sheets.Add
ActiveSheet.Name = "In Program Pivot"
[COLOR=#008000]Dim tri As Long[/COLOR]
[COLOR=#008000]tri = Sheets("In Program").Select.Range("A1:O" & Range("O" & Rows.Count).End(xlUp).Row)[/COLOR]
Sheets("In Program Pivot").Select
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, [COLOR=#008000]SourceData:= _[/COLOR]
[COLOR=#008000] "tri"[/COLOR], Version:=xlPivotTableVersion15).CreatePivotTable TableDestination _
:="'In Program Pivot'!R3C1", TableName:="PivotTable1", DefaultVersion:= _
xlPivotTableVersion15
Sheets("In Program Pivot").Select
Cells(3, 1).Select
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Member Name")
.Orientation = xlRowField
.Position = 1
End With