Delete Duplicate row based off of email then gender

ineedadedt

Board Regular
Joined
Jan 7, 2004
Messages
163
Hi all, I searched the forum and found 2 different macros that may work with some tweaking, but is beyond my capabilities.
I need the following scenario to happen:
12000 email list has all info from first name, last name, address, gender, age, email and more. The only columns I am concerend about are
V - email address
I - Gender
H - age
B- first name

I need the macro to look at the emails, see if there is a duplicate, if so look at the gender to compare and if it's a male delete the duplicate. If it's two females delete the younger one. If it's two males delete the younger one.

I'm not sure it's worth posting the macro codes I found as they don't do exactly that. I can if it makes sense to.

Any help is greatly appreciated!

Eric
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Try this

Code:
Sub Delete_Rows()
  Dim lr As Long, c As Range, r As Range, n As Long, m As Variant
  Application.ScreenUpdating = False
  lr = Range("B" & Rows.Count).End(xlUp).Row
  Set r = Range("A" & lr + 1)
  For Each c In Range("V2:V" & lr)
    n = WorksheetFunction.CountIfs(Range("V2:V" & lr), c, _
                                   Range("I2:I" & lr), Range("I" & c.Row))
    If n > 1 Then
      m = Evaluate("=MAX(IF((V2:V" & lr & "=V" & c.Row & ")*" & _
                           "(I2:I" & lr & "=I" & c.Row & "),H2:H" & lr & "))")
      If m <> Range("H" & c.Row) Then
        Set r = Union(r, Range("A" & c.Row))
      End If
    End If
  Next
  r.EntireRow.Delete
End Sub
 
Upvote 0
Thanks Dante! When I run Excel to remove all duplicates it says there should be 10,221 values remaining. When I run this code it leaves 11,742. I can see the difference just scrolling through. If I run it again, it doesn't do anything. Thoughts?
 
Upvote 0
Check that your sheet actually has these columns.

V - email address
I - Gender
H - age (Numerical values)


Perform a test with a sample.

Paste a sample of your data here.
 
Upvote 0

Forum statistics

Threads
1,214,560
Messages
6,120,217
Members
448,951
Latest member
jennlynn

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