Deleting Duplicate Rows 06-07-10

Hi,
I checked out the archives for close to an hour, but I couldn't figure out 
how to change the codes given there to suit my needs.
I have a large set of data, from about A1 to X441.  In column X, there are a 
lot of exact duplicates, and I need to delete the rows where those duplicates 
are (but still leaving the first instance of the duplicate).  For example:

John Smith Oxford St.
John Johnson Oxford St.
John Johnson Rubble St.
John Smith Oxford St.

All of those have things in common, but I only want to delete the final row 
(and the whole row, not just the cell), because it is an exact duplicate.  
How do I code for this?  Excel 2007.
Thanks,
Jbm
0
Utf
6/7/2010 8:06:22 PM
excel.programming 6508 articles. 2 followers. Follow

11 Replies
2326 Views

Similar Articles

[PageSpeed] 12

Select column X

2003  Data>Filter>Advanced Filter>Uniques only.

Copy to another place.

2007   Data>Remove Duplicates.

Unselect all.  Select only column X and remove.


Gord Dibben  MS Excel MVP

On Mon, 7 Jun 2010 13:06:22 -0700, Jbm <Jbm@discussions.microsoft.com>
wrote:

>Hi,
>I checked out the archives for close to an hour, but I couldn't figure =
out=20
>how to change the codes given there to suit my needs.
>I have a large set of data, from about A1 to X441.  In column X, there =
are a=20
>lot of exact duplicates, and I need to delete the rows where those =
duplicates=20
>are (but still leaving the first instance of the duplicate).  For =
example:
>
>John Smith Oxford St.
>John Johnson Oxford St.
>John Johnson Rubble St.
>John Smith Oxford St.
>
>All of those have things in common, but I only want to delete the final =
row=20
>(and the whole row, not just the cell), because it is an exact =
duplicate. =20
>How do I code for this?  Excel 2007.
>Thanks,
>Jbm

0
Gord
6/7/2010 8:30:54 PM
Another way that does not copy elsewhere IF? sorting is allowed. Assumes all 
text in ONE cell??
'==
Option Explicit
Sub SortAndDeleteDuplicatesSAS()
Dim mc As Long
Dim i As Long
mc = 1 'column A
Columns(mc).Sort Key1:=Cells(1, mc), Order1:=xlAscending, _
Header:=xlGuess, OrderCustom:=1, MatchCase:=False,Orientation:=xlTopToBottom
For i = Cells(Rows.Count, mc).End(xlUp).Row To 2 Step -1
  If Cells(i - 1, mc) = Cells(i, mc) Then Rows(i).Delete
Next i
End Sub
'====
-- 
Don Guillett
Microsoft MVP Excel
SalesAid Software
dguillett@gmail.com
"Jbm" <Jbm@discussions.microsoft.com> wrote in message 
news:1FA919E8-69ED-4C39-BCB1-68FBCD6D24F9@microsoft.com...
> Hi,
> I checked out the archives for close to an hour, but I couldn't figure out
> how to change the codes given there to suit my needs.
> I have a large set of data, from about A1 to X441.  In column X, there are 
> a
> lot of exact duplicates, and I need to delete the rows where those 
> duplicates
> are (but still leaving the first instance of the duplicate).  For example:
>
> John Smith Oxford St.
> John Johnson Oxford St.
> John Johnson Rubble St.
> John Smith Oxford St.
>
> All of those have things in common, but I only want to delete the final 
> row
> (and the whole row, not just the cell), because it is an exact duplicate.
> How do I code for this?  Excel 2007.
> Thanks,
> Jbm 

0
Don
6/7/2010 8:45:18 PM
=?Utf-8?B?SmJt?= <Jbm@discussions.microsoft.com> wrote in
news:1FA919E8-69ED-4C39-BCB1-68FBCD6D24F9@microsoft.com: 

