PC Review


Reply
Thread Tools Rate Thread

Code for duplicate rows?

 
 
=?Utf-8?B?ZnBkODMz?=
Guest
Posts: n/a
 
      20th Jun 2007
Following up on a previous post.

I have a list of data in columns A:I. I need to find all duplicate rows in
the used range based on the data in col G, cut the all duplicates and paste
into another worksheet in the workbook.

Tom Ogilvy provided the following routine, but this leaves behind 1 of the
duplicate rows. Lets say I have 3 rows that have the same data in col G, is
it possible to cut and past all 3 rows into the other sheet? Thanks in
advance for any help you can provide.

Thanks!

Sub ABC()
Dim rng As Range, rng1 As Range
Set rng = Intersect(ActiveSheet.UsedRange.EntireRow, _
ActiveSheet.Columns(10))
rng.Formula = "=if(Countif($G$1:G1,G1)>1,na(),"""")"
On Error Resume Next
Set rng1 = rng.SpecialCells(xlFormulas, xlErrors)
On Error GoTo 0
If Not rng1 Is Nothing Then
rng1.EntireRow.Copy Worksheets("Sheet2").Range("A1")
rng1.EntireRow.Delete
Worksheets("Sheet2").Columns(10).ClearContents
End If
ActiveSheet.Columns(10).ClearContents
End Sub


 
Reply With Quote
 
 
 
 
=?Utf-8?B?VG9tIE9naWx2eQ==?=
Guest
Posts: n/a
 
      20th Jun 2007
Column G
A
A '<== duplicate
A '<== duplicate

Is my interpretation of duplicate records and the code does that. If what
you describe now is what you actually want, the modification is simple:

Sub ABC()
Dim rng As Range, rng1 As Range
Set rng = Intersect(ActiveSheet.UsedRange.EntireRow, _
ActiveSheet.Columns(10))
rng.Formula = "=if(Countif($G:G,G1)>1,na(),"""")"
On Error Resume Next
Set rng1 = rng.SpecialCells(xlFormulas, xlErrors)
On Error GoTo 0
If Not rng1 Is Nothing Then
rng1.EntireRow.Copy Worksheets("Sheet2").Range("A1")
rng1.EntireRow.Delete
Worksheets("Sheet2").Columns(10).ClearContents
End If
ActiveSheet.Columns(10).ClearContents
End Sub

--
Regards,
Tom Ogilvy


"fpd833" wrote:

