I was working on a database in Excell 2010 and found many duplicated names. I tried to make a VBA Script to solve this, but it just ends on a infinite loop. I wanted it to stop when it hits a blank cell. Heres the code I came up with
Sub excluirDuplicatas()
Dim lngCont As Long
Dim lngLinhas As Long
Dim rngNom1 As Range
Dim rngNom2 As Range
lngCont = 0
lngLinhas = Cells.SpecialCells(xlCellTypeLastCell).Row
While lngCont <= lngLinhas
Set rngNom1 = ActiveCell
Set rngNom2 = rngNom1.Offset(1, 0)
While rngNom1.Value = rngNom2.Value And rngNom2 <> lastRow
rngNom2.Select
rngNom2.EntireRow.Delete
Set rngNom2 = ActiveCell
Wend
Set rngNom1 = rngNom2
Set rngNom1 = ActiveCell
Set rngNom1 = rngNom2
rngNom1.Select
lngCont = lngCont + 1
Wend
End Sub
I don't know whats wrong, my guess is the part where I state
rngNom2 <> Cells.SpecialCells(xlCellTypeLastCell).Row
Please be aware that I starded VBA Programing today(March 22th). If you could please post not only the answer but also a quick explanation I would appreciate.
PS: The data sheet has over 2000 lines long