Hi,
This is a strange one, well to my mind anyway, I have written a macro which is supposed to look for an email address and delete the entire row when found.
I'm running this on a list of about 5000 logged emails, on the first run of this macro I get x = 1400 or so but I still see some emaillog addresses in there, so I run it again, now about 400, then 40 then 1 so finally after running the macro 4 times it has finally deleted all of them.
Does anybody know why this is happening?
I can only think that if perhaps it found one in cell H10, deleted the row and now H11 has become H10 but it has already moved to check H11 not H10 which may contain the emaillog address.
So I guess my question is how can I run this from bottom to top?
Thanks for help, any advice gratefully received.
This is a strange one, well to my mind anyway, I have written a macro which is supposed to look for an email address and delete the entire row when found.
Code:
Sub delete_emailog()
Dim cell As Range
Dim x As Integer
x = 1
For Each cell In Range("H:H")
If cell.Value = "emaillog@mycompany.co.uk" Then
cell.EntireRow.Delete
x = x + 1
Else: End If
Next
MsgBox x
End Sub
I'm running this on a list of about 5000 logged emails, on the first run of this macro I get x = 1400 or so but I still see some emaillog addresses in there, so I run it again, now about 400, then 40 then 1 so finally after running the macro 4 times it has finally deleted all of them.
Does anybody know why this is happening?
I can only think that if perhaps it found one in cell H10, deleted the row and now H11 has become H10 but it has already moved to check H11 not H10 which may contain the emaillog address.
So I guess my question is how can I run this from bottom to top?
Thanks for help, any advice gratefully received.