PDA

View Full Version : Solved: Removing duplicates based on two columns



DanOfEarth
06-03-2010, 01:13 PM
Hi guys,

Sorry so needy. I've got a nasty deadline. If I don't get this in time, people's houses get foreclosed on.

This should be simple. I'm getting an error at the "with selection". I knew it would hang there, but I can't figure out how to apply ".Removeduplicates" to the selection. I prob don't even need the "with" statement.


Sub Duplicates()
'
' Duplicates Macro
Sheets("Leads").Select
Set rng = ActiveSheet.UsedRange
rng.Offset(1, 0).Resize(rng.Rows.Count - 1, _
rng.Columns.Count).Select

With Selection
.RemoveDuplicates Columns:=Array(3, 4),
Header:=xlYes
End With
End Sub

mdmackillop
06-03-2010, 03:47 PM
Sample data always helps.
RemoveDuplicates sounds like a custom function. Please post all of your code.

mdmackillop
06-03-2010, 03:52 PM
Sorry so needy. I've got a nasty deadline. If I don't get this in time, people's houses get foreclosed on.

While we are happy to assist, if this is urgent you should really consider paying a professional for a solution. We are not an emergency service.

Tinbendr
06-03-2010, 05:21 PM
Appears you can only use it with the Range (http://msdn.microsoft.com/en-us/library/bb238869%28office.12%29.aspx) object. (Another reason to use Range.)

Sub Duplicates()
'
' Duplicates Macro
Dim Rng As Range
Sheets("Leads").Select

Set Rng = ActiveSheet.UsedRange

With Rng.Offset(1, 0).Resize(Rng.Rows.Count - 1, _
Rng.Columns.Count)
.RemoveDuplicates Columns:=Array(3, 4), Header:=xlYes
End With
End Sub

DanOfEarth
06-03-2010, 06:13 PM
Awesome...Tinbendr my man you're a genious. Taking what you said, I was able to simplify it even more. It was sickly simple:

Sub Duplicates()
'
' Duplicates Macro
Sheets("Leads").Select
ActiveSheet.UsedRange.RemoveDuplicates Columns:=Array(3, 4), Header:=xlYes
End Sub

And no, mdmackillop, I don't think that's a custom function or code.