+ Reply to Thread
Results 1 to 4 of 4

Thread: Compare cells and delete row if they are not the same

  1. #1
    Registered User
    Join Date
    12-17-2008
    Location
    edinburgh, uk
    Posts
    46

    Compare cells and delete row if they are not the same

    Hi,
    I need a macro to compare two cells in a row and delete the row if the cells are not the same. Not sure how to do this?

    Thanks in advance

  2. #2
    Forum Guru
    Join Date
    11-23-2005
    Location
    Rome
    MS-Off Ver
    Ms Office 2003
    Posts
    1,241

    Re: Compare cells and delete row if they are not the same

    You can try with this code (in this example I work for rows 2 to 100 and I use column "a" and "b"):
    For r = 2 to 100
       If cells(r,"a") <> cells(r,"b") then
          rows(r).delete
       End If
    Next r
    Regards,
    Antonio

  3. #3
    Registered User
    Join Date
    12-17-2008
    Location
    edinburgh, uk
    Posts
    46

    Re: Compare cells and delete row if they are not the same

    Thanks for that- I've got about 20000 rows and it takes ages to go through them all. any way of speeding it up a bit?

    Cheers

  4. #4
    Registered User
    Join Date
    12-17-2008
    Location
    edinburgh, uk
    Posts
    46

    Re: Compare cells and delete row if they are not the same

    An update on this:

    What i think i need is to go through only the range used in the worksheet and delete the row if two cells are the same value.

    The reason for this is that the length of the spreadsheet will vary from time to time.

    Thanks

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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.2.0