user3601714
user3601714

Reputation: 3

excel macro to compare a row with next and replace duplicate rows with blank

image: http://webserv-me.com/x.png

Hi, I've an excel sheet with 7000 row and I'd like please a VBA script in Excel 2007 to search in the selected Column and compare the row with the next, if any duplicate rows have been found, it should keep the original and remove the duplicate I.E: if we have 4 duplicates it should remove 3 and keep one, also the comparison with the next cell not with the entire colum this image will describe what I need, I found this code but the comparison between the row and the entire column, So it gives me a wrong result. http://www.teachexcel.com/free-excel-macros/m-23,delete-duplicate-rows-in-excel.html

thanks

Upvotes: 0

Views: 2035

Answers (2)

IronX
IronX

Reputation: 355

Select the Range of interest. Click the Remove Duplicates tool on the Data ribbon. Select the options in the dialog box to fit your specific needs. Click OK.

Upvotes: 0

Gary's Student
Gary's Student

Reputation: 96753

If we started with this:

before

and run this tiny macro:

Sub DeDup()
    Dim N As Long, i As Long
    N = Cells(Rows.Count, "A").End(xlUp).Row
    For i = N To 2 Step -1
        If Cells(i, "A").Value = Cells(i - 1, "A").Value Then Cells(i, "A").Clear
    Next i
End Sub

We would result in this:

after

Upvotes: 1

Related Questions