> Following up on a previous post.
>
> I have a list of data in columns A:I. I need to find all duplicate rows in
> the used range based on the data in col G, cut the all duplicates and paste
> into another worksheet in the workbook.
>
> Tom Ogilvy provided the following routine, but this leaves behind 1 of the
> duplicate rows. Lets say I have 3 rows that have the same data in col G, is
> it possible to cut and past all 3 rows into the other sheet? Thanks in
> advance for any help you can provide.
>
> Thanks!
>
> Sub ABC()
> Dim rng As Range, rng1 As Range
> Set rng = Intersect(ActiveSheet.UsedRange.EntireRow, _
> ActiveSheet.Columns(10))
> rng.Formula = "=if(Countif($G$1:G1,G1)>1,na(),"""")"
> On Error Resume Next
> Set rng1 = rng.SpecialCells(xlFormulas, xlErrors)
> On Error GoTo 0
> If Not rng1 Is Nothing Then
> rng1.EntireRow.Copy Worksheets("Sheet2").Range("A1")
> rng1.EntireRow.Delete
> Worksheets("Sheet2").Columns(10).ClearContents
> End If
> ActiveSheet.Columns(10).ClearContents
> End Sub
>
>

 
Reply With Quote
 
=?Utf-8?B?ZnBkODMz?=
Guest
Posts: n/a
 
      20th Jun 2007
Thanks Tom....that change makes sense! However this routine causes Excel to
stop responding. Any ideas?

"Tom Ogilvy" wrote:

> Column G
> A
> A '<== duplicate
> A '<== duplicate
>
> Is my interpretation of duplicate records and the code does that. If what
> you describe now is what you actually want, the modification is simple:
>
> Sub ABC()
> Dim rng As Range, rng1 As Range
> Set rng = Intersect(ActiveSheet.UsedRange.EntireRow, _
> ActiveSheet.Columns(10))
> rng.Formula = "=if(Countif($G:G,G1)>1,na(),"""")"
> On Error Resume Next
> Set rng1 = rng.SpecialCells(xlFormulas, xlErrors)
> On Error GoTo 0
> If Not rng1 Is Nothing Then
> rng1.EntireRow.Copy Worksheets("Sheet2").Range("A1")
> rng1.EntireRow.Delete
> Worksheets("Sheet2").Columns(10).ClearContents
> End If
> ActiveSheet.Columns(10).ClearContents
> End Sub
>
> --
> Regards,
> Tom Ogilvy
>
>
> "fpd833" wrote:
>
> > Following up on a previous post.
> >
> > I have a list of data in columns A:I. I need to find all duplicate rows in
> > the used range based on the data in col G, cut the all duplicates and paste
> > into another worksheet in the workbook.
> >
> > Tom Ogilvy provided the following routine, but this leaves behind 1 of the
> > duplicate rows. Lets say I have 3 rows that have the same data in col G, is
> > it possible to cut and past all 3 rows into the other sheet? Thanks in
> > advance for any help you can provide.
> >
> > Thanks!
> >
> > Sub ABC()
> > Dim rng As Range, rng1 As Range
> > Set rng = Intersect(ActiveSheet.UsedRange.EntireRow, _
> > ActiveSheet.Columns(10))
> > rng.Formula = "=if(Countif($G$1:G1,G1)>1,na(),"""")"
> > On Error Resume Next
> > Set rng1 = rng.SpecialCells(xlFormulas, xlErrors)
> > On Error GoTo 0
> > If Not rng1 Is Nothing Then
> > rng1.EntireRow.Copy Worksheets("Sheet2").Range("A1")
> > rng1.EntireRow.Delete
> > Worksheets("Sheet2").Columns(10).ClearContents
> > End If
> > ActiveSheet.Columns(10).ClearContents
> > End Sub
> >
> >

 
Reply With Quote
 
=?Utf-8?B?VG9tIE9naWx2eQ==?=
Guest
Posts: n/a
 
      20th Jun 2007
Sub ABC()
Dim rng As Range, rng1 As Range
Set rng = Intersect(ActiveSheet.UsedRange.EntireRow, _
ActiveSheet.Columns(10))
rng.Formula = "=if(Countif($G:$G,G1)>1,na(),"""")"
On Error Resume Next
Set rng1 = rng.SpecialCells(xlFormulas, xlErrors)
On Error GoTo 0
If Not rng1 Is Nothing Then
rng1.EntireRow.Copy Worksheets("Sheet2").Range("A1")
rng1.EntireRow.Delete
Worksheets("Sheet2").Columns(10).ClearContents
End If
ActiveSheet.Columns(10).ClearContents
End Sub

code worked fine for me.

Tested in xl2003

How many rows are you trying to process.

--
Regards,
Tom Ogilvy


"fpd833" wrote:

