detriez
Board Regular
- Joined
- Sep 13, 2011
- Messages
- 193
- Office Version
- 365
- Platform
- Windows
I've got a named range (nPersonalEmailDomain) with around 3700 email domains... gmail.com, yahoo.com etc
I need to delete the entire row of another sheet where an email in Column C is on the nPersonalEmailDomain list. This sheet can have several hundred to several thousand rows
So, If an email in Column C = bob@gmail.com, delete the entire row
This hangs for about 8 minutes before it finally completes processing 300 rows
Is there a more efficient way to do this?
Rather than looking in each email for the domain on the named range, maybe I should put the email domain from the email to another column and then do an exact match ?
What might the below code look like to delete the entire row if Column BH equals nPersonalEmailDomain?
I need to delete the entire row of another sheet where an email in Column C is on the nPersonalEmailDomain list. This sheet can have several hundred to several thousand rows
So, If an email in Column C = bob@gmail.com, delete the entire row
This hangs for about 8 minutes before it finally completes processing 300 rows
Is there a more efficient way to do this?
Rather than looking in each email for the domain on the named range, maybe I should put the email domain from the email to another column and then do an exact match ?
What might the below code look like to delete the entire row if Column BH equals nPersonalEmailDomain?
VBA Code:
Sub PersonalEmails(Control As IRibbonControl)
Dim nRng As Range, rng As Range, c As Range, n As Range
Set nRng = Range("nPersonalEmailDomain") 'my named range containing the list of personal email domains
Set rng = Range("C2", ActiveSheet.Cells(Rows.Count, "c").End(xlUp)) 'get col C parameters
For Each c In rng 'Look at each item in col C
For Each n In nRng
If InStr(c.Text, n.Text) > 0 Then
c.EntireRow.Delete 'Delete rows with match to named range
Exit For
End If
Next
Next
End Sub