try this on a copy of your workbook to see if it does what you want:
VBA Code:
Sub TEST()
Dim badt() As Variant
Dim ISNP As Variant
Dim Seq As Variant
lastrow = Cells(Rows.Count, "A").End(xlUp).Row
lastcol = 46 ' column AT
inarr = Range(Cells(1, 1), Cells(lastrow, lastcol))
ReDim badt(1 To lastrow, 1 To lastcol)
ReDim ISNP(1 To lastrow, 1 To lastcol)
ReDim Seq(1 To lastrow, 1 To lastcol)
bcnt = 2
icnt = 2
scnt = 2
'copy headers
For j = 1 To lastcol
badt(1, j) = inarr(1, j)
ISNP(1, j) = inarr(1, j)
Seq(1, j) = inarr(1, j)
Next j
For i = 1 To lastrow
If inarr(i, 9) = "14000-00" Then
For j = 1 To lastcol
badt(bcnt, j) = inarr(i, j)
Next j
bcnt = bcnt + 1
End If
If inarr(i, 9) = "42875-00" Then
For j = 1 To lastcol
ISNP(icnt, j) = inarr(i, j)
Next j
icnt = icnt + 1
End If
If inarr(i, 19) = "X" Or inarr(i, 19) = "XR" Then
For j = 1 To lastcol
Seq(scnt, j) = inarr(i, j)
Next j
scnt = scnt + 1
End If
Next i
Worksheets.Add
ActiveSheet.Name = "Bad Debt Data"
Range(Cells(1, 1), Cells(bcnt, lastcol)) = badt
Worksheets.Add
ActiveSheet.Name = "ISNP Data"
Range(Cells(1, 1), Cells(icnt, lastcol)) = ISNP
Worksheets.Add
ActiveSheet.Name = "Sequestered Data"
Range(Cells(1, 1), Cells(scnt, lastcol)) = Seq
End Sub
so it worked perfectly on my original file, but then when I deleted all of the tabs (except for the original data tab) and tried running it again
that worked perfectly!!! thank you so much!
I have another question. I wanted to take those data tabs and create pivot tables. I thought I could just record a macro doing everything I wanted but there's an error. do you know why this is? I bolded out the highlighted area when I clicked debug
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