Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Macro to copy duplicate rows (not delete)

Hello,

I have unsorted data (and needs to stay unsorted, so no autofilter/sort
on original data) that I want to copy all duplicate rows into another
sheet based on a column value. Example:


A B C ...
1 x a a
2 z b b
3 x c c
4 y d d
5 z e e
6 r f f
7 x g g
....


Using column A as criterion for duplicates. There are 3 instances of x
and 2 instances of z that will need to be copied. Another worksheet
would then contain:


A B C
1 x a a
2 x c c
3 x g g
4 z b b
5 z e e


I have been looking at other macros that are prevalent in this
newsgroup that DELETE duplicate rows. However, I do not want to delete
anything, or modify the original worksheet for that matter. Since I do
not know the # of times a particular value in the column would be
duplicated, I'm not sure a 2 FOR/LOOP type statements ala bubble-sort
type method would work?

The method I'm employing as a workaround is to use an empty column and
do:
IF((COUNTIF($A:$A, A1)1), "dupe", "")
...and then let a macro copy & paste all rows that show "dupe" value.
Ideally I would like to omit this step.


Thanks,
-jzk

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Macro to copy duplicate rows (not delete)

Sub ABC()
Dim rng As Range, rng1 As Range
Dim i As Long
With Worksheets("Sheet1")
Set rng = .Range("A1").CurrentRegion
End With
rng.Copy Destination:=Worksheets("Sheet2").Range("A1")
With Worksheets("Sheet2")
Set rng1 = .Range(rng.Address).Resize(, 1)
For i = rng.Rows.Count To 1 Step -1
If Application.CountIf(rng1, .Cells(i, 1)) = 1 Then
.Rows(i).Delete
End If
Next
End With
End Sub


--
Regards,
Tom Ogilvy


wrote in message
oups.com...
Hello,

I have unsorted data (and needs to stay unsorted, so no autofilter/sort
on original data) that I want to copy all duplicate rows into another
sheet based on a column value. Example:


A B C ...
1 x a a
2 z b b
3 x c c
4 y d d
5 z e e
6 r f f
7 x g g
...


Using column A as criterion for duplicates. There are 3 instances of x
and 2 instances of z that will need to be copied. Another worksheet
would then contain:


A B C
1 x a a
2 x c c
3 x g g
4 z b b
5 z e e


I have been looking at other macros that are prevalent in this
newsgroup that DELETE duplicate rows. However, I do not want to delete
anything, or modify the original worksheet for that matter. Since I do
not know the # of times a particular value in the column would be
duplicated, I'm not sure a 2 FOR/LOOP type statements ala bubble-sort
type method would work?

The method I'm employing as a workaround is to use an empty column and
do:
IF((COUNTIF($A:$A, A1)1), "dupe", "")
..and then let a macro copy & paste all rows that show "dupe" value.
Ideally I would like to omit this step.


Thanks,
-jzk



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
Delete Duplicate Rows Macro Question elfmajesty Excel Discussion (Misc queries) 1 June 17th 06 01:12 AM
Macro - to copy duplicate rows to another sheet [email protected] Excel Worksheet Functions 2 April 19th 05 01:53 AM
Macro to delete duplicate/triplicate rows Ken Wright Excel Programming 0 August 11th 03 05:50 PM
Macro to delete duplicate/triplicate rows Tom Ogilvy Excel Programming 0 August 11th 03 05:47 PM
delete duplicate rows rhys Excel Programming 2 July 29th 03 12:52 PM


All times are GMT +1. The time now is 01:20 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"