J
John Menken
Hi, I'm in Excel 2010 and using the code below to do some pivot table
work. In several of the lines of code the pivot table is identified as
PivotTable6. This worries me because I want it to be able to run on
Pivot tables of the future that will most likely not have that name.
Is there a way that I can modify this code to have it identify the
pivot table correctly without actually using its name? Many thanks.
Sheets.Add
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase,
SourceData:= _
"My Calcs!R1C1:R109C23",
Version:=xlPivotTableVersion10).CreatePivotTable _
TableDestination:="Sheet1!R3C1", TableName:="PivotTable6",
DefaultVersion _
:=xlPivotTableVersion10
Sheets("Sheet1").Select
Cells(3, 1).Select
With ActiveSheet.PivotTables("PivotTable6").PivotFields("Mgr E-
mail")
.Orientation = xlRowField
.Position = 1
End With
Range("A9").Select
With ActiveSheet.PivotTables("PivotTable6")
.ColumnGrand = False
.RowGrand = False
End With
Range("A6").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
MsgBox "The Macro is paused until you paste the email addresses in
an Outlook email. Click OK when complete"
work. In several of the lines of code the pivot table is identified as
PivotTable6. This worries me because I want it to be able to run on
Pivot tables of the future that will most likely not have that name.
Is there a way that I can modify this code to have it identify the
pivot table correctly without actually using its name? Many thanks.
Sheets.Add
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase,
SourceData:= _
"My Calcs!R1C1:R109C23",
Version:=xlPivotTableVersion10).CreatePivotTable _
TableDestination:="Sheet1!R3C1", TableName:="PivotTable6",
DefaultVersion _
:=xlPivotTableVersion10
Sheets("Sheet1").Select
Cells(3, 1).Select
With ActiveSheet.PivotTables("PivotTable6").PivotFields("Mgr E-
mail")
.Orientation = xlRowField
.Position = 1
End With
Range("A9").Select
With ActiveSheet.PivotTables("PivotTable6")
.ColumnGrand = False
.RowGrand = False
End With
Range("A6").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
MsgBox "The Macro is paused until you paste the email addresses in
an Outlook email. Click OK when complete"