PC Review


Reply
Thread Tools Rate Thread

Delete Entire Row for duplicate values in selected column

 
 
porter444
Guest
Posts: n/a
 
      24th Nov 2008
I work with massive lists of data everyday, and many times have to combine
multiple sheets. This of course leads to duplicates, and hence having to
delete the duplicates. Today I use countif if to identify them, sort and
delete.

This works fine, but I keep thinking there has to be a better way.

What I'd really like to have is a macro that, for the column I select, rows
with duplicate values are deleted. If no duplicates are found, a message box
that says that. Would like to keep the first value found.

Thanks in advance!

Scott
 
Reply With Quote
 
 
 
 
dbKemp
Guest
Posts: n/a
 
      24th Nov 2008
On Nov 24, 9:41 am, porter444 <porter...@discussions.microsoft.com>
wrote:
> I work with massive lists of data everyday, and many times have to combine
> multiple sheets. This of course leads to duplicates, and hence having to
> delete the duplicates. Today I use countif if to identify them, sort and
> delete.
>
> This works fine, but I keep thinking there has to be a better way.
>
> What I'd really like to have is a macro that, for the column I select, rows
> with duplicate values are deleted. If no duplicates are found, a message box
> that says that. Would like to keep the first value found.
>
> Thanks in advance!
>
> Scott


I use this. You could also use the Scripting.Dictionary object if
this is too slow.


Private Sub RemoveDupeRecords(ByRef Target As Range, ByVal RefCol As
Integer)
' Purpose:
' Deletes entire row of data when reference value is duplicated.
'
' Inputs:
' [Target] In/Out - Range representing database
' [RefCol] In - Column to be used to determine duplicate records
'
' Remarks:
' Attempts to put value of each cell in RefCol into a collection
' If there is a duplicate an error occurs and ErrorHandler deletes
' entire row of associated cell.

Dim iCounter As Integer
Dim sValue As String 'data in rCell, used for dupe check
Dim colUniqueTerms As Collection
Dim rCell As Range 'current cell

Set colUniqueTerms = New Collection
On Error GoTo ErrorHandler
For iCounter = Target.Rows.Count To 2 Step -1
Set rCell = Target.Cells(iCounter, RefCol)
sValue = rCell.Value
colUniqueTerms.Add sValue, sValue
Next
On Error GoTo 0

Set colUniqueTerms = Nothing
Set rCell = Nothing
Exit Sub
ErrorHandler:
rCell.EntireRow.Delete
Resume Next
End Sub
 
Reply With Quote
 
porter444
Guest
Posts: n/a
 
      24th Nov 2008
THANKS!
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Delete an entire row if a selected row doesn't have a specified value in a cell marcusdmc@gmail.com Microsoft Excel Programming 1 27th Jun 2007 09:06 PM
Delete entire row if two cells are duplicate Les Stout Microsoft Excel Programming 4 15th Sep 2006 01:50 PM
Determine if entire row or column is selected MC82 Microsoft Excel Programming 3 29th Apr 2006 12:33 AM
Don't run if entire column is selected =?Utf-8?B?RWxhaW5l?= Microsoft Excel Programming 4 21st Mar 2005 02:01 AM
How to run delete duplicate contacts on entire folder C. Hamill Microsoft Outlook Contacts 0 6th Aug 2003 11:55 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:29 PM.