LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #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

 
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 04:54 PM.

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

About Us

"It's about Microsoft Excel"