Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 70
Default How to completely remove duplicate rows in vba

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default How to completely remove duplicate rows in vba

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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 70
Default How to completely remove duplicate rows in vba

On Aug 27, 10:50*pm, Patrick Molloy
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
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
remove duplicate rows but keeping all columns DC Excel Worksheet Functions 3 June 10th 09 03:10 AM
Highlight/remove duplicate rows Blasting Cap Excel Programming 3 September 7th 07 04:52 PM
How do I remove Duplicate rows? 85225 Excel Discussion (Misc queries) 15 March 9th 07 11:41 PM
Need macro to remove duplicate rows in a wksht with same order# G2 in AUS Excel Discussion (Misc queries) 2 December 16th 05 05:44 PM
Remove duplicate rows and sum cells ToddG[_4_] Excel Programming 7 September 27th 04 09:55 PM


All times are GMT +1. The time now is 10:36 PM.

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"