> Hi,
> I checked out the archives for close to an hour, but I couldn't figure
> out how to change the codes given there to suit my needs.
> I have a large set of data, from about A1 to X441.  In column X, there
> are a lot of exact duplicates, and I need to delete the rows where
> those duplicates are (but still leaving the first instance of the
> duplicate).  For example: 
> 
> John Smith Oxford St.
> John Johnson Oxford St.
> John Johnson Rubble St.
> John Smith Oxford St.
> 
> All of those have things in common, but I only want to delete the
> final row (and the whole row, not just the cell), because it is an
> exact duplicate.  How do I code for this?  Excel 2007.
> Thanks,
> Jbm

Make a backup first just in case the results are not what you expect.

Excel 2007 select the whole sheet ctrl+a, goto data>data tools>remove 
duplicates, in the dialogue box click unselect all and then select row X 
click ok this will remove the whole row A-X where X is a duplicate.

Regards
  Steve
0
Steve
6/7/2010 8:49:04 PM
Well, those are not all duplicates, so what is the logic?
John Smith Oxford St. = John Smith Oxford St.
However, John Smith Oxford St. <> John Johnson Oxford St.

Take a look at this:
http://www.rondebruin.nl/easyfilter.htm

Maybe you will have to run through the data a couple times, but that should 
do what you want.

-- 
Ryan---
If this information was helpful, please indicate this by clicking ''Yes''.


"Jbm" wrote:

> Hi,
> I checked out the archives for close to an hour, but I couldn't figure out 
> how to change the codes given there to suit my needs.
> I have a large set of data, from about A1 to X441.  In column X, there are a 
> lot of exact duplicates, and I need to delete the rows where those duplicates 
> are (but still leaving the first instance of the duplicate).  For example:
> 
> John Smith Oxford St.
> John Johnson Oxford St.
> John Johnson Rubble St.
> John Smith Oxford St.
> 
> All of those have things in common, but I only want to delete the final row 
> (and the whole row, not just the cell), because it is an exact duplicate.  
> How do I code for this?  Excel 2007.
> Thanks,
> Jbm
0
Utf
6/7/2010 8:57:54 PM
This assumes Column A is continuously populated from top to bottom of data 
set.  If not, then pick another column to use for finding last row.  You can 
also use the UsedRange property of the sheet if necessary.

Sub NoXDups()

    Dim TestR As Long
    Dim MyStr As String
    
    For TestR = Range("A1").End(xlDown).Row To 1 Step -1
        MyStr = Cells(TestR, "X").Value
        If Range("X:X").Find(what:=MyStr, After:=Range("X1"), _
          LookAt:=xlWhole).Row <> TestR Then
            Rows(TestR & ":" & TestR).Delete shift:=xlUp
        End If
    Next TestR
    
End Sub


"Jbm" wrote:

> Hi,
> I checked out the archives for close to an hour, but I couldn't figure out 
> how to change the codes given there to suit my needs.
> I have a large set of data, from about A1 to X441.  In column X, there are a 
> lot of exact duplicates, and I need to delete the rows where those duplicates 
> are (but still leaving the first instance of the duplicate).  For example:
> 
> John Smith Oxford St.
> John Johnson Oxford St.
> John Johnson Rubble St.
> John Smith Oxford St.
> 
> All of those have things in common, but I only want to delete the final row 
> (and the whole row, not just the cell), because it is an exact duplicate.  
> How do I code for this?  Excel 2007.
> Thanks,
> Jbm
0
Utf
6/7/2010 8:58:08 PM
I tried your macro, but it doesn't seem to be working...  Maybe the fact that 
there are headers is screwing it up?  I've been working with your code since 
you posted it, but I can't get it to work correctly (Column A has data in 
every cell until the bottom of my data set).
0
Utf
6/7/2010 9:19:43 PM
Ryguy -- I can't install new software on this machine.