> Thanks Tom....that change makes sense! However this routine causes Excel to
> stop responding. Any ideas?
>
> "Tom Ogilvy" wrote:
>
> > Column G
> > A
> > A '<== duplicate
> > A '<== duplicate
> >
> > Is my interpretation of duplicate records and the code does that. If what
> > you describe now is what you actually want, the modification is simple:
> >
> > Sub ABC()
> > Dim rng As Range, rng1 As Range
> > Set rng = Intersect(ActiveSheet.UsedRange.EntireRow, _
> > ActiveSheet.Columns(10))
> > rng.Formula = "=if(Countif($G:G,G1)>1,na(),"""")"
> > On Error Resume Next
> > Set rng1 = rng.SpecialCells(xlFormulas, xlErrors)
> > On Error GoTo 0
> > If Not rng1 Is Nothing Then
> > rng1.EntireRow.Copy Worksheets("Sheet2").Range("A1")
> > rng1.EntireRow.Delete
> > Worksheets("Sheet2").Columns(10).ClearContents
> > End If
> > ActiveSheet.Columns(10).ClearContents
> > End Sub
> >
> > --
> > Regards,
> > Tom Ogilvy
> >
> >
> > "fpd833" wrote:
> >
> > > Following up on a previous post.
> > >
> > > I have a list of data in columns A:I. I need to find all duplicate rows in
> > > the used range based on the data in col G, cut the all duplicates and paste
> > > into another worksheet in the workbook.
> > >
> > > Tom Ogilvy provided the following routine, but this leaves behind 1 of the
> > > duplicate rows. Lets say I have 3 rows that have the same data in col G, is
> > > it possible to cut and past all 3 rows into the other sheet? Thanks in
> > > advance for any help you can provide.
> > >
> > > Thanks!
> > >
> > > Sub ABC()
> > > Dim rng As Range, rng1 As Range
> > > Set rng = Intersect(ActiveSheet.UsedRange.EntireRow, _
> > > ActiveSheet.Columns(10))
> > > rng.Formula = "=if(Countif($G$1:G1,G1)>1,na(),"""")"
> > > On Error Resume Next
> > > Set rng1 = rng.SpecialCells(xlFormulas, xlErrors)
> > > On Error GoTo 0
> > > If Not rng1 Is Nothing Then
> > > rng1.EntireRow.Copy Worksheets("Sheet2").Range("A1")
> > > rng1.EntireRow.Delete
> > > Worksheets("Sheet2").Columns(10).ClearContents
> > > End If
> > > ActiveSheet.Columns(10).ClearContents
> > > End Sub
> > >
> > >

 
Reply With Quote
 
=?Utf-8?B?ZnBkODMz?=
Guest
Posts: n/a
 
      20th Jun 2007
I'm running through about 3000 rows of data. When I run the macro Excel tells
me "Calaculating Cells 100%".....it does this twice but hangs at the second
100%. I have left it running for 30 minutes.....

Thanks Tom!

"Tom Ogilvy" wrote:

