ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Deleting Rows where some Cells have same Content (https://www.excelbanter.com/excel-programming/309333-deleting-rows-where-some-cells-have-same-content.html)

JamesT[_2_]

Deleting Rows where some Cells have same Content
 
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

Tom Ogilvy

Deleting Rows where some Cells have same Content
 
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

--
Regards,
Tom Ogilvy





"JamesT" wrote in message
...
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




Tom Ogilvy

Deleting Rows where some Cells have same Content
 
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

--
Regards,
Tom Ogilvy



"JamesT" wrote in message
...
Thanks Tom

I tried to run the Script on the following very simplified sheet where I

am
conerned with Title/Platform and Prog as my sear criteria... Where Title

and
Platform and Program are the same I want the duplicates deleted

irrespective
of Pack and Doc. The Script did not work on this and I do not know how to
alter it - Any suggestions?


title platform prog pack doc

a ps2 e e e
a ps2 f f f
a ps2 f g g
a ps2 g I l
b ps2 e t t
b xbox e g g
c ps2 e hg hg
c pccd e gf gf


"Tom Ogilvy" wrote:

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

--
Regards,
Tom Ogilvy





"JamesT" wrote in message
...
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








All times are GMT +1. The time now is 10:13 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com