Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,069
Default looking for duplicates

I have a spreadsheet that has several thousand rows. I want to be able to
run a macro, or something, that will go through column A and return ONLY the
rows that have duplicate values in column A and delete all the other rows.

How would I do this???

Thanks in advance
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5
Default looking for duplicates

Hi,

This isn't entirely clear but I think you want to delete records that
aren't duplicated. so if a record exists only once this will delete
it. If so try this, if not post back and clarify.

Sub Please_delete_Me()
Dim copyrange As Range, lastrow As Long
lastrow = Cells(Cells.Rows.Count, "A").End(xlUp).Row
Set MyRange = Range("A1:A" & lastrow)
For Each c In MyRange
If WorksheetFunction.CountIf(Range("A:A"), c.Value) = 1 Then
If copyrange Is Nothing Then
Set copyrange = c.EntireRow
Else
Set copyrange = Union(copyrange, c.EntireRow)
End If
End If
Next
If Not copyrange Is Nothing Then
copyrange.Delete
End If
End Sub

Mike

On Fri, 25 Sep 2009 11:20:01 -0700, John
wrote:

I have a spreadsheet that has several thousand rows. I want to be able to
run a macro, or something, that will go through column A and return ONLY the
rows that have duplicate values in column A and delete all the other rows.

How would I do this???

Thanks in advance

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 6
Default looking for duplicates

this tuturial might help
http://www.mrexcel.com/articles/dupl...formatting.php

"John" wrote:

I have a spreadsheet that has several thousand rows. I want to be able to
run a macro, or something, that will go through column A and return ONLY the
rows that have duplicate values in column A and delete all the other rows.

How would I do this???

Thanks in advance

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 6
Default looking for duplicates

If you have 2007 excel then under the data tab in the data tools section you
can apply a function called "Remove Duplicates"


"John" wrote:

I have a spreadsheet that has several thousand rows. I want to be able to
run a macro, or something, that will go through column A and return ONLY the
rows that have duplicate values in column A and delete all the other rows.

How would I do this???

Thanks in advance

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,069
Default looking for duplicates

works great, thank you

" wrote:

Hi,

This isn't entirely clear but I think you want to delete records that
aren't duplicated. so if a record exists only once this will delete
it. If so try this, if not post back and clarify.

Sub Please_delete_Me()
Dim copyrange As Range, lastrow As Long
lastrow = Cells(Cells.Rows.Count, "A").End(xlUp).Row
Set MyRange = Range("A1:A" & lastrow)
For Each c In MyRange
If WorksheetFunction.CountIf(Range("A:A"), c.Value) = 1 Then
If copyrange Is Nothing Then
Set copyrange = c.EntireRow
Else
Set copyrange = Union(copyrange, c.EntireRow)
End If
End If
Next
If Not copyrange Is Nothing Then
copyrange.Delete
End If
End Sub

Mike

On Fri, 25 Sep 2009 11:20:01 -0700, John
wrote:

I have a spreadsheet that has several thousand rows. I want to be able to
run a macro, or something, that will go through column A and return ONLY the
rows that have duplicate values in column A and delete all the other rows.

How would I do this???

Thanks in advance


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
Duplicates shaloy Excel Worksheet Functions 2 September 6th 08 07:25 PM
Condensing a list with duplicates to a list with non-duplicates Nuclear Excel Worksheet Functions 2 July 29th 08 08:03 PM
Duplicates in excel that aren't 100% DUPLICATES ... [email protected] Excel Discussion (Misc queries) 4 May 2nd 08 06:43 PM
Keep non-duplicates only GMK Excel Worksheet Functions 7 October 25th 06 03:04 PM
Duplicates Steved Excel Worksheet Functions 2 August 25th 05 10:58 AM


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