+ Reply to Thread
Results 1 to 2 of 2

Compare cells and delete

  1. #1
    Registered User
    Join Date
    05-27-2010
    Location
    Norway
    MS-Off Ver
    Excel 2003
    Posts
    1

    Compare cells and delete

    Hi,
    I have a worksheet with many rows and in column D I have different values/text in each cell (no blanks). The first 20 rows have a certain value/text and the next 34 have another certain value/text and so on and so on. (i.e. 20 ab's and 34 qx's)
    What I want is to only keep one of the lines for each value/text.

    My thought was to compare the cell D1 with D2 and if they were the same then delete entire row of D2 and then continue with D1 and D3 and so on until the end and then continue with comparing D2 and D3...... The script I wrote was:
    Please Login or Register  to view this content.
    But this script leaves 5 of each line, and I don't understand why.
    Can anyone help?

    If you have a better way of solving this it will be greatly appreciated. (Total number of rows is 5000)
    W
    Last edited by Leith Ross; 05-27-2010 at 07:50 PM. Reason: Added Code Tags

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Compare cells and delete

    Hello whitebalance,

    There a several methods you can use to do this. This macro uses the Dictionary object to store only the unique entries. Any duplicates will have the entire row cleared. Afterward, the remaining data is sorted in ascending order to remove the blank rows.
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1