Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default 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
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 Macro Question elfmajesty Excel Discussion (Misc queries) 1 June 17th 06 01:12 AM
Macro to delete duplicate records Horselover Excel Programming 2 July 1st 04 03:06 PM
Macro to delete duplicate data in row Tony Excel Programming 2 November 13th 03 03:17 PM
Macro to delete duplicate data Tony Excel Programming 0 November 12th 03 10:52 PM
Macro to delete duplicate/triplicate rows Ken Wright Excel Programming 0 August 11th 03 05:50 PM


All times are GMT +1. The time now is 05:44 AM.

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"