Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 73
Default Delete Entire Row for duplicate values in selected column

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 58
Default Delete Entire Row for duplicate values in selected column

On Nov 24, 9:41 am, porter444
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
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 73
Default Delete Entire Row for duplicate values in selected column

THANKS!
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


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 [email protected] Excel Programming 1 June 27th 07 09:06 PM
Delete entire row if two cells are duplicate Les Stout[_2_] Excel Programming 4 September 15th 06 01:50 PM
Determine if entire row or column is selected MC82 Excel Programming 3 April 29th 06 12:33 AM
How do I delete duplicate records from an entire Excel workbook? Steven B. Excel Discussion (Misc queries) 0 December 6th 05 10:32 AM
Don't run if entire column is selected Elaine Excel Programming 4 March 21st 05 02:01 AM


All times are GMT +1. The time now is 01:48 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"