Remove rows that contain full or partial email addresses

Serafin54

Board Regular
Joined
Apr 11, 2014
Messages
165
Office Version
  1. 2016
Platform
  1. Windows
Hello,

I have a report which contains email addresses in column F most are valid but some are not. I am needing to delete any rows containing an invalid email address. Below is a dummy file, same set up but data changed for privacy. Yellow highlighted cells are ones with issues.

PROD1 CASS_RESULTS.xlsx
ABCDEF
1AddressitemdepartmentcodeEE LAST NAMEEmployee Home Email
264 Central St.checkbook22954JX8939WILSONcyrus@hotmail.com
365 W. Military Dr.doll13910JF1074KRANTZdmouse@AGMAIL.COM
466 North Nicolls Ave.bottle7828JW8594MISALandrei@me.com
57047 Poor House Drivebananas8802GQ6511SANCHEZ MARTINEZjbarta@me.com
68652 Locust Ave.pencil91224JW5310GARNIER ROVIRAreport@hotmail.com
74 Selby St.apple25241D59732CASTANEDAjmorris@mac.com
853 Sulphur Springs Streetnail clippers24690KC1501ROSADOkarasik@GMAIL..COM
9518 Cobblestone Drivemoney18835GQ3054MOOREgumpish@msn.com
107761 Old York Streetsailboat16892M44288BATTCOCKnatepuri@yahoo.com
1198 Oakland Rd.sticky note24934S76416PARRILLA BRUNOkalpol@yahoo.ca
129689 Homestead Dr.buckle101012JZ8577KOONCEideguy@hotmail.com
1335B 53rd Streetchapter book630157DD9192Demeusycamenisch@mac.com
149468 Victoria Drivecouch640196KL6703CORRALESjigsaw@yahoo.com
153 Warren St.photo album18041T26488BUTTERFIELDmichiel@msn.com
168468 Vine Rd.needle20310GZ9574BEILENSONdprice@gmail.com
1718 Lookout Ave.wallet701064GH5648CHARPENTIERNOEMAIL@GMAIL.COM
187302 Stillwater Ave.clay pot24934GG1666SMITHNone
testfile



Currently, I open my report and also an excel file I created named "Invalid Emails" with two columns. Column A is the full address that may contain items such as "NOEMAIL@GMAIL.COM", "1234@567.com", or even "@gmail.com" and 36 entries . And column C that has only the extensions which may be "AGMAIL.COM", "GMAIL.CON", etc with 62 entries. Below is part of the list. Yellow Cells relate to the yellow cells on the report example from above.

PROD1 CASS_RESULTS.xlsx
ABC
1First LookupSecond Lookup
2N/A.com
3NAAGMAIL.COM
4NLaol.om
5Noneatt.netde
6@g.comGAMAIL.COM
7@gmail.comGAMIAL.COM
80@0.CMGAMIAL.COM
90@0.COMGAMIL.COM
101234@567.comGIMAIL.COM
11a@a.comGMAI.COM
12ABC@ABC.COMGMAIIL.COM
13ABC@NOEMAIL.COMGMAIL..COM
14ABC@xx.COMGMAIL.CO
15NA@NA.COMGMAIL.COJM
16NOEMAIL@GAMIL.COMG-MAIL.COM
17NOEMAIL@GMAIL.COMgmail.com.
18NOEMAIL@HOTMAIL.COMgmail.com.
19NOEMAIL@NOEMAIL.COMGMAIL.COMG
20NOEMAIL@SHORTYS.COMGMAIL.COMM
Sheet1


I begin by entering a vlookup in column G2 of my report using F2 of my report to reference column A of the Invalid Emails file and filling down. I then filter F to exclude "#N/A" and delete all rows that appear.

I unfilter and copy/paste all remaining emails in F into G, find "*@" and replace with "" to get the extension of the emails and enter another vlookup into H2 on my report to column C of the Invalid Emails file and filling down. I then filter K to exclude "#N/A" and delete all rows that appear. Unfilter and delete columns G and H.

This process isn't back breaking by any means but am curious if there is a way to accomplish this through VBA or not.
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Try this code :

VBA Code:
Sub DeleteYellow()
    Dim lr As Long, i As Long
    Application.ScreenUpdating = False
    
    lr = Range("F" & Rows.Count).End(xlUp).Row
    
    For i = lr To 2 Step -1
        
        If Cells(i, "F").DisplayFormat.Interior.ColorIndex = 6 Then Rows(i).Delete
 
    Next
    
    Application.ScreenUpdating = True

End Sub
 
Upvote 0
sorry. I was a bit unclear. The yellow was just to show which cells would be problems. That isn't actually part of the report.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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