Gord -- it's telling me that it removed 11 duplicates, and 400some unique 
values remain.  Despite this, all the duplicates I can see are still there 
(and I am carefully checking to make sure they are the exact same....  They 
are).
0
Utf
6/7/2010 9:24:53 PM
Well this is deleting things, but not necessarily duplicates, and oftentimes 
cells instead of rows (which means correlated data is getting thrown off).  
Not all the data is in one cell, sorting would be allowed as long as the rows 
of data each stay together.
0
Utf
6/7/2010 9:34:24 PM
      If desired, send your file to my address below. I will only look if:
      1. You send a copy of this message on an inserted sheet
      2. You give me the newsgroup and the subject line
      3. You send a clear explanation of what you want
      4. You send before/after examples and expected results.


-- 
Don Guillett
Microsoft MVP Excel
SalesAid Software
dguillett@gmail.com
"Jbm" <Jbm@discussions.microsoft.com> wrote in message 
news:BAC9AF70-9077-42FE-B2AA-BCCEB45CC466@microsoft.com...
>I tried your macro, but it doesn't seem to be working...  Maybe the fact 
>that
> there are headers is screwing it up?  I've been working with your code 
> since
> you posted it, but I can't get it to work correctly (Column A has data in
> every cell until the bottom of my data set). 

0
Don
6/7/2010 9:34:44 PM
The headers would not prevent it working unless you had a blank row between 
the headers and the data, or no header in column A.  Before posting, I tested 
this (Excel 2007 Pro) on a block of data with duplicates in column X and it 
worked just fine.  And it accounts for all the conditions that appeared to 
need satisfying.  From your sample data, it seems the duplicates may not be 
listed consecutively, and you specified the first instance should be the one 
left, so re-sorting the data is likely to create problems.

If you've copied this section into a procedure that does other things as 
well, perhaps you could post the whole thing to see if there is some other 
factor causing it to fail.  You don't happen to have any protection on the 
sheet do you?


"Jbm" wrote:

> I tried your macro, but it doesn't seem to be working...  Maybe the fact that 
> there are headers is screwing it up?  I've been working with your code since 
> you posted it, but I can't get it to work correctly (Column A has data in 
> every cell until the bottom of my data set).
0
Utf
6/7/2010 10:15:39 PM
      If desired, send your file to my address below. I will only look if:
      1. You send a copy of this message on an inserted sheet
      2. You give me the newsgroup and the subject line
      3. You send a clear explanation of what you want
      4. You send before/after examples and expected results.


-- 
Don Guillett
Microsoft MVP Excel
SalesAid Software
dguillett@gmail.com
"Jbm" <Jbm@discussions.microsoft.com> wrote in message 
news:6F1418DF-9E77-4C86-B48D-094DC8132030@microsoft.com...
> Well this is deleting things, but not necessarily duplicates, and 
> oftentimes
> cells instead of rows (which means correlated data is getting thrown off).
> Not all the data is in one cell, sorting would be allowed as long as the 
> rows
> of data each stay together. 

0
Don
6/7/2010 10:23:13 PM
Reply:

Similar Artilces:

How to Recover Deleted Sent Mail?
While trying to delete very old "Sent" mail I seem to have deleted all "Sent" mail. Is there a way of recovering this mail? Have you closed Outlook since deleting the old sent mail? http://www.howto-outlook.com/howto/restoredeleteditemsfromanoutlookpst.htm might help. Next time, archive the items you want removed from your active .pst file. --� Milly Staples [MVP - Outlook] Post all replies to the group to keep the discussion intact. All unsolicited mail sent to my personal account will be deleted without reading. After furious head scratching, Sidney Friedman as...

Pivot Table row comparison
I'm trying to compare an old customer schedule with their new schedule and highlight the changes with colour or by hiding a row. My pivot table looks like this Prod Sched wk1 wk2 wk3 A old 3 2 3 A new 3 4 3 B old 2 2 2 B new 2 2 2 So in the above example I'd like to colour the cells for wk2- Product A in yellow, and hide the product B rows as there has been no change in demand. Can someone give me some advice about how to do this Thanks for your help Ross How about an alternative??? Your raw data looks kind of like this: Prod Sched wk# qty...

