Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default Delete Duplicate rows in a range

Hi
try the following:
1. create a helper column C with the formula
=A1&B1
and copy this down for all rows

2. Use the macro on the following site:
http://www.cpearson.com/excel/deleti...eDuplicateRows

In your case change it to

Public Sub DeleteDuplicateRows()
'
' This macro deletes duplicate rows in the selection. Duplicates are
' counted in the COLUMN of the active cell.

Dim Col As Integer
Dim r As Long
Dim C As Range
Dim N As Long
Dim V As Variant
Dim Rng As Range

On Error GoTo EndMacro
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

Col = ActiveCell.Column

If Selection.Rows.Count 1 Then
Set Rng = Selection
Else
Set Rng = ActiveSheet.UsedRange.Rows
End If

N = 0
For r = Rng.Rows.Count To 1 Step -1
V = Rng.Cells(r, 3).Value
If Application.WorksheetFunction.CountIf(Rng.Columns( 3), V) 1
Then
Rng.Rows(r).EntireRow.Delete
N = N + 1
End If
Next r

EndMacro:

Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic

End Sub


--
Regards
Frank Kabel
Frankfurt, Germany


UK wrote:
In Excel I need a way to delete duplicate rows based on
more than one column.eg:

Original Data in a range of cells:

A 1
B 1
C 2
A 3
A 1
B 2
B 1
C 5
C 2


Resulting data after deleting duplicate rows should look
like below

A 1
B 1
C 2
A 3
B 2
C 5

Any help is appreciated. 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 duplicate rows, keep one Wasdell Excel Discussion (Misc queries) 1 October 30th 09 12:16 PM
delete duplicate rows christinaLO Excel Worksheet Functions 1 February 27th 07 06:22 PM
HELP delete duplicate rows. Malcolm Excel Programming 2 September 29th 03 11:48 AM
Delete duplicate rows christina Excel Programming 1 August 4th 03 01:04 PM
delete duplicate rows rhys Excel Programming 2 July 29th 03 12:52 PM


All times are GMT +1. The time now is 07:24 AM.

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"