Katterman
Board Regular
- Joined
- May 15, 2014
- Messages
- 103
- Office Version
- 365
- Platform
- Windows
- Mobile
- Web
Hello Everyone
Relative newbie here but learning quickly from all of your vast knowledge.
I'm having some pivot table issues when a Macro used to create the Pivots (from a table data on a sheet) when used on different sheets.
The macro works fine on my original Data sheet but when the sheet is duplicated the pivot table creation macro fails.
I fairly sure it's because of Pivot Table names that can't be duplicated but i'm unsure how to get around it.
Some info on the end goal for this "workbook".
This workbook (Created Monthly) will have an identical worksheet generated for every day (Each Sheet is Named for that Month/Day EG: Sept 1, Sept 2 etc). The each sheet contains a "Table" that Data is imported into from 2 other sheets (Basically just Temp sheets to clean up the data pasted in from other sources) and once the import is done I run a Macro to create 3 Pivot Tables on the same sheet. This will be done every day on the corresponding date / sheet. The data imported onto the "Sheet of the day" will always be different since it's for reporting on the days before's activity. On the first sheet which is essentially the "template" that is used to create the sheets for the month (and where the macro was "recorded and Tweaked from for the pivot tables), everything works perfectly when the macro is run. On any subsequent sheets, The Pivot table creation fails when the macro runs..
One part i did get past was the fact the actual Table Name the Pivot table is created changes on each sheet
I Had
and Changed To
So far that went well but it fails further into the code now on every sheet except the original.
Like i said before, i'm sure it's because the Pivot table names (TableName:xxxx) need to not duplicate across the sheets
but unsure how to address.
Error is: Run-Time error '1004'
Select Method of Range class failed
and it Highlights" on this line when debugged.
Here is my one of the 3 sections of code (The other 2 sections are for the other 2 Pivot tables created from the same table)
Hopefully i'm going about this in the right direction but not opposed to being rerouted
Thanks In Advance for any and all replies.
Scott
Relative newbie here but learning quickly from all of your vast knowledge.
I'm having some pivot table issues when a Macro used to create the Pivots (from a table data on a sheet) when used on different sheets.
The macro works fine on my original Data sheet but when the sheet is duplicated the pivot table creation macro fails.
I fairly sure it's because of Pivot Table names that can't be duplicated but i'm unsure how to get around it.
Some info on the end goal for this "workbook".
This workbook (Created Monthly) will have an identical worksheet generated for every day (Each Sheet is Named for that Month/Day EG: Sept 1, Sept 2 etc). The each sheet contains a "Table" that Data is imported into from 2 other sheets (Basically just Temp sheets to clean up the data pasted in from other sources) and once the import is done I run a Macro to create 3 Pivot Tables on the same sheet. This will be done every day on the corresponding date / sheet. The data imported onto the "Sheet of the day" will always be different since it's for reporting on the days before's activity. On the first sheet which is essentially the "template" that is used to create the sheets for the month (and where the macro was "recorded and Tweaked from for the pivot tables), everything works perfectly when the macro is run. On any subsequent sheets, The Pivot table creation fails when the macro runs..
One part i did get past was the fact the actual Table Name the Pivot table is created changes on each sheet
I Had
Code:
Range("Table3[[#Headers],[Tech '#]]").Select
Code:
ActiveSheet.ListObjects(1).Range.Select
So far that went well but it fails further into the code now on every sheet except the original.
Like i said before, i'm sure it's because the Pivot table names (TableName:xxxx) need to not duplicate across the sheets
but unsure how to address.
Error is: Run-Time error '1004'
Select Method of Range class failed
and it Highlights" on this line when debugged.
Code:
ActiveSheet.PivotTables("VANPivot").PivotFields("Branch").CurrentPage = "VAN"
Here is my one of the 3 sections of code (The other 2 sections are for the other 2 Pivot tables created from the same table)
Code:
Sub Pivot_Tables_TEST()
Dim ShName As String
ShName = ActiveSheet.Name
With Application
.ScreenUpdating = False
End With
ActiveSheet.ListObjects(1).Range.Select
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"Table3", Version:=xlPivotTableVersion12).CreatePivotTable TableDestination _
:=Worksheets(ShName).Range("I5"), TableName:="VANPivot", DefaultVersion:= _
xlPivotTableVersion12
ActiveSheet.Select
Cells(5, 9).Select
With ActiveSheet.PivotTables("VANPivot").PivotFields("Branch")
.Orientation = xlPageField
.Position = 1
End With
With ActiveSheet.PivotTables("VANPivot").PivotFields("Area")
.Orientation = xlRowField
.Position = 1
End With
With ActiveSheet.PivotTables("VANPivot").PivotFields("Tech Name")
.Orientation = xlRowField
.Position = 2
End With
ActiveSheet.PivotTables("VANPivot").AddDataField ActiveSheet.PivotTables( _
"VANPivot").PivotFields("WO"), "Count of WO", xlCount
ActiveSheet.PivotTables("VANPivot").PivotFields("Branch").ClearAllFilters
ActiveSheet.PivotTables("VANPivot").PivotFields("Branch").CurrentPage = _
"VAN"
ActiveWorkbook.ShowPivotTableFieldList = False
With Application
.ScreenUpdating = True
End With
End Sub
Hopefully i'm going about this in the right direction but not opposed to being rerouted
Thanks In Advance for any and all replies.
Scott