so I posted this on my other chain but I think it may go unnoticed since the original question was solved. I had a data tab that I wanted a macro to breakout into three different tabs. I then thought I could just record a macro while setting up the pivot tables, but there's an error when running the macro and I am not sure how to fix it. any help would be appreciated!
Basically I have a sequestered data tab that I want to make a sequestered pivot table tab, an ISNP data tab that I want to create an ISNP pivot table tab and a bad debt data tab that I want to create a bad debt pivot table tab. I placed the pivot table macro button on the sequestered key tab, so I don't know if that matters. below is the recorded macro and the error is in bold
Basically I have a sequestered data tab that I want to make a sequestered pivot table tab, an ISNP data tab that I want to create an ISNP pivot table tab and a bad debt data tab that I want to create a bad debt pivot table tab. I placed the pivot table macro button on the sequestered key tab, so I don't know if that matters. below is the recorded macro and the error is in bold
Rich (BB code):
Sub Pivot_tables()
'
' Pivot_tables Macro
'
'
Range("A1").Select
Sheets(Array("Sequestered Data", "ISNP Data", "Bad Debt Data")).Select
Sheets("Sequestered Data").Activate
Cells.Select
Cells.EntireColumn.AutoFit
Range("A1:AT1").Select
Selection.Font.Bold = True
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorDark1
.TintAndShade = -0.249977111117893
.PatternTintAndShade = 0
End With
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Cells.Select
Cells.EntireColumn.AutoFit
Range("B1").Select
Sheets("Sequestered Data").Select
Columns("K:K").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("K1").Select
ActiveCell.FormulaR1C1 = "Sequestered category"
Range("K2").Select
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-1],'sequestered key'!C[-10]:C[-9],2,0)"
Range("K2").Select
Selection.AutoFill Destination:=Range("K2:K19969")
Range("K2:K19969").Select
Range("B1").Select
Sheets.Add
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"Sequestered Data!R1C1:R19969C47", Version:=xlPivotTableVersion15). _
CreatePivotTable TableDestination:="Sheet6!R3C1", TableName:="PivotTable18" _
, DefaultVersion:=xlPivotTableVersion15
Sheets("Sheet6").Select
Cells(3, 1).Select
With ActiveSheet.PivotTables("PivotTable18").PivotFields("Facility Name")
.Orientation = xlRowField
.Position = 1
End With
With ActiveSheet.PivotTables("PivotTable18").PivotFields("Sequestered category" _
)
.Orientation = xlRowField
.Position = 2
End With
ActiveSheet.PivotTables("PivotTable18").AddDataField ActiveSheet.PivotTables( _
"PivotTable18").PivotFields("Amount"), "Sum of Amount", xlSum
Columns("B:B").Select
Selection.Style = "Comma"
Sheets("Sheet6").Select
Sheets("Sheet6").Name = "sequestered pivot table"
Range("D31").Select
Sheets("ISNP Data").Select
Sheets.Add
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"ISNP Data!R1C1:R33C46", Version:=xlPivotTableVersion15).CreatePivotTable _
TableDestination:="Sheet7!R3C1", TableName:="PivotTable19", DefaultVersion _
:=xlPivotTableVersion15
Sheets("Sheet7").Select
Cells(3, 1).Select
With ActiveSheet.PivotTables("PivotTable19").PivotFields("Facility Name")
.Orientation = xlRowField
.Position = 1
End With
With ActiveSheet.PivotTables("PivotTable19").PivotFields("JE Name")
.Orientation = xlRowField
.Position = 2
End With
ActiveSheet.PivotTables("PivotTable19").AddDataField ActiveSheet.PivotTables( _
"PivotTable19").PivotFields("Units"), "Sum of Units", xlSum
ActiveSheet.PivotTables("PivotTable19").AddDataField ActiveSheet.PivotTables( _
"PivotTable19").PivotFields("Amount"), "Sum of Amount", xlSum
Columns("C:C").Select
Selection.Style = "Comma"
Range("C17").Select
Sheets("Sheet7").Select
Sheets("Sheet7").Name = "ISNP pivot table"
Sheets("Bad Debt Data").Select
Sheets.Add
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"Bad Debt Data!R1C1:R232C46", Version:=xlPivotTableVersion15). _
CreatePivotTable TableDestination:="Sheet8!R3C1", TableName:="PivotTable20" _
, DefaultVersion:=xlPivotTableVersion15
Sheets("Sheet8").Select
Cells(3, 1).Select
With ActiveSheet.PivotTables("PivotTable20").PivotFields("Facility Name")
.Orientation = xlRowField
.Position = 1
End With
With ActiveSheet.PivotTables("PivotTable20").PivotFields("Payer Type")
.Orientation = xlRowField
.Position = 2
End With
ActiveSheet.PivotTables("PivotTable20").AddDataField ActiveSheet.PivotTables( _
"PivotTable20").PivotFields("Amount"), "Sum of Amount", xlSum
Columns("B:B").Select
Selection.Style = "Comma"
Sheets("Sheet8").Select
Sheets("Sheet8").Name = "bad debt pivot table"
Range("C4").Select
End Sub
Last edited by a moderator: