Delete entire.row if value found not working.

JonathanA

Board Regular
Joined
Jan 2, 2008
Messages
62
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.
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.
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.

Forum statistics

Threads
1,224,526
Messages
6,179,322
Members
452,906
Latest member
Belthazar

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top