I tried to reply earlier, but it didn't make it in...
This should be close, I haven't tested all scenarios:
Code:Sub delRowsGT11() Dim i As Long Dim lastRow As Long Dim currKey As String Dim endRow As Long Dim startRow As Long Dim deleteRow As Long lastRow = Range("h" & Rows.Count).End(xlUp).Row currKey = Range("h" & lastRow).Value endRow = lastRow For i = lastRow - 1 To 12 Step -1 If i = 12 And currKey = Range("h" & endRow).Value Then Range("a13", "a" & endRow).EntireRow.Delete Exit Sub End If If Range("h" & i).Value <> currKey Then 'found first row above with different value startRow = i + 1 If endRow - startRow > 11 Then delrow = startRow + 11 Range("a" & delrow, "a" & endRow).EntireRow.Delete End If currKey = Range("h" & i).Value endRow = i End If Next i End Sub




Reply With Quote