Logo 
Search:

MS Office Answers

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds
  Question Asked By: Keana Schmidt   on Mar 16 In MS Office Category.

  
Question Answered By: Katrina Edwards   on Mar 16

Here is my code (using macreo recorder).

Sub By_Product_and_by_Branch()
'
' By_Product_and_by_Branch Macro
' Macro recorded 5/25/2007 by XXX
'

'
Dim pt As PivotTable
Dim ps As PivotCache
Dim ws As Worksheet
Set ws = Worksheets("Pivot")
For Each pt In ws.PivotTables
pt.TableRange2.Clear
Set ps = Nothing
Next pt


Sheets("Pivot").Select
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
"Detail!R1C1:R330C16").CreatePivotTable TableDestination:= _
"'[2007 OPA Auditor Summary_MTY.xls]Pivot'!R4C1",
TableName:="PivotTable1", _
DefaultVersion:=xlPivotTableVersion10

ActiveSheet.PivotTables("PivotTable1").PivotCache.RefreshOnFileOpen = True
ActiveSheet.PivotTables("PivotTable1").AddFields RowFields:=Array( _
"Process Area", "Review Area"), PageFields:=Array("Branch",
"Product")
With
ActiveSheet.PivotTables("PivotTable1").PivotFields("Compliance %")
.Orientation = xlDataField
.Caption = "Average of Compliance %"
.Function = xlAverage
.NumberFormat = "0.00%"
End With

ActiveSheet.PivotTables("PivotTable1").PivotSelect "",
xlDataAndLabel, True
ActiveSheet.PivotTables("PivotTable1").Format xlTable9

ActiveSheet.PivotTables("PivotTable1").PivotFields("Process
Area").AutoSort _
xlDescending, "Average of Compliance %"


With ActiveSheet.PivotTables("PivotTable1").PivotFields("Review Area")
.Orientation = xlColumnField
.Position = 1
End With

With ActiveSheet.PivotTables("PivotTable1").PivotFields("Process
Area")
.Orientation = xlRowField
.Position = 1
End With

ActiveWindow.ScrollColumn = 3
ActiveWindow.ScrollColumn = 5
ActiveWindow.ScrollColumn = 6
ActiveWindow.ScrollColumn = 7
ActiveWindow.ScrollColumn = 9
ActiveWindow.ScrollColumn = 10
ActiveWindow.ScrollColumn = 11
ActiveWindow.ScrollColumn = 12
ActiveWindow.ScrollColumn = 14
ActiveWindow.ScrollColumn = 15
ActiveWindow.ScrollColumn = 16
ActiveWindow.ScrollColumn = 17
ActiveWindow.ScrollColumn = 16
ActiveWindow.ScrollColumn = 15
ActiveWindow.ScrollColumn = 14
ActiveWindow.ScrollColumn = 12
ActiveWindow.ScrollColumn = 11
ActiveWindow.ScrollColumn = 10
ActiveWindow.ScrollColumn = 8
ActiveWindow.ScrollColumn = 7
ActiveWindow.ScrollColumn = 5
ActiveWindow.ScrollColumn = 4
ActiveWindow.ScrollColumn = 2
ActiveWindow.ScrollColumn = 1
Selection.FormatConditions.Delete
Selection.FormatConditions.Add Type:=xlCellValue,
Operator:=xlBetween, _
Formula1:="0.1", Formula2:="0.6"
Selection.FormatConditions(1).Interior.ColorIndex = 3
Selection.FormatConditions.Add Type:=xlCellValue,
Operator:=xlBetween, _
Formula1:="0.6", Formula2:="0.8"
Selection.FormatConditions(2).Interior.ColorIndex = 46
Selection.FormatConditions.Add Type:=xlCellValue,
Operator:=xlBetween, _
Formula1:="0.8", Formula2:="1"
Selection.FormatConditions(3).Interior.ColorIndex = 50
Sheets("Pivot").Select
Range("B6").Select
Selection.FormatConditions.Delete
Selection.FormatConditions.Add Type:=xlCellValue,
Operator:=xlBetween, _
Formula1:="0.1", Formula2:="0.6"
Selection.FormatConditions(1).Interior.ColorIndex = 3
Selection.FormatConditions.Add Type:=xlCellValue,
Operator:=xlBetween, _
Formula1:="0.6", Formula2:="0.8"
Selection.FormatConditions(2).Interior.ColorIndex = 45
Selection.FormatConditions.Add Type:=xlCellValue,
Operator:=xlBetween, _
Formula1:="0.8", Formula2:="1"
Selection.FormatConditions(3).Interior.ColorIndex = 50
ActiveWorkbook.ShowPivotTableFieldList = False
Cells.Select
Selection.FormatConditions.Delete
Selection.FormatConditions.Add Type:=xlCellValue,
Operator:=xlBetween, _
Formula1:="0.1", Formula2:="0.6"
Selection.FormatConditions(1).Interior.ColorIndex = 3
Selection.FormatConditions.Add Type:=xlCellValue,
Operator:=xlBetween, _
Formula1:="0.6", Formula2:="0.8"
Selection.FormatConditions(2).Interior.ColorIndex = 46
Selection.FormatConditions.Add Type:=xlCellValue,
Operator:=xlBetween, _
Formula1:="0.8", Formula2:="1"
Selection.FormatConditions(3).Interior.ColorIndex = 10
Range("E20").Select
Columns("D:D").ColumnWidth = 9.86
Columns("C:C").ColumnWidth = 11.57
Columns("E:E").ColumnWidth = 11.29
Columns("F:F").ColumnWidth = 11.57
Columns("H:H").ColumnWidth = 12
Columns("B:B").ColumnWidth = 9.57
Columns("B:B").ColumnWidth = 12.14
Range("D1").Select
Columns("C:C").ColumnWidth = 11
Range("D5").Select
Charts.Add
ActiveChart.SetSourceData Source:=Sheets("Pivot").Range("D5")
ActiveChart.Location Where:=xlLocationAsNewSheet
With ActiveChart.Axes(xlCategory)
.HasMajorGridlines = False
.HasMinorGridlines = False
End With
With ActiveChart.Axes(xlValue)
.HasMajorGridlines = False
.HasMinorGridlines = False
End With
ActiveChart.HasLegend = False
ActiveChart.HasDataTable = True
ActiveChart.DataTable.ShowLegendKey = True
ActiveChart.PlotArea.Select
With Selection.Border
.ColorIndex = 16
.Weight = xlThin
.LineStyle = xlContinuous
End With
Selection.Interior.ColorIndex = xlNone
ActiveChart.ChartArea.Select
Sheets("Pivot").Select
Range("B15").Select
End Sub

Share: 

 

This Question has 12 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on PivotChart Updating using VBA Macros Or get search suggestion and latest updates.


Tagged: