Folks -
I am working on a project where I have a bunch of stacked data and I am separating it by looking for certain criteria. The template that I am using only has sheet 1 in it containing the data. I have 3 macros to create sheet2, separate the data and then pull the data that I want back to sheet2.
Create sheet2 is your basic create sheet macro (recorded macro)
Sub Create_Sheet()
Sheets.Add After:=Sheets(Sheets.Count)
Sheet1.Select
End Sub
Now the separate data and put headers on sheet2. I am getting the Object required error on the line Sheet2.select
Sub Get_Name()
Application.ScreenUpdating = False
Sheet2.Select
Dim InputRange(30000) As Variant
Dim PatRange(30000) As Variant
Dim RowNumber(30000) As Variant
Dim CheckInput(30000) As Boolean
Dim CheckInput2(30000) As Boolean
Dim CheckInput3(30000) As Boolean
Dim CheckInput4(30000) As Boolean
Dim CheckInput5(30000) As Boolean
Dim CheckInput6(30000) As Boolean
Dim Top As Double
Dim Bot As Double
Dim aRange As Range
Sheet2.Range("A1") = "Name"
Sheet2.Range("B1") = "Beg Row #"
Sheet2.Range("C1") = "End Row #"
Sheet2.Range("D1") = "Patient #"
Sheet2.Range("E1") = "Patient Billed Date"
Sheet2.Range("F1") = "Primary Billed Date"
Sheet2.Range("G1") = "Secondary Billed Date"
Sheet2.Range("H1") = "Balance"
For i = 1 To 30000
InputRange(i) = Sheet1.Range("Input")(i, 1).Value
RowNumber(i) = Sheet1.Range("Input")(i, 1).Row
If Right(InputRange(i), 1) = ")" And Left(InputRange(i), 7) <> "Primary" Then
CheckInput(i) = True
Else
CheckInput(i) = False
End If
Next i
k = 1
For i = 1 To 30000
If CheckInput(i) = True Then
Sheet2.Range("A1").Offset(k, 0) = InputRange(i)
Sheet2.Range("B1").Offset(k, 0) = RowNumber(i)
k = k + 1
End If
Next i
For j = 1 To 30000
RowNumber(j) = Sheet1.Range("Input")(j, 1).Row
If InputRange(j) = "Patient Unapplied Prepayment Total" Then
CheckInput2(j) = True
Else
CheckInput2(j) = False
End If
Next j
m = 1
For j = 1 To 30000
If CheckInput2(j) = True Then
Sheet2.Range("C1").Offset(m, 0) = RowNumber(j)
Sheet2.Range("D1").Offset(m, 0) = m
m = m + 1
End If
Next j
p = 1
For i = 1 To 30000
If CheckInput(i) = True Then
Top = Sheet2.Range("B" & p + 1).Value
Bot = Sheet2.Range("C" & p + 1).Value
Sheet1.Select
Rows(Top & ":" & Bot).Select
DataCarry = Selection.Copy
Sheets.Add After:=Sheets(Sheets.Count)
ActiveSheet.Name = Left(InputRange(i), 30)
Sheets(Left(InputRange(i), 30)).Select
Range("A1").Select
ActiveSheet.Paste
Range("A1").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Name = "Patient" & p
yy = WorksheetFunction.CountA(Range("Patient" & p))
Range("Patient" & p).Resize(yy, 8).Select
Selection.Name = "PatientL" & p
p = p + 1
End If
Next i
Sheet2.Select
Columns("A:H").Select
Columns("A:H").EntireColumn.AutoFit
Columns("B:D").Select
Selection.EntireColumn.Hidden = True
Sheet1.Select
Range("A1").Select
Application.CutCopyMode = False
Application.ScreenUpdating = True
End Sub
I don't understand why I am getting this error and any help would be greatly appreciated.
Thank you
David
I am working on a project where I have a bunch of stacked data and I am separating it by looking for certain criteria. The template that I am using only has sheet 1 in it containing the data. I have 3 macros to create sheet2, separate the data and then pull the data that I want back to sheet2.
Create sheet2 is your basic create sheet macro (recorded macro)
Sub Create_Sheet()
Sheets.Add After:=Sheets(Sheets.Count)
Sheet1.Select
End Sub
Now the separate data and put headers on sheet2. I am getting the Object required error on the line Sheet2.select
Sub Get_Name()
Application.ScreenUpdating = False
Sheet2.Select
Dim InputRange(30000) As Variant
Dim PatRange(30000) As Variant
Dim RowNumber(30000) As Variant
Dim CheckInput(30000) As Boolean
Dim CheckInput2(30000) As Boolean
Dim CheckInput3(30000) As Boolean
Dim CheckInput4(30000) As Boolean
Dim CheckInput5(30000) As Boolean
Dim CheckInput6(30000) As Boolean
Dim Top As Double
Dim Bot As Double
Dim aRange As Range
Sheet2.Range("A1") = "Name"
Sheet2.Range("B1") = "Beg Row #"
Sheet2.Range("C1") = "End Row #"
Sheet2.Range("D1") = "Patient #"
Sheet2.Range("E1") = "Patient Billed Date"
Sheet2.Range("F1") = "Primary Billed Date"
Sheet2.Range("G1") = "Secondary Billed Date"
Sheet2.Range("H1") = "Balance"
For i = 1 To 30000
InputRange(i) = Sheet1.Range("Input")(i, 1).Value
RowNumber(i) = Sheet1.Range("Input")(i, 1).Row
If Right(InputRange(i), 1) = ")" And Left(InputRange(i), 7) <> "Primary" Then
CheckInput(i) = True
Else
CheckInput(i) = False
End If
Next i
k = 1
For i = 1 To 30000
If CheckInput(i) = True Then
Sheet2.Range("A1").Offset(k, 0) = InputRange(i)
Sheet2.Range("B1").Offset(k, 0) = RowNumber(i)
k = k + 1
End If
Next i
For j = 1 To 30000
RowNumber(j) = Sheet1.Range("Input")(j, 1).Row
If InputRange(j) = "Patient Unapplied Prepayment Total" Then
CheckInput2(j) = True
Else
CheckInput2(j) = False
End If
Next j
m = 1
For j = 1 To 30000
If CheckInput2(j) = True Then
Sheet2.Range("C1").Offset(m, 0) = RowNumber(j)
Sheet2.Range("D1").Offset(m, 0) = m
m = m + 1
End If
Next j
p = 1
For i = 1 To 30000
If CheckInput(i) = True Then
Top = Sheet2.Range("B" & p + 1).Value
Bot = Sheet2.Range("C" & p + 1).Value
Sheet1.Select
Rows(Top & ":" & Bot).Select
DataCarry = Selection.Copy
Sheets.Add After:=Sheets(Sheets.Count)
ActiveSheet.Name = Left(InputRange(i), 30)
Sheets(Left(InputRange(i), 30)).Select
Range("A1").Select
ActiveSheet.Paste
Range("A1").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Name = "Patient" & p
yy = WorksheetFunction.CountA(Range("Patient" & p))
Range("Patient" & p).Resize(yy, 8).Select
Selection.Name = "PatientL" & p
p = p + 1
End If
Next i
Sheet2.Select
Columns("A:H").Select
Columns("A:H").EntireColumn.AutoFit
Columns("B:D").Select
Selection.EntireColumn.Hidden = True
Sheet1.Select
Range("A1").Select
Application.CutCopyMode = False
Application.ScreenUpdating = True
End Sub
I don't understand why I am getting this error and any help would be greatly appreciated.
Thank you
David