I would use a macro for this.
first sort your data by column A and then column B
Then put this formula into E2 and Fill Down
Formula:
=IF(A2=A1,"",1)
Then put this formula into F2 and Fill Down
Formula:
=IF(E2=1,1,IF(B2=B1,F1,F1+1))
Then select Select Column F and find the first 1. if Column E in the previous Row does not contain 49 then delete the previous selection.
Sorry I got pulled away. This code seems to work. Please test carefully, as I have lost focus.
Sub Macro1()
LR = Cells(Rows.Count, 1).End(xlUp).Row
Start = 2
Range("E3:E" & LR).FormulaR1C1 = "=IF(RC[-4]=R[-1]C[-4],"""",1)"
Range("F3:F" & LR).FormulaR1C1 = "=IF(RC[-1]=1,1,IF(RC[-4]=R[-1]C[-4],R[-1]C,R[-1]C+1))"
Range("E2:F" & LR).Value = Range("E2:F" & LR).Value
Cells(LR + 1, 5).Value = 1
Loop1:
Z = Columns(5).Find(1, LookIn:=xlValues, Lookat:=xlWhole).Row
If Cells(Z - 1, 6).Value <> 49 Then
Rows(Start & ":" & Z - 1).EntireRow.Delete
LR = Cells(Rows.Count, 1).End(xlUp).Row
End If
Cells(Z, 5).Clear
Start = Z
If Start < LR Then GoTo Loop1
End Sub
Bookmarks