> Sub ABC()
> Dim rng As Range, rng1 As Range
> Set rng = Intersect(ActiveSheet.UsedRange.EntireRow, _
> ActiveSheet.Columns(10))
> rng.Formula = "=if(Countif($G:$G,G1)>1,na(),"""")"
> On Error Resume Next
> Set rng1 = rng.SpecialCells(xlFormulas, xlErrors)
> On Error GoTo 0
> If Not rng1 Is Nothing Then
> rng1.EntireRow.Copy Worksheets("Sheet2").Range("A1")
> rng1.EntireRow.Delete
> Worksheets("Sheet2").Columns(10).ClearContents
> End If
> ActiveSheet.Columns(10).ClearContents
> End Sub
>
> code worked fine for me.
>
> Tested in xl2003
>
> How many rows are you trying to process.
>
> --
> Regards,
> Tom Ogilvy
>
>
> "fpd833" wrote:
>
> > Thanks Tom....that change makes sense! However this routine causes Excel to
> > stop responding. Any ideas?
> >
> > "Tom Ogilvy" wrote:
> >
> > > Column G
> > > A
> > > A '<== duplicate
> > > A '<== duplicate
> > >
> > > Is my interpretation of duplicate records and the code does that. If what
> > > you describe now is what you actually want, the modification is simple:
> > >
> > > Sub ABC()
> > > Dim rng As Range, rng1 As Range
> > > Set rng = Intersect(ActiveSheet.UsedRange.EntireRow, _
> > > ActiveSheet.Columns(10))
> > > rng.Formula = "=if(Countif($G:G,G1)>1,na(),"""")"
> > > On Error Resume Next
> > > Set rng1 = rng.SpecialCells(xlFormulas, xlErrors)
> > > On Error GoTo 0
> > > If Not rng1 Is Nothing Then
> > > rng1.EntireRow.Copy Worksheets("Sheet2").Range("A1")
> > > rng1.EntireRow.Delete
> > > Worksheets("Sheet2").Columns(10).ClearContents
> > > End If
> > > ActiveSheet.Columns(10).ClearContents
> > > End Sub
> > >
> > > --
> > > Regards,
> > > Tom Ogilvy
> > >
> > >
> > > "fpd833" wrote:
> > >
> > > > Following up on a previous post.
> > > >
> > > > I have a list of data in columns A:I. I need to find all duplicate rows in
> > > > the used range based on the data in col G, cut the all duplicates and paste
> > > > into another worksheet in the workbook.
> > > >
> > > > Tom Ogilvy provided the following routine, but this leaves behind 1 of the
> > > > duplicate rows. Lets say I have 3 rows that have the same data in col G, is
> > > > it possible to cut and past all 3 rows into the other sheet? Thanks in
> > > > advance for any help you can provide.
> > > >
> > > > Thanks!
> > > >
> > > > Sub ABC()
> > > > Dim rng As Range, rng1 As Range
> > > > Set rng = Intersect(ActiveSheet.UsedRange.EntireRow, _
> > > > ActiveSheet.Columns(10))
> > > > rng.Formula = "=if(Countif($G$1:G1,G1)>1,na(),"""")"
> > > > On Error Resume Next
> > > > Set rng1 = rng.SpecialCells(xlFormulas, xlErrors)
> > > > On Error GoTo 0
> > > > If Not rng1 Is Nothing Then
> > > > rng1.EntireRow.Copy Worksheets("Sheet2").Range("A1")
> > > > rng1.EntireRow.Delete
> > > > Worksheets("Sheet2").Columns(10).ClearContents
> > > > End If
> > > > ActiveSheet.Columns(10).ClearContents
> > > > End Sub
> > > >
> > > >

 
Reply With Quote
 
Tom Ogilvy
Guest
Posts: n/a
 
      21st Jun 2007
Here is a modification:

Sub ABC()
Dim tt As Single
Dim calc As Long
Dim rng As Range, rng1 As Range
tt = Timer
calc = Application.Calculation
Application.Calculation = xlManual
Set rng = Intersect(ActiveSheet.UsedRange.EntireRow, _
ActiveSheet.Columns(10))
For Each cell In rng
cell.Formula = "=if(Countif($G$1:$G$5000,G" & cell.Row & ")>1,na(),"""")"
ActiveSheet.Calculate
cell.Formula = cell.Value
If cell.Row Mod 10 = 0 Then Application.StatusBar = cell.Row
Next
On Error Resume Next
Set rng1 = rng.SpecialCells(xlConstants, xlErrors)
On Error GoTo 0
If Not rng1 Is Nothing Then
rng1.EntireRow.Copy Worksheets("Sheet2").Range("A1")
rng1.EntireRow.Delete
Worksheets("Sheet2").Columns(10).ClearContents
End If
ActiveSheet.Columns(10).ClearContents
Application.Calculation = calc
Application.StatusBar = False
Debug.Print Timer - tt
End Sub


took about 10 seconds for me with 3500 rows.


--
Regards,
Tom Ogilvy


