Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default Deleting Duplicate Rows

How do I Remove/Delete duplicate rows based on row value not column value? I
can't base it on Column value because some cells in the column might be the
same value but the over record may be different. I need to be able to delete
actual duplicate rows.

Joel
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Deleting Duplicate Rows

To match the entire row to another row would require each cell in that row to
be compared to the orther row. Most of the time these type comparisons can
be limited to two or three cells that contain primary data. That is data
that matters if it is duplicated. The remainder of the cells might contain
data that is not used for computation purposes and do not affect the out come
of any future computations.
In that case you could use a For... Next loop starting with the last record
and working to the top like:

lastRow = Worksheets(yourSht).Cells(Rows.Count, 1).End(xlUp).Row
lastCol = Worksheets(yourSht).Cells(1, Columns.Count).End(xlToLeft).Column
myRange = Worksheets(yourSht).Range("A1:A" & lastRow)
For i = lastRow To 2 Step -1
If Cells(i, 1) = Cells(i, 1).Offset(-1, 0) And Cells(i, 2) = _
Cells(i, 2).Offset(-1, 0) And Cells(i, 3 = Cells(i, 3).Offset(-1, 0) Then
Cells(i, 1).EntireRow.Delete
End If
Next

This snippet compares three data elements in each row to the same three
elements in the row above and if they match, considers the entire row to be a
duplicate and deletes the the bottom row, then move one row up. You will
need to to sort your data base before beginning for this snippet to work
properly.

If you must compare all of the data elements, the you would have to continue
with the And statements inside the If ... End If for each data field in the
row.


"Jase4now" wrote:

How do I Remove/Delete duplicate rows based on row value not column value? I
can't base it on Column value because some cells in the column might be the
same value but the over record may be different. I need to be able to delete
actual duplicate rows.

Joel

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 783
Default Deleting Duplicate Rows

If the functions in the freely downloadable file at
http://home.pacbell.net/beban are available to your workbook

Sub abtest4()
Dim rng As Range, i As Integer, j As Integer
Set rng = Range("DataRange").Rows
For i = rng.Rows.Count To 2 Step -1
For j = i - 1 To 1 Step -1
If RowsEqual(rng(i), rng(j)) Then
rng(i).Delete
i = i - 1
j = i
End If
Next j
Next i
End Sub

No sorting required.

Alan Beban

Jase4now wrote:
How do I Remove/Delete duplicate rows based on row value not column value? I
can't base it on Column value because some cells in the column might be the
same value but the over record may be different. I need to be able to delete
actual duplicate rows.

Joel

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
Deleting duplicate rows Balan Excel Programming 3 August 26th 07 04:04 AM
VBA for deleting duplicate rows ulfb[_2_] Excel Programming 4 June 27th 07 12:46 PM
Deleting Duplicate Rows pettes01 Excel Discussion (Misc queries) 4 November 8th 05 06:50 PM
Deleting Duplicate Rows RMort[_2_] Excel Programming 5 April 26th 05 09:43 PM
Deleting duplicate rows.....there's more Fredy Excel Programming 1 June 24th 04 07:04 PM


All times are GMT +1. The time now is 04:32 PM.

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

About Us

"It's about Microsoft Excel"