How to remove all emails with certain domains from the list in one go?

LizzieLiz

New Member
Joined
Oct 13, 2022
Messages
2
Office Version
  1. 2016
Platform
  1. Windows
How do I remove all emails with certain domains (e.g. gmail, hotmail, yahoo) in one go?
I've got a list where a couple of emails are from the same company. I want to remove all emails with particular domains (around 100+ of them).
Is there a way to do that in one go instead of multiplying same effort x100, eg. Find&Replace x 100?

I tried to be as clear as possible :)

Thank you!
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Let's assume your list of domains to clear are in A1:A100, and your list of e-mail addresses is in column F, e.g. F1:F5000. This code will put the bad domains into an array and then check each e-mail address in the list to see if it finds a match. If so, it clears that cell value. You can have it do other things like delete the entire row, etc. (In that case, your list of domains shouldn't overlap rows, preferably put it on another sheet.)
VBA Code:
Sub LizzieLiz()
Dim myList As Variant, i As Long, lastrow As Long, j As Long
lastrow = Range("F" & Rows.Count).End(xlUp).Row
myList = Sheets("Sheet1").Range("A1:A100").Value

For i = 1 To lastrow
    For j = LBound(myList) To UBound(myList)
        If Cells(i, 6).Value Like "*" & myList(j, 1) & "*" Then Cells(i, 6).ClearContents
    Next j
Next i
End Sub
 
Upvote 0
Let's assume your list of domains to clear are in A1:A100, and your list of e-mail addresses is in column F, e.g. F1:F5000. This code will put the bad domains into an array and then check each e-mail address in the list to see if it finds a match. If so, it clears that cell value. You can have it do other things like delete the entire row, etc. (In that case, your list of domains shouldn't overlap rows, preferably put it on another sheet.)
VBA Code:
Sub LizzieLiz()
Dim myList As Variant, i As Long, lastrow As Long, j As Long
lastrow = Range("F" & Rows.Count).End(xlUp).Row
myList = Sheets("Sheet1").Range("A1:A100").Value

For i = 1 To lastrow
    For j = LBound(myList) To UBound(myList)
        If Cells(i, 6).Value Like "*" & myList(j, 1) & "*" Then Cells(i, 6).ClearContents
    Next j
Next i
End Sub
Im getting runtime error 1004 in the third line.
 
Upvote 0
Try specifying the sheet name, e.g.
VBA Code:
lastrow = Sheets("Sheet1").Range("F" & Rows.Count).End(xlUp).Row
Also, in the "If Cells(i, 6)..." line, add the sheet references:
VBA Code:
If Sheets("Sheet1").Cells(i, 6).Value Like "*" & myList(j, 1) & "*" Then Sheets("Sheet1").Cells(i, 6).ClearContents
 
Upvote 0

Forum statistics

Threads
1,214,976
Messages
6,122,541
Members
449,089
Latest member
davidcom

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