+ Reply to Thread
Results 1 to 12 of 12

If Column A = Value & Column B = Value in Same Row THEN Delete Row

  1. #1
    Registered User
    Join Date
    06-27-2011
    Location
    Austin, TX
    MS-Off Ver
    Excel 2007
    Posts
    26

    If Column A = Value & Column B = Value in Same Row THEN Delete Row

    Hello Everyone,

    I'm looking to search all rows within a sheet for one value in Column A, and then when it finds that value, identify the rows that have a second value in Column B as well. Once that is found, delete the row.

    For example,

    A B
    22222 111
    22222 222
    22222 333

    Find the row that has 22222 is column A & 222 in column B, and delete this row. If you can please help me make the code using this 22222 222 combo as an example, I can edit the numbers for a few exceptions I need it for.

    Thanks!
    Last edited by perdooky; 01-12-2012 at 06:01 PM.

  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,259

    Re: If Column A = Value & Column B = Value in Same Row THEN Delete Row

    Hello perdooky,

    This macro will delete any row whose value in cell "A" matches 22222 and the adjacent cell in column "B" is part of the cell in "A".
    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!)

  3. #3
    Registered User
    Join Date
    06-27-2011
    Location
    Austin, TX
    MS-Off Ver
    Excel 2007
    Posts
    26

    Re: If Column A = Value & Column B = Value in Same Row THEN Delete Row

    It looks like this macro is not working for the actual numbers I need to use it for. I should have just told from the beginning, I need this to run through a spreadsheet of data for these three combinations in Column A & B:

    10083 & 4800
    10346 & 4800
    10153 & 4800

    Thanks for your help already. It looks like this is almost what I need, but I may have messed up by telling you the data in column B was 3 digits. It will always be a 5 digit number in column A and 4 digit number in column B. Thanks for your help so far!

  4. #4
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: If Column A = Value & Column B = Value in Same Row THEN Delete Row

    So, if column A = 10083 or 10346 or 10153 and column B = 4800 then delete the row?
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  5. #5
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: If Column A = Value & Column B = Value in Same Row THEN Delete Row

    just use advanced filter and delete the rows found click data/filter /advanced to see criteria, saves all this macro malarkey! or for multiple see advanced mult
    Attached Files Attached Files
    Last edited by martindwilson; 01-10-2012 at 07:04 PM.
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  6. #6
    Registered User
    Join Date
    06-27-2011
    Location
    Austin, TX
    MS-Off Ver
    Excel 2007
    Posts
    26

    Re: If Column A = Value & Column B = Value in Same Row THEN Delete Row

    Tiger, correct. But I would hopefully want the solution to be open to different numbers in column B other than 4800.

    Martin, correct me if I'm wrong, but isn't that filter doing the opposite of what I want? I need to delete only those three combinations, not delete everything but.

    Thanks everyone.

  7. #7
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: If Column A = Value & Column B = Value in Same Row THEN Delete Row

    hmm i cant see how,if they show up just delete the rest will be left intact

  8. #8
    Registered User
    Join Date
    06-27-2011
    Location
    Austin, TX
    MS-Off Ver
    Excel 2007
    Posts
    26

    Re: If Column A = Value & Column B = Value in Same Row THEN Delete Row

    Still looking for a solution, thanks.

  9. #9
    Registered User
    Join Date
    01-15-2010
    Location
    VA, USA
    MS-Off Ver
    Excel 2003
    Posts
    26

    Re: If Column A = Value & Column B = Value in Same Row THEN Delete Row

    I think you need to elaborate on exactly the criteria for a delete if you cannot adjust the code provided above. If it is constantly changing criteria you may want to name a range and keep that up to date and use that as the criteria for a delete. Unsure until I have some more information.

  10. #10
    Registered User
    Join Date
    06-27-2011
    Location
    Austin, TX
    MS-Off Ver
    Excel 2007
    Posts
    26

    Re: If Column A = Value & Column B = Value in Same Row THEN Delete Row

    Quote Originally Posted by vthokie2010 View Post
    I think you need to elaborate on exactly the criteria for a delete if you cannot adjust the code provided above. If it is constantly changing criteria you may want to name a range and keep that up to date and use that as the criteria for a delete. Unsure until I have some more information.
    If you read above I mention that the code provided does not work with the actual 3 combinations I need that will be in Column A & B (so I can't adjust the code):

    10083 & 4800
    10346 & 4800
    10153 & 4800

    I need it to search columns A & B, and delete the lines that match that criteria.

    I took the code, replaced 22222 & 222 with 10083 & 4800, and it doesn't delete the line. I'd be curious to find out why it works with one set of numbers and not another.

  11. #11
    Registered User
    Join Date
    01-15-2010
    Location
    VA, USA
    MS-Off Ver
    Excel 2003
    Posts
    26

    Re: If Column A = Value & Column B = Value in Same Row THEN Delete Row

    Here is your new code. The problem had to do with starting from row 1 as opposed to the last row. Since you might delete rows during the for each block it skips cells because of how it changes the row number after the delete.


    Please Login or Register  to view this content.
    Last edited by vthokie2010; 01-12-2012 at 04:29 PM.

  12. #12
    Registered User
    Join Date
    06-27-2011
    Location
    Austin, TX
    MS-Off Ver
    Excel 2007
    Posts
    26

    Re: If Column A = Value & Column B = Value in Same Row THEN Delete Row

    Thanks for the tweak, this work great!

+ 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