PC Review


Reply
Thread Tools Rate Thread

How to completely remove duplicate rows in vba

 
 
geniusideas
Guest
Posts: n/a
 
      27th Aug 2009
Hi,

In one sheet I have many duplicate rows and I wanted to remove
completely and left non duplicate rows.Pls help how to do in VBA.
Example:
Before
A B
Mary 50
Jane 20
Sam 10
Jery 30
Jane 20
Sam 10

After
A B
Mary 50
Jery 30
Left only non duplicate rows.
Pls help.Thanks

 
Reply With Quote
 
 
 
 
Patrick Molloy
Guest
Posts: n/a
 
      27th Aug 2009
is col A unique or is it A B

ie will you ever have
Mary, 10
Mary, 20

if not then

Option Explicit

Sub sortanddelete()
Dim rw As Long

'sort the data
With Range("A1:A" & Range("A:A").Rows.Count)
.Sort Range("A1")
End With
'strip out duplicates
For rw = Range("A1").End(xlDown).Row To 2 Step -1
If Cells(rw, 1) = Cells(rw - 1, 1) Then Rows(rw).Delete
Next

End Sub




"geniusideas" wrote:

> Hi,
>
> In one sheet I have many duplicate rows and I wanted to remove
> completely and left non duplicate rows.Pls help how to do in VBA.
> Example:
> Before
> A B
> Mary 50
> Jane 20
> Sam 10
> Jery 30
> Jane 20
> Sam 10
>
> After
> A B
> Mary 50
> Jery 30
> Left only non duplicate rows.
> Pls help.Thanks
>
>

 
Reply With Quote
 
geniusideas
Guest
Posts: n/a
 
      27th Aug 2009
On Aug 27, 10:50*pm, Patrick Molloy
<PatrickMol...@discussions.microsoft.com> wrote:
> is col A unique or is it A B
>
> ie will you ever have
> Mary, 10
> Mary, 20
>
> if not then
>
> Option Explicit
>
> Sub sortanddelete()
> * * Dim rw As Long
>
> 'sort the data
> * * With Range("A1:A" & Range("A:A").Rows.Count)
> * * * * .Sort Range("A1")
> * * End With
> 'strip out duplicates * *
> * * For rw = Range("A1").End(xlDown).Row To 2 Step -1
> * * * * If Cells(rw, 1) = Cells(rw - 1, 1) Then Rows(rw).Delete
> * * Next
>
> End Sub
>
> "geniusideas" wrote:
> > Hi,

>
> > In one sheet I have many duplicate rows and I wanted to remove
> > completely and left non duplicate rows.Pls help how to do in VBA.
> > Example:
> > Before
> > * *A * * * * * * * * * B
> > Mary * * * * * * * *50
> > Jane * * * * * * * *20
> > Sam * * * * * * * *10
> > Jery * * * * * * * * 30
> > Jane * * * * * * * *20
> > Sam * * * * * * * *10

>
> > After
> > * A * * * * * * * * * B
> > Mary * * * * * * * *50
> > Jery * * * * * * * * 30
> > Left only non duplicate rows.
> > Pls help.Thanks


Dear Patrick,

Both col is unique, mean I should have
Mary, 10
Mary, 20

Thanks
 
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
Remove Duplicate Rows Philidec Microsoft Excel Worksheet Functions 0 26th Apr 2009 10:08 PM
How do I remove Duplicate rows? =?Utf-8?B?ODUyMjU=?= Microsoft Excel Misc 15 9th Mar 2007 11:41 PM
Could anyone help me to remove duplicate rows? Leon Microsoft ADO .NET 7 28th Sep 2004 02:52 PM
Remove duplicate rows =?Utf-8?B?dGJhc2lj?= Microsoft Excel Misc 1 15th Apr 2004 08:52 PM
Could anyone help me to remove duplicate rows? TaeHo Yoo Microsoft ASP .NET 1 21st Jul 2003 08:41 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:12 PM.