Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default delete duplicates macro to color instead of delete


I have this macro I found online. Once I sort my sheet by the column of
the selection that I'm' about to make (it has to be sorted) I then
select all the data in that column and this macro runs through and
deletes rows in which there are duplicate numbers. I'm trying to edit
it so that instead of deleting it colors it so I can decide what to do
from there. Here's the code.

Code:
--------------------
Public Sub DELETE_DUPLICATE_ROWS()
'
' This macro deletes duplicate rows in the selection. Duplicates are
' counted in the COLUMN of the active cell.

Dim col As Integer
Dim r As Long
Dim C As Range
Dim N As Long
Dim V As Variant
Dim rng As Range

On Error GoTo EndMacro
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

col = ActiveCell.Column

If Selection.Rows.Count 1 Then
Set rng = Selection
Else
Set rng = ActiveSheet.UsedRange.Rows
End If

N = 0
For r = rng.Rows.Count To 1 Step -1
V = rng.Cells(r, 1).Value
If Application.WorksheetFunction.CountIf(rng.Columns( 1), V) 1 Then
rng.Rows(r).EntireRow.delete
N = N + 1
End If
Next r

EndMacro:

Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic

End Sub
--------------------


I try and replace the
rng.Rows(r).EntireRow.delete
with
rng.Rows(r).EntireRow.ColorIndex = 36
and the macro doesn't work right. It runs until it finds a duplicate
then it Ends the Macro. Does anyone know why my snippet of code is
stopping this from running correctly?


--
DKY
------------------------------------------------------------------------
DKY's Profile: http://www.excelforum.com/member.php...o&userid=14515
View this thread: http://www.excelforum.com/showthread...hreadid=471112

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default delete duplicates macro to color instead of delete

Take a look he

http://cpearson.com/excel/duplicat.htm

In article ,
DKY wrote:

I have this macro I found online. Once I sort my sheet by the column of
the selection that I'm' about to make (it has to be sorted) I then
select all the data in that column and this macro runs through and
deletes rows in which there are duplicate numbers. I'm trying to edit
it so that instead of deleting it colors it so I can decide what to do
from there. Here's the code.

Code:
--------------------
Public Sub DELETE_DUPLICATE_ROWS()
'
' This macro deletes duplicate rows in the selection. Duplicates are
' counted in the COLUMN of the active cell.

Dim col As Integer
Dim r As Long
Dim C As Range
Dim N As Long
Dim V As Variant
Dim rng As Range

On Error GoTo EndMacro
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

col = ActiveCell.Column

If Selection.Rows.Count 1 Then
Set rng = Selection
Else
Set rng = ActiveSheet.UsedRange.Rows
End If

N = 0
For r = rng.Rows.Count To 1 Step -1
V = rng.Cells(r, 1).Value
If Application.WorksheetFunction.CountIf(rng.Columns( 1), V) 1 Then
rng.Rows(r).EntireRow.delete
N = N + 1
End If
Next r

EndMacro:

Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic

End Sub
--------------------


I try and replace the
rng.Rows(r).EntireRow.delete
with
rng.Rows(r).EntireRow.ColorIndex = 36
and the macro doesn't work right. It runs until it finds a duplicate
then it Ends the Macro. Does anyone know why my snippet of code is
stopping this from running correctly?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default delete duplicates macro to color instead of delete

Public Sub DELETE_DUPLICATE_ROWS()
'
' This macro deletes duplicate rows in the selection. Duplicates are
' counted in the COLUMN of the active cell.

Dim col As Integer
Dim r As Long
Dim C As Range
Dim N As Long
Dim V As Variant
Dim rng As Range

On Error GoTo EndMacro
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

col = ActiveCell.Column

If Selection.Rows.Count 1 Then
Set rng = Selection
Else
Set rng = ActiveSheet.UsedRange.Rows
End If

N = 0
For r = rng.Rows.Count To 1 Step -1
V = rng.Cells(r, 1).Value
If Application.WorksheetFunction.CountIf(rng.Columns( 1), V) 1 Then
rng.Rows(r).EntireRow.Interior.ColorIndex = 5
N = N + 1
End If
Next r

EndMacro:

Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic

End Sub


--
Regards,
Tom Ogilvy

"DKY" wrote in message
...

I have this macro I found online. Once I sort my sheet by the column of
the selection that I'm' about to make (it has to be sorted) I then
select all the data in that column and this macro runs through and
deletes rows in which there are duplicate numbers. I'm trying to edit
it so that instead of deleting it colors it so I can decide what to do
from there. Here's the code.

Code:
--------------------
Public Sub DELETE_DUPLICATE_ROWS()
'
' This macro deletes duplicate rows in the selection. Duplicates are
' counted in the COLUMN of the active cell.

Dim col As Integer
Dim r As Long
Dim C As Range
Dim N As Long
Dim V As Variant
Dim rng As Range

On Error GoTo EndMacro
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

col = ActiveCell.Column

If Selection.Rows.Count 1 Then
Set rng = Selection
Else
Set rng = ActiveSheet.UsedRange.Rows
End If

