This is more out of academic interest than any need for a practical solution - I recently wrote a bit of code that does a bunch of filters/sorts/removal of duplicates in a huge file, but as I was stepping through the code it seems like this loop is the main bottleneck and I want to understand why this is so bad, and why the in built functions like filter and sort seem to work so much more quickly doing more difficult operation.
For i = 2 To nRows
If (Cells(i, 1) <> Cells(i - 1, 1) Or Cells(i, 2) <> Cells(i - 1, 2)) _
And (Cells(i, 1) <> Cells(i + 1, 1) Or Cells(i, 2) <> Cells(i + 1, 2)) Then
Rows(i).EntireRow.Delete
i = i - 1
nRows = nRows - 1
End If
Next i