Forum Discussion
Samuel Parry
Jul 19, 2018Copper Contributor
Delete rows in an IF test
I need to delete a row if the value in column B for the current row is equal to the value in the next row. Can I do this in an IF test?If not, then how?
Lorenzo Kim
Jul 19, 2018Bronze Contributor
Mr. Parry
I don't know if the IF function can do what you want.
Below is a SUB (Mr. Man Fai Chan helped me with this - my way of pay it forward) for you to try.
test this in another sheet - just in case. (always make a backup copy of your work).
HTH
column B should be sorted first
Sub DeleteRowforSameB()
Dim i As Long
For i = Cells(Rows.Count, "B").End(xlUp).Row To 2 Step -1
mdata = Cells(i - 1, "B")
If Cells(i, "B") = mdata Then Rows(i).Delete
Next i
End Sub