I'm working on a book, and I need to add a pivot chart to each worksheet in my workbook. I have everything set up right now to do what I need on one of the pages, but i'm clueless on where even to begin trying to get it to cycle through each worksheet, excluding the first 4 worksheets. I'm sure there is some kind of easy fix, but like i said, i've got no clue. This is what I have so far:
Sub Macro7()
Dim pc As PivotCache, pt As PivotTable
Dim cht As Chart
Set pc = ActiveWorkbook.PivotCaches.create(SourceType:=xlDatabase, SourceData:= _
"ICS-GSD-Account Management!R2C1:R1106C8", Version:=xlPivotTableVersion10)
Set pt = pc.CreatePivotTable(TableDestination:=Sheets("ICS-GSD-Account Management").Cells(2, 9), _
TableName:="", DefaultVersion:=xlPivotTableVersion10)
Sheets("ICS-GSD-Account Management").Select
Cells(2, 9).Select
Set cht = ActiveSheet.Shapes.AddChart.Chart
With cht
.SetSourceData Source:=Sheets("ICS-GSD-Account Management").Range("$I$2:$O$15")
.ChartType = xlColumnClustered
End With
With ActiveSheet.PivotTables("").PivotFields("Date")
.Orientation = xlPageField
.Position = 1
End With
With ActiveSheet.PivotTables("").PivotFields("Time")
.Orientation = xlRowField
.Position = 1
End With
ActiveSheet.PivotTables("").AddDataField ActiveSheet.PivotTables(""). _
PivotFields("Handled"), "Sum of Handled", xlSum
ActiveSheet.PivotTables("").AddDataField ActiveSheet.PivotTables(""). _
PivotFields("Aband Within"), "Sum of Aband Within", xlSum
With ActiveSheet.PivotTables("").DataPivotField
.Orientation = xlColumnField
.Position = 1
End With
ActiveSheet.PivotTables("").AddDataField ActiveSheet.PivotTables(""). _
PivotFields("Aband Diff"), "Sum of Aband Diff", xlSum
ActiveSheet.PivotTables("").AddDataField ActiveSheet.PivotTables(""). _
PivotFields("Dequeued"), "Sum of Dequeued", xlSum
cht.ChartType = xlBarStacked
ActiveWorkbook.ShowPivotChartActiveFields = False
ActiveWorkbook.ShowPivotTableFieldList = False
cht.Legend.Select
cht.Legend.LegendEntries(4).Select
With cht.SeriesCollection(4)
.Interior.ColorIndex = 44
End With
With cht.Parent
.Width = 920
.Height = 560
.Left = 300
.Top = 15
End With
With ActiveSheet.PivotTables("").PivotFields("Date")
.PivotItems("2/1/2010").Visible = True
.PivotItems("2/2/2010").Visible = False
.PivotItems("2/3/2010").Visible = False
.PivotItems("2/4/2010").Visible = False
.PivotItems("2/5/2010").Visible = False
.PivotItems("2/6/2010").Visible = False
.PivotItems("2/7/2010").Visible = False
.PivotItems("2/8/2010").Visible = False
.PivotItems("2/9/2010").Visible = False
.PivotItems("2/10/2010").Visible = False
.PivotItems("2/11/2010").Visible = False
.PivotItems("2/12/2010").Visible = False
.PivotItems("2/13/2010").Visible = False
.PivotItems("2/14/2010").Visible = False
.PivotItems("2/15/2010").Visible = False
.PivotItems("2/16/2010").Visible = False
.PivotItems("2/17/2010").Visible = False
.PivotItems("2/18/2010").Visible = False
.PivotItems("2/19/2010").Visible = False
.PivotItems("2/20/2010").Visible = False
.PivotItems("2/21/2010").Visible = False
.PivotItems("2/22/2010").Visible = False
.PivotItems("2/23/2010").Visible = False
End With
ActiveSheet.PivotTables("").PivotFields("Date").EnableMultiplePageItems = True
End Sub
Bookmarks