N = 0
For r = rng.Rows.Count To 1 Step -1
V = rng.Cells(r, 1).Value
If Application.WorksheetFunction.CountIf(rng.Columns( 1), V) 1 Then
rng.Rows(r).EntireRow.delete
N = N + 1
End If
Next r

EndMacro:

Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic

End Sub
--------------------


I try and replace the
rng.Rows(r).EntireRow.delete
with
rng.Rows(r).EntireRow.ColorIndex = 36
and the macro doesn't work right. It runs until it finds a duplicate
then it Ends the Macro. Does anyone know why my snippet of code is
stopping this from running correctly?


--
DKY
------------------------------------------------------------------------
DKY's Profile:

http://www.excelforum.com/member.php...o&userid=14515
View this thread: http://www.excelforum.com/showthread...hreadid=471112



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default delete duplicates macro to color instead of delete


Thank you Tom, that works beautifull

--
DK
-----------------------------------------------------------------------
DKY's Profile: http://www.excelforum.com/member.php...fo&userid=1451
View this thread: http://www.excelforum.com/showthread.php?threadid=47111

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default delete duplicates macro to color instead of delete

Hello Tom
you may be able to help me! Im tearing my hair out trying to manually
delete rows of data that is only exactly duplicated in two columns because of
typos etc ie Column C contains an exact duplicate of the entered data as
does column J. I need a macro to recognise the duplicates in the
corresponding row of C and J columns and then delete one of the rows.
The programming below looks like it may be tweaked so that it will say ' If
the duplicated cells in J are also duplicated cells in C-delete'
Column C contains duplicated names Column J contains duplicated codes that
are a mix of text and numbers.

"Tom Ogilvy" wrote:

Public Sub DELETE_DUPLICATE_ROWS()
'
' This macro deletes duplicate rows in the selection. Duplicates are
' counted in the COLUMN of the active cell.

Dim col As Integer
Dim r As Long
Dim C As Range
Dim N As Long
Dim V As Variant
Dim rng As Range

On Error GoTo EndMacro
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

col = ActiveCell.Column

If Selection.Rows.Count 1 Then
Set rng = Selection
Else
Set rng = ActiveSheet.UsedRange.Rows
End If

N = 0
For r = rng.Rows.Count To 1 Step -1
V = rng.Cells(r, 1).Value
If Application.WorksheetFunction.CountIf(rng.Columns( 1), V) 1 Then
rng.Rows(r).EntireRow.Interior.ColorIndex = 5
N = N + 1
End If
Next r

EndMacro:

Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic

End Sub


--
Regards,
Tom Ogilvy

"DKY" wrote in message
...

I have this macro I found online. Once I sort my sheet by the column of
the selection that I'm' about to make (it has to be sorted) I then
select all the data in that column and this macro runs through and
deletes rows in which there are duplicate numbers. I'm trying to edit
it so that instead of deleting it colors it so I can decide what to do
from there. Here's the code.

Code:
--------------------
Public Sub DELETE_DUPLICATE_ROWS()
'
' This macro deletes duplicate rows in the selection. Duplicates are
' counted in the COLUMN of the active cell.

Dim col As Integer
Dim r As Long
Dim C As Range
Dim N As Long
Dim V As Variant
Dim rng As Range

On Error GoTo EndMacro
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

col = ActiveCell.Column

If Selection.Rows.Count 1 Then
Set rng = Selection
Else
Set rng = ActiveSheet.UsedRange.Rows
End If

N = 0
For r = rng.Rows.Count To 1 Step -1
V = rng.Cells(r, 1).Value
If Application.WorksheetFunction.CountIf(rng.Columns( 1), V) 1 Then
rng.Rows(r).EntireRow.delete
N = N + 1
End If
Next r

EndMacro:

Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic

End Sub
--------------------


I try and replace the
rng.Rows(r).EntireRow.delete
with
rng.Rows(r).EntireRow.ColorIndex = 36
and the macro doesn't work right. It runs until it finds a duplicate
then it Ends the Macro. Does anyone know why my snippet of code is
stopping this from running correctly?


--
DKY
------------------------------------------------------------------------
DKY's Profile:

http://www.excelforum.com/member.php...o&userid=14515
View this thread: http://www.excelforum.com/showthread...hreadid=471112




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
macro find and delete duplicates in a spread sheet. Marc[_18_] Excel Programming 5 September 9th 13 09:28 PM
Macro to delete sheets and saves remaining file does not properly delete module pherrero Excel Programming 1 June 22nd 05 01:12 AM
Macro to delete sheets and saves remaining file does not properly delete module pherrero Excel Programming 0 June 21st 05 05:16 PM
Macro to delete sheets and saves remaining file does not properly delete module pherrero Excel Programming 0 June 21st 05 05:11 PM
Macro to delete sheets and saves remaining file does not properly delete module bhawane Excel Programming 0 June 21st 05 04:53 PM


All times are GMT +1. The time now is 06:44 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"