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
 

Some videos you may like

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
12,208
Office Version
2007
Platform
Windows
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
 

ineedadedt

Board Regular
Joined
Jan 7, 2004
Messages
163
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?
 

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
12,208
Office Version
2007
Platform
Windows
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,102,694
Messages
5,488,314
Members
407,634
Latest member
ps01

This Week's Hot Topics

  • Timer in VBA - Stop, Start, Pause and Reset
    [CODE=vba][/CODE] Option Explicit Dim CmdStop As Boolean Dim Paused As Boolean Dim Start Dim TimerValue As Date Dim pausedTime As Date Sub...
  • how to updates multiple rows in muliselect listbox
    Hello everyone. I need help with below code. code is only chaning 1st row in mulitiselect list box. i know issue with code...
  • Delete Row from Table
    I am trying to delete a row from a table using VBA using a named range to find what I need to delete. My Range is finding the right cell. In the...
  • Assigning to a variable
    I have a for each block where I want to assign the value in column 5 of the found row to the variable Serv. [CODE=vba] For Each ws In...
  • Way to verify information
    Hi All, I don't know what to call this formula, and therefore can't search. I have a spreadsheet with information I want to reference...
  • Active Cell Address – Inactive Sheet
    How to use VBA to get the cell address of the active cell in an inactive worksheet and then place that cell address in a location on the current...
Top