Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Macro to delete duplicate data
Hello All,
Can someone tell me how to create a macro to delete duplicate data in a spreadsheet? Here is what I would like it to do: scan down a column of data and compare the value in one cell to the cell directly above it, if the contents of the two cells (say C25 and C26) are the same, the lower row (in this example row 26) is deleted and cells shifted up. This would continue until a blank cell is encountered. Thanks for any suggestions you can give. Tom |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Macro to delete duplicate data
Adjust this to your needs, and it should work...
Sub DeleteDuplicates() Dim c As Long, r As Long, firstRow As Long, lastRow As Long c = 3 'this is the column to check for duplicates firstRow = 2 'this assumes you have headers, if you don't change this to 1 lastRow = Cells(Rows.Count, c).End(xlUp).Row For r = lastRow To firstRow Step -1 If r 1 Then If Cells(r, c) = Cells(r - 1, c) Then Rows(r).Delete End If End If Next End Sub |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Macro to delete duplicate data
Thanks for the quick reply.
I will give it a try. Tom "TommyGun" wrote in message ... Adjust this to your needs, and it should work... Sub DeleteDuplicates() Dim c As Long, r As Long, firstRow As Long, lastRow As Long c = 3 'this is the column to check for duplicates firstRow = 2 'this assumes you have headers, if you don't change this to 1 lastRow = Cells(Rows.Count, c).End(xlUp).Row For r = lastRow To firstRow Step -1 If r 1 Then If Cells(r, c) = Cells(r - 1, c) Then Rows(r).Delete End If End If Next End Sub |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Delete Duplicate Rows Macro Question | Excel Discussion (Misc queries) | |||
Macro to delete duplicate records | Excel Programming | |||
Macro to delete duplicate data in row | Excel Programming | |||
Macro to delete duplicate data | Excel Programming | |||
Macro to delete duplicate/triplicate rows | Excel Programming |