PC Review


Reply
Thread Tools Rate Thread

Deleting Duplicate Row Macro Question

 
 
JR
Guest
Posts: n/a
 
      16th Dec 2005
Hello,

I have the below macro which deletes duplicate entries based on column "A"
part number. The worksheet has nine columns, and column nine includes the
UPC code. So some duplicate rows may contain column nine with a upc code and
some may be blank. I need the duplicate rows that contains the ups code not
to be deleted. Also, some duplicate rows may not contain any info in column
nine, so still need it to leave one and delete others.

Thanks JR


Public Sub DeleteDuplicateRows()
'
' 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




 
Reply With Quote
 
 
 
 
Bernie Deitrick
Guest
Posts: n/a
 
      16th Dec 2005
Try this: Change

Rng.Rows(r).EntireRow.Delete

to

If Rng.Cells(r, 9).Value = "" Then Rng.Rows(r).EntireRow.Delete

HTH,
Bernie
MS Excel MVP


"JR" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
> Hello,
>
> I have the below macro which deletes duplicate entries based on column "A" part number. The
> worksheet has nine columns, and column nine includes the UPC code. So some duplicate rows may
> contain column nine with a upc code and some may be blank. I need the duplicate rows that contains
> the ups code not to be deleted. Also, some duplicate rows may not contain any info in column nine,
> so still need it to leave one and delete others.
>
> Thanks JR
>
>
> Public Sub DeleteDuplicateRows()
> '
> ' 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
>
>
>
>



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Macro Question - Find duplicate and make unique votequimby Microsoft Excel Programming 1 21st Jun 2006 03:03 PM
Macro Question - Find duplicate and make unique votequimby Microsoft Excel Programming 0 21st Jun 2006 02:28 PM
Delete Duplicate Rows Macro Question =?Utf-8?B?ZWxmbWFqZXN0eQ==?= Microsoft Excel Misc 1 17th Jun 2006 01:12 AM
Deleting duplicates Macro question Bungers Microsoft Excel Misc 2 14th Jan 2004 11:46 AM
Newbie question on deleting duplicate rows Phil Horwood Microsoft Excel Programming 4 26th Nov 2003 10:38 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:11 PM.