I have recorded a macro creating a pivot and doing the necessary pivot filters. I would like to be able to run this macro in different workbooks since I will be doing this a several excel files daily.
As you can see in the code below the macro will only work on a specific worksheet.
Thanks
Sub accountlistingpivot()
'
' accountlistingpivot Macro
'
'
Windows("2015 09 17 - FE BPs and PTPs.xls").Activate
Range("A1:Y11812").Select
Sheets.Add
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"F03_F04_F05!R1C1:R11812C25", Version:=xlPivotTableVersion10). _
CreatePivotTable TableDestination:="Sheet1!R3C1", TableName:="PivotTable12" _
, DefaultVersion:=xlPivotTableVersion10
Sheets("Sheet1").Select
Cells(3, 1).Select
With ActiveSheet.PivotTables("PivotTable12").PivotFields("State_Code")
.Orientation = xlColumnField
.Position = 1
End With
With ActiveSheet.PivotTables("PivotTable12").PivotFields("Cycle")
.Orientation = xlRowField
.Position = 1
End With
ActiveSheet.PivotTables("PivotTable12").AddDataField ActiveSheet.PivotTables( _
"PivotTable12").PivotFields("AccountNumber"), "Count of AccountNumber", xlCount
ActiveSheet.PivotTables("PivotTable12").AddDataField ActiveSheet.PivotTables( _
"PivotTable12").PivotFields("Billed_OB"), "Sum of Billed_OB", xlSum
With ActiveSheet.PivotTables("PivotTable12").DataPivotField
.Orientation = xlColumnField
.Position = 2
End With
With ActiveSheet.PivotTables("PivotTable12").PivotFields("Sum of Billed_OB")
.NumberFormat = "#,##0"
End With
Sheets("Sheet1").Select
Sheets("Sheet1").Name = "Summary"
End Sub
Bookmarks