New Excel Forum

This forum has been moved to TeachExcel.com

Ask all future questions in the New Excel Forum.

ExcelKey

Need macro to find duplicates and delete based on criteria

Macros, VBA, Excel Automation, etc.

Need macro to find duplicates and delete based on criteria

Postby dmaner » Mon Jan 09, 2012 12:46 pm

Hello,

I have looked but cannot find a macro that will find duplicates in column A, then of these duplicates delete the row(s) leaving one row where column B is the smallest integer.

Sample data:

Column A Column B
abc@gmail.com 1
def@gmail.com 18
dflkj@gmail.com 12
abc@gmail.com 9
abc@gmail.com 5

The macro would need to delete rows 4 and 5.

Thanks in advance!
  • 0

dmaner
Rookie
 
Posts: 7
Joined: Jan 9, 2012
Reputation: 0

Re: Need macro to find duplicates and delete based on criter

Postby lucky027 » Mon Jan 09, 2012 1:15 pm

Could try this code ?

Code: Select all
Sub dmaner_code()
Dim lastrow
lastrow = Range("A" & Rows.Count).End(xlUp).Row
For I = 1 To lastrow
If WorksheetFunction.CountIf(Range("A1:A" & I), Range("A" & I)) > 1 Then
Rows(I).Delete
I = I - 1
End If
Next
End Sub


hope that helps
Have a nice day
  • 0

lucky027
Rookie
 
Posts: 10
Joined: Dec 7, 2011
Reputation: 0

Re: Need macro to find duplicates and delete based on criter

Postby dmaner » Mon Jan 09, 2012 1:38 pm

Thank you so much, that works perfectly!
  • 0

dmaner
Rookie
 
Posts: 7
Joined: Jan 9, 2012
Reputation: 0


Return to Macros and VBA Questions

Who is online

Users browsing this forum: Majestic-12 [Bot] and 265 guests