I am banging my head against the wall trying to figure out why my copy paste is not lining up. I thought I had the index figured out correctly, but I am still missing something. It is correct for the first case of data but then is off by one one for the second and two for the third. It was initially two and four rows respectively, but I figured out that I need to update my counter regardless of which statement is true.
My code as is follows:
Dim FirstItem As Integer
Dim SecondItem As Integer
Dim Offsetcount As Integer
Dim Rowoffset As Integer
Dim true_offset As Integer
Dim myNum As Integer
Sheets("Sheet2").Activate
ActiveSheet.Range("C2").Select
FirstItem = ActiveCell.Value
SecondItem = ActiveCell.Offset(1, 0).Value
Offsetcount = 1
Rowoffset = 0
true_offset = 1
myNum = (Range("C" & Rows.Count).End(xlUp).Row)
'MsgBox myNum
Do While myNum > 1
true_offset = true_offset + 1
If FirstItem = SecondItem Then
Offsetcount = Offsetcount + 1
Rowoffset = Rowoffset + 1
SecondItem = ActiveCell.Offset(Offsetcount, 0).Value
Else
Set myactivecell = ActiveCell
Set myActiveWorksheet = ActiveSheet 'Do I need to declare this and the line below?
Set myActiveWorkbook = ActiveWorkbook
ActiveSheet.Range(ActiveSheet.Cells(true_offset - Rowoffset, 1), ActiveSheet.Cells(true_offset + 1, 1)).EntireRow.Select
Selection.Copy
Set new_workbook = Workbooks.Add
ActiveSheet.Paste
myActiveWorkbook.Activate
myActiveWorksheet.Activate
myactivecell.Activate
ActiveCell.Offset(Offsetcount + 1, 0).Select
If ActiveCell.Value = "" Then
myNum = 0
End If
FirstItem = ActiveCell.Value
SecondItem = ActiveCell.Offset(1, 0).Value
Offsetcount = 1
myNum = myNum - 1
Rowoffset = 0
End If
Loop
Here's a screen cap of some sample data: