ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Comparing and deleting duplicate cells (https://www.excelbanter.com/excel-programming/303171-comparing-deleting-duplicate-cells.html)

David Jacobs

Comparing and deleting duplicate cells
 
I am trying to compare the contents of a cell and the one below it. If it
is the same then delete the upper one.Have come up with this (please don't
laugh):

For cellcount = 1 To 500
If Cells(B, cellcount) = Cells(B, cellcount + 1) Then
Cells(B, cellcount).Delete (xlShiftUp)
End If
Next

Have absolutely no idea about Excel Macro's but am keen to learn, in fact
this is my first shot so if someone could help with answers in one
syllable!!

FIA

David Jacobs



Bob Phillips[_6_]

Comparing and deleting duplicate cells
 
Work from the bottom up.

Cells object takes rows, column arguments, not the other way, and if you use
a column letter it must be in quotes

For cellcount = 500 To 1
If Cells(cellcount,"B")= Cells(cellcount + 1,"B") Then
Cells(cellcount,"B").Delete (xlShiftUp)
End If
Next


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"David Jacobs" wrote in message
...
I am trying to compare the contents of a cell and the one below it. If it
is the same then delete the upper one.Have come up with this (please don't
laugh):

For cellcount = 1 To 500
If Cells(B, cellcount) = Cells(B, cellcount + 1) Then
Cells(B, cellcount).Delete (xlShiftUp)
End If
Next

Have absolutely no idea about Excel Macro's but am keen to learn, in fact
this is my first shot so if someone could help with answers in one
syllable!!

FIA

David Jacobs





Jim May

Comparing and deleting duplicate cells
 
David, your going to have to add "Step -1" to the end of line 1 below, like
For cellcount = 500 To 1 Step -1
or code will not run.
JMay

"Bob Phillips" wrote in message
...
Work from the bottom up.

Cells object takes rows, column arguments, not the other way, and if you

use
a column letter it must be in quotes

For cellcount = 500 To 1
If Cells(cellcount,"B")= Cells(cellcount + 1,"B") Then
Cells(cellcount,"B").Delete (xlShiftUp)
End If
Next


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"David Jacobs" wrote in message
...
I am trying to compare the contents of a cell and the one below it. If

it
is the same then delete the upper one.Have come up with this (please

don't
laugh):

For cellcount = 1 To 500
If Cells(B, cellcount) = Cells(B, cellcount + 1) Then
Cells(B, cellcount).Delete (xlShiftUp)
End If
Next

Have absolutely no idea about Excel Macro's but am keen to learn, in

fact
this is my first shot so if someone could help with answers in one
syllable!!

FIA

David Jacobs







Bob Phillips[_6_]

Comparing and deleting duplicate cells
 
Oops, thanks Jim (that will teach me to air-code as Rob Bovey said)

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Jim May" wrote in message
news:39wFc.20576$mN3.2727@lakeread06...
David, your going to have to add "Step -1" to the end of line 1 below,

like
For cellcount = 500 To 1 Step -1
or code will not run.
JMay

"Bob Phillips" wrote in message
...
Work from the bottom up.

Cells object takes rows, column arguments, not the other way, and if you

use
a column letter it must be in quotes

For cellcount = 500 To 1
If Cells(cellcount,"B")= Cells(cellcount + 1,"B") Then
Cells(cellcount,"B").Delete (xlShiftUp)
End If
Next


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"David Jacobs" wrote in message
...
I am trying to compare the contents of a cell and the one below it.

If
it
is the same then delete the upper one.Have come up with this (please

don't
laugh):

For cellcount = 1 To 500
If Cells(B, cellcount) = Cells(B, cellcount + 1) Then
Cells(B, cellcount).Delete (xlShiftUp)
End If
Next

Have absolutely no idea about Excel Macro's but am keen to learn, in

fact
this is my first shot so if someone could help with answers in one
syllable!!

FIA

David Jacobs










All times are GMT +1. The time now is 05:14 PM.

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