"fpd833" <(E-Mail Removed)> wrote in message
news:646F994C-D9E1-4A2D-8766-(E-Mail Removed)...
> I'm running through about 3000 rows of data. When I run the macro Excel
> tells
> me "Calaculating Cells 100%".....it does this twice but hangs at the
> second
> 100%. I have left it running for 30 minutes.....
>
> Thanks Tom!
>
> "Tom Ogilvy" wrote:
>
>> Sub ABC()
>> Dim rng As Range, rng1 As Range
>> Set rng = Intersect(ActiveSheet.UsedRange.EntireRow, _
>> ActiveSheet.Columns(10))
>> rng.Formula = "=if(Countif($G:$G,G1)>1,na(),"""")"
>> On Error Resume Next
>> Set rng1 = rng.SpecialCells(xlFormulas, xlErrors)
>> On Error GoTo 0
>> If Not rng1 Is Nothing Then
>> rng1.EntireRow.Copy Worksheets("Sheet2").Range("A1")
>> rng1.EntireRow.Delete
>> Worksheets("Sheet2").Columns(10).ClearContents
>> End If
>> ActiveSheet.Columns(10).ClearContents
>> End Sub
>>
>> code worked fine for me.
>>
>> Tested in xl2003
>>
>> How many rows are you trying to process.
>>
>> --
>> Regards,
>> Tom Ogilvy
>>
>>
>> "fpd833" wrote:
>>
>> > Thanks Tom....that change makes sense! However this routine causes
>> > Excel to
>> > stop responding. Any ideas?
>> >
>> > "Tom Ogilvy" wrote:
>> >
>> > > Column G
>> > > A
>> > > A '<== duplicate
>> > > A '<== duplicate
>> > >
>> > > Is my interpretation of duplicate records and the code does that. If
>> > > what
>> > > you describe now is what you actually want, the modification is
>> > > simple:
>> > >
>> > > Sub ABC()
>> > > Dim rng As Range, rng1 As Range
>> > > Set rng = Intersect(ActiveSheet.UsedRange.EntireRow, _
>> > > ActiveSheet.Columns(10))
>> > > rng.Formula = "=if(Countif($G:G,G1)>1,na(),"""")"
>> > > On Error Resume Next
>> > > Set rng1 = rng.SpecialCells(xlFormulas, xlErrors)
>> > > On Error GoTo 0
>> > > If Not rng1 Is Nothing Then
>> > > rng1.EntireRow.Copy Worksheets("Sheet2").Range("A1")
>> > > rng1.EntireRow.Delete
>> > > Worksheets("Sheet2").Columns(10).ClearContents
>> > > End If
>> > > ActiveSheet.Columns(10).ClearContents
>> > > End Sub
>> > >
>> > > --
>> > > Regards,
>> > > Tom Ogilvy
>> > >
>> > >
>> > > "fpd833" wrote:
>> > >
>> > > > Following up on a previous post.
>> > > >
>> > > > I have a list of data in columns A:I. I need to find all duplicate
>> > > > rows in
>> > > > the used range based on the data in col G, cut the all duplicates
>> > > > and paste
>> > > > into another worksheet in the workbook.
>> > > >
>> > > > Tom Ogilvy provided the following routine, but this leaves behind 1
>> > > > of the
>> > > > duplicate rows. Lets say I have 3 rows that have the same data in
>> > > > col G, is
>> > > > it possible to cut and past all 3 rows into the other sheet? Thanks
>> > > > in
>> > > > advance for any help you can provide.
>> > > >
>> > > > Thanks!
>> > > >
>> > > > Sub ABC()
>> > > > Dim rng As Range, rng1 As Range
>> > > > Set rng = Intersect(ActiveSheet.UsedRange.EntireRow, _
>> > > > ActiveSheet.Columns(10))
>> > > > rng.Formula = "=if(Countif($G$1:G1,G1)>1,na(),"""")"
>> > > > On Error Resume Next
>> > > > Set rng1 = rng.SpecialCells(xlFormulas, xlErrors)
>> > > > On Error GoTo 0
>> > > > If Not rng1 Is Nothing Then
>> > > > rng1.EntireRow.Copy Worksheets("Sheet2").Range("A1")
>> > > > rng1.EntireRow.Delete
>> > > > Worksheets("Sheet2").Columns(10).ClearContents
>> > > > End If
>> > > > ActiveSheet.Columns(10).ClearContents
>> > > > 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
How to convert duplicate rows into unique rows in a Table? KK Microsoft Access Queries 2 7th May 2008 02:40 PM
Speed up code Removing duplicate rows Ixtreme Microsoft Excel Programming 2 21st Aug 2007 05:48 PM
Eliminating records with duplicate fields, but not duplicate rows robert_dickey@hotmail.com Microsoft Access Queries 1 15th Sep 2006 03:34 PM
Convert columns to rows: create duplicate rows based on column val =?Utf-8?B?Q2FycmllUg==?= Microsoft Access 3 30th Aug 2006 07:07 PM
Duplicate rows Elimination- change rows accordingly meendar Microsoft Excel Programming 2 11th Apr 2006 05:31 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:58 PM.