Cannot delete subreport
I am using Access 2003 and have a report I did a while back with a simple subreport. I want to remove the subreport but for the life of me can't figure out how to do it. Any help would be greatly appreciated. Thanks. Hi - When you say "remove the sub report", what do you mean? Do you want to delete the entire subreport control containing the subreport, or do you want to keep the control, but change the report contained in it? The first is easy - select the control by clicking once on it once, then press delete. For the second, click the control once, then set ...

Rule for Deleted Items
I am being told that there is a rule in place on my Exchange server that will not empty the deleted items folder every 30 days for certain users in my organization. I found a recipient policy in System Manager that says "Users Excluded from Mailbox Cleanup" but it only shows 2 users and not the 3 I was told about. But I have confirmed that the missing person has email in her deleted items folder going back to 2005 so it must be working. Is there any other location I should be looking? Also, we just had someone come in and migrate our Exchange environment from 2000 to a new...

I need to show the last number in a rows in the total pending row
I have a column where I list pending cases each month and I need to show the last number in the total pending cell at the bottom of the row. I can use an offset fomula which works if the pending cases begin in row 1. However, I am not able to get it to work if the pending cases begin in rows 4 or 5 as an example. Any suggestion? Rows don't have a bottom.............guess you meant Column. Last number in column A =LOOKUP(99^99,A:A) Last anything in column A =LOOKUP(2,1/(A1:A65535<>""),A1:A65535) Gord Dibben MS Excel MVP On Wed, 28 Jan 2009 16:30:08 -0800, Jen S ...

number of rows #2
I used autoformat so that my rows would alternate colors. But, it added a bunch of empty rows so that the sheet is maxed out and my file is huge. I don't need all those empty rows and I can't find a way to delete them. Any suggestions for how to get rid of the rows, or limit the number of rows on a worksheet? I know I could copy all the data to a new worksheet, but I'd like a better solution. Try this: click on the number of the first empty row, so the whole row is selected. Using the vertical scrollbar, go to the last row on the sheet. Hold down the shift key while you cli...

cannot delete message from deleted items
I have a message in my deleted items folder that when choosing delete opens the McAfee box warning of potential virus and wants me to choose open or do not open, but will not delete. I have tried choosing another file and holding ctrl and choosing the file I want deleted and then choosing delete, I have tried moving it to the desktop but it will only copy there, I have tried every form of delete possible. I need help. Anyone know how? Outlook 2002. Can you empty the deleted items folder entirely? Or turn off the McAfee scanning temporarily to see if it makes a difference? Julie wr...

I can not delete a duplicate personal folders list #2
Vall... amazing that there isn't an easy fix for this. The instructions provided simply don't work ( tools-email accounts-view change email accounts-deliver to new account-finish-close outlook and reopen ), and none of the other offered explanations have worked either. As this is such a common problem; why hasn't microsoft provided a very EASY fix? I am more confused ( and frightened ) and don't want to make the problem worse! Your profile is corrupt, probably based on an incorrect migration of your ..pst file. Create a new mail profile and configure it to use your exi...

Retrieval of Deleted Items After Being Deleted from the Deleted Items File
I deleted a number of important emails from the deleted items file in Outlook 2000. This may sound stupid, but I completely emptied the deleted items file instead of deleting them one by one. Pretty stupid, huh. Anyone. Can they be retrieved? Please help. Thanks. Sorry for sending this again but I seem to be computer illiterate and it has taken me some time to explain the whole situation. Thanks again. unless you use Exchange server with deleted retention enabled, you are most likely out of luck, but you can try something that might help.... http://www.outlook-tips.net/howto/r...

Delete macros
I am using Excel 2002. When I click on Tools->Macro->Macros... i see 2 macros. The problem I am having is that I can't delete these macros, the delete button to the right is grayed out. How can I delete these macros? Hi maybe the macros are protected. Try hitting ALT + F11 to open the VBA editor and try to delete the macros / modules there -- Regards Frank Kabel Frankfurt, Germany excel777 wrote: > I am using Excel 2002. When I click on Tools->Macro->Macros... i see > 2 macros. The problem I am having is that I can't delete these > macros, the delete button to ...

