Deleting Rows where some Cells have same Content

J

JamesT

Hello

I am after a Macro that will delete rows where information is the same in
defined columns.... I have data that is similar to the following, but extends
across several comumns, but I only want to conern the macro with the first 3
colums for instance:

Name Book Language

James Flowers French
James Flowers French
James Flowers German

Name Book Language

James Flowers French
James Flowers German

I want it to leave me with, can anyone help with a VB Macro?

thanks
 
T

Tom Ogilvy

Sub DeleteDups()
Dim i As Long

i = 2
Do While Not IsEmpty(Cells(i, 1))
If Cells(i, 1) = Cells(i - 1, 1) And _
Cells(i, 2) = Cells(i - 1, 2) And _
Cells(i, 3) = Cells(i - 1, 3) Then
Cells(i, 1).EntireRow.Delete
Else
i = i + 1
End If
Loop
End Sub
 
T

Tom Ogilvy

It stops when it finds a blank cell. If you really have a header row and
your data starts in row 3, then here is the adjustment:

Sub DeleteDups()
Dim i As Long

i = 4
Do While Not IsEmpty(Cells(i, 1))
If Cells(i, 1) = Cells(i - 1, 1) And _
Cells(i, 2) = Cells(i - 1, 2) And _
Cells(i, 3) = Cells(i - 1, 3) Then
Cells(i, 1).EntireRow.Delete
Else
i = i + 1
End If
Loop
End Sub
 
Top