Pergunta

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

Foi útil?

Solução

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

Outras dicas

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top