deleting email in outlook, freezes before i can delete
i have a file with pics that symetec scanner says is to large. i can receieve email but cannot send any. it freezes before i can delete and says non responding. Hi All, I want to re-raise the old issue of Fax numbers showing up in the Outlook Address book when one is sending an email. I know that this can be stopped by prepending the Contact's fax number with a letter so that Outlook doesn't see it as a valid fax number and therefore doesn't list it. What's always puzzled me, however, is that this fix doesn't work if the fax numbers are changed using an export to CSV...

Locate a specific row or column
Hi all, Could you tell me how to locate a specific row instead of using Mouse to dray the scroll bar? Clara thank you so much for your help In VBA code, you can use: Range("D100").Activate ' Or Range("D1:D100").Select ' Depending on if you want only one cell highlighted or a range of cells. -- Best wishes, Jim "clara" wrote: > Hi all, > > Could you tell me how to locate a specific row instead of using Mouse to > dray the scroll bar? > > Clara > > thank you so much for your help Hi Clara Have you tried goto in the Ed...

Re: Ranking my results in a query to get the TOP#10 percent
Hello, I have created several queries and now I would like to rank my result to only get the TOP 10 percent. Could you please assist me with an Access SQL statement that can accomplish this? Thanks, TL SELECT TOP 10 PERCENT * FROM somewhere ORDER BY someExpression It is not a 'rank' in itself, though, just a pick of the 'top most'. Light difference between the two expressions, but it probably does not matter... :-) Vanderghast, Access MVP "TL" <TL@discussions.microsoft.com> wrote in message news:E6549C8D-9FDC-4568-B73F-434BAF601BD7@mi...

OK to delete Deleted Items folder?
I'm afraid I'll have to delete my Deleted Items folder in Outlook 2000. When I try to empty the folder I get a "The messaging interfce has returned an unknown error. If the problem persists Restart Outlook" message. Is it possible to delete the entire folder and replace it with an empty new one? Will it create any problems? TIA Henrik Not possible. Run scanpst.exe against your pst-file to scan it for errors first. -- Robert Sparnaaij [MVP-Outlook] www.howto-outlook.com Tips of the month: -What do the Outlook Icons Mean? -Create an Office 2003 CD slipstreamed with Se...

How to delete chart
I created a histogram and want to delete it. I select it and the faint double border apperars. There are no square handles like in 2003. Then I press the Delete key. The faint double border goes away replaced by a single thin black border. The chart is still there and is not able to be selected at all. I entered "delete chart" in the Excel Help window, and there was nothing at all on deleting a chart. Ditto for "remove chart." I got no help searching on the internet either. I have Excel 2007 and Windows XP Professional When the border changes, can you press Delete a...

Delete blank Last page
In a word document where the last page is blank due to editing or whatnot, how do you get rid of the frigg' thing. This is a Visio newsgroup - your question was about Word. However, I have had this problem as you have. Narrowing the margins and line spacing on the page previous to the last may get rid of this annoying "blank" page for you. - Jeff Chapman "silkies" <silkies@discussions.microsoft.com> wrote in message news:BDCC1FF1-50D0-42CE-BA84-868CB26A43AC@microsoft.com... > In a word document where the last page is blank due to editing or > whatnot...

Having trouble with extra rows at the bottom of the doc
How do I delete the extra rows at the bottom of a doc. I have inherited a document that has 60 rows of data and 3682 rows of empty cells that have the boarder set. When I select and delete them, new ones reappear. I have turned the cell boards off and it still creates empty cells with the boarder. Is there any way to delete these rows? -ken Ken, Are you selecting and then deleting and then saving? HTH, Andy Ken Excel has a habit of retaining "used" cells way beyond where you are currently working. On a worksheet hit CRTL + END to see where you wind up. If far below and...

