aha! managed to fix it, I simply changed:
For p = ws.Range("P65536").End(xlUp).Row To 1 Step -1
to:
For p = ws.Range("P65536").End(xlUp).Row To 2 Step -1
Have tested that it still works correctly, by placing a row in row to that
is not equal to "cw" and it was correctly deleted.
Thanks to any and everyone who took a look at this for me
"PVANS" wrote:
> Good morning
>
> I have the following code to delete all rows that do not contain the
> following two variables, in column P, "cw" and "ea".
>
> Set ws = ActiveSheet
>
> For p = ws.Range("P65536").End(xlUp).Row To 1 Step -1
> If ws.Cells(p, 16) <> "cw" Then
> If ws.Cells(p, 16) <> "ea" Then
> ws.Rows(p).Delete
> End If
> End If
> Next
>
> It works very well apart from the fact that it deletes the Header row.
> Please can someone assist me in modifying this code so it does not delete Row
> 1 (the header row).
>
> Thanks for any help in advance, I really appreciate it.
>
|