|
-
Feb 12th, 2010, 02:56 PM
#1
Thread Starter
Junior Member
[RESOLVED] Delete All but One Duplicate Row in Worksheet
I have a single worksheet with (let's say, for simplicity's sake) fifteen rows and ten columns. Rows number 2, 6 and 9 are exact duplicates of each other in all cells. How can I search through all of the rows, find the duplicates, and delete all but one of them (essentially keeping only one of each duplicate row? Below is some code I found that deletes ALL duplicate rows, but I want to keep one of them... Any suggestions?
Code:
'Delete Duplicate Rows
For i = 1 To Worksheets("Overview").UsedRange.Rows.Count
For j = Worksheets("Overview").UsedRange.Rows.Count To 1 Step -1
If Worksheets("Overview").Cells(i, 1) = Worksheets("Overview").Cells(j, 1) Then Worksheets("Overview").Rows(j).Delete
Next j
Next i
-
Feb 12th, 2010, 03:42 PM
#2
Re: Delete All but One Duplicate Row in Worksheet
try
vb Code:
For i = 1 To Worksheets("Overview").UsedRange.Rows.Count For j = Worksheets("Overview").UsedRange.Rows.Count To i + 1 Step -1 If Worksheets("Overview").Cells(i, 1) = Worksheets("Overview").Cells(j, 1) Then Worksheets("Overview").Rows(j).Delete Next j Next i
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Feb 12th, 2010, 04:13 PM
#3
Thread Starter
Junior Member
Re: Delete All but One Duplicate Row in Worksheet
That works BRILLIANTLY. THank yoU!
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|