Deleting an email
I have an email (with a file attached) that is "hung up" in my outbox of Microsoft Outlook. Now I can't send or receive emails in Outlook. How can I delete the email that is "hung up"? Define hung up. Is it trying to send it? If so, disconnect your connection while it's trying to send and wait. It will time out after a bit and you should be able to delete it. Reconnect. "Aaron Hurliman" <AaronLHurliman@aol.com> wrote in message news:03b001c34f39$0fb61ff0$a301280a@phx.gbl... > I have an email (with a file attached) that is "hung up&q...

Recovering Unrecoverable Deleted Public Folders
Long, sad story with a punch line (which is worth getting to): Exchange 2003. Ran into a situation where a user deleted 10 public folders by mistake. Using Recover Deleted Items to retrieve them, got back five of the folders (the ones that were empty in the first place) but we received the following error message when attempting to recover the other five (the ones with actual stuff in them): "Outlook was unable to recover some or all of the items in this folder. Make sure you have the required permissions to recover items in this folder and try again. If the problem persists contact you...

Integration Manager 10.0 error message
Would anyone know the cause if this error? This fixed assets integration ran with no problem last month. "Integration < > is not ready to run due to the following problems: Source queries are not ready to execute. Query < > cannot be executed until the following problem is corrected:" ------ and nothing is listed! Thanks for any help offerred. Are you able to right click on the source and preview? You may have to remap the source file. Thanks, VJ On Nov 3, 10:57=A0am, Patti <Pa...@discussions.microsoft.com> wrote: > Would anyone know the cause if t...

How do I delete a message in my outbox that contains a large file
I tried to send an email containing a large enclosure. Too large to send and now the message is stuck in my outbox. How do I delete the message? I have tried the normal route - cut, delete, but it stays in the outbox and slows down my send/receive capabilities "Lillian" <Lillian@discussions.microsoft.com> wrote in message news:C11E7BA3-C410-48CC-8B15-F6EA284665E7@microsoft.com... > I tried to send an email containing a large enclosure. Too large to send > and > now the message is stuck in my outbox. How do I delete the message? I > have >...

#Deleted
Have a rown in a table that contains the value '#Deleted' in every field. Want to actually delete this row from the table. Tried to delete, it appears that the row is deleted, I exit the table then open the table back up, and the row still exists with the value '#Deleted'. Tried to Compact and Repair.... Still receiveing the same result. How can I remove this row from the table????? The trick is to replace the table with another table populated the *other* records in your bad table. Details: Recovering from corruption: Some table rows show #Deleted at: http:...

Duplicate messages
Hi, I've followed a few of the posts relating to duplicate messages being downloaded in Outlook XP. I have a similar problem, but am not sure it is the same: I have 4 different email accounts with on 4 different POP3 servers. These accounts are also web accessible (so I can check them at work etc). I use a cable broadband connection and all 4 accounts use my ISPs outgoing mail server to send. So that messages are accessible however I access the accounts, Outlook is set not to delete them from the server. I am receiving multiple copies of some, but crucially not all, of my messages. ...

Can I delete this from ADSI?
Hi all, I am upgrating Exchange 2K to Exchange 2K3 and removed the Mobile information Server (which we never used it). But, I can see the CN=Microsoft-Mobile-Information-Server under configuration -->Services from ADSIedit. Can I safely delete this? or If I do not delete this, wii it have any issue with exchange 2003 mobile? Thanks! Exchange Server 2003 mobility features do not rely on that. Saving a LDIF dump may be a good idea before you delete - this provides ability to recreate the object if required. -- Bharat Suneja MVP - Exchange www.zenprise.com NEW blog location: www.e...

outlook deletes inbox mail
On about three occaisions, my computer has restarted itself while Outlook Express, and sometimes other applications have been open, without my prompting it to do so. Upon rebooting, my Outlook inbox messages are completely wiped out, however, my sent folders and deleted messages, address book, ect. remain the same, and with no data lost. Can someone tell me what has happened, or perhaps how I can recover these lost emails? Any help would be greatly appreciated. Thank you, C.C. Outlook or Outlook Express? If Outlook Express and you search your drive (use advanced option for hidden f...