+ Reply to Thread
Results 1 to 12 of 12

Delete a row based on condition

  1. #1
    Forum Contributor vijay2482's Avatar
    Join Date
    03-03-2009
    Location
    Paris,France
    MS-Off Ver
    Excel 2003
    Posts
    263

    Delete a row based on condition

    Hi all,
    Thanks to all those who help in the past.

    I want to delete a row in excel based on a condition.
    The condition is as follows:
    I have few rows in the excel where the columns 7,12,13,23 are same and column 24 in one row has some number and in some other row the column 24 is blank with orange color filled(the colorindex for orange is 44).
    In this case I want the row with orange color filled in column 24 to be deleted.

    Have attached a sample sheet.

    Any help on this will be helpful.
    Thanks in Advance.
    Attached Files Attached Files
    Last edited by vijay2482; 12-16-2009 at 05:14 AM.
    VIjay

    If you find any of the post useful to your question, please add to the contributor's reputation by clicking the blue scales icon in the blue bar of the post.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Delete a row based on condition

    So in your example sheet, the only row to delete would be row 11 based on X11 being orange colored and empty?

    Please Login or Register  to view this content.
    Last edited by JBeaucaire; 12-14-2009 at 01:09 PM.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Forum Contributor vijay2482's Avatar
    Join Date
    03-03-2009
    Location
    Paris,France
    MS-Off Ver
    Excel 2003
    Posts
    263

    Re: Delete a row based on condition

    Thanks JBeaucaire.
    Will execute the macro and get back to you soon.

    Thanks once again.

  4. #4
    Forum Contributor vijay2482's Avatar
    Join Date
    03-03-2009
    Location
    Paris,France
    MS-Off Ver
    Excel 2003
    Posts
    263

    Re: Delete a row based on condition

    Hi JBeaucaire,

    Thanks a lot.
    The code did exactly what I wanted.
    But I want the other column values( 7,12,13,23) same in the rows. and only column 24 to be orange and blank.
    The above code does not check if all the other columns a same.

    Any help on it will be helpfull.
    Thanks in Advance.
    Last edited by vijay2482; 12-15-2009 at 10:29 AM.

  5. #5
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Delete a row based on condition

    I don't actually understand that last part.

    Explain further by pointing to your sheet and an example of a row that should be deleted and why. Be specific with your cell references, sometimes I'm dense.

  6. #6
    Forum Contributor vijay2482's Avatar
    Join Date
    03-03-2009
    Location
    Paris,France
    MS-Off Ver
    Excel 2003
    Posts
    263

    Re: Delete a row based on condition

    In my sample wookbook, the rows 6 and 11 has same values in columns 7,12,13,23 and column 24 has 07 in row 6 and has orange color filled without value in row 11.
    Hence the row 11 has to be deleted.
    Since the other columns are similar in rows 6 and 11 and the column 24 has orange filled with blank value in row 11, that row has to be deleted.

    Have attached the sample workbook.
    Thanks in Advance.
    Attached Files Attached Files

  7. #7
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Delete a row based on condition

    I'm going to refer to columns by their letters, not their numbers, since that confuses the heck out me.

    So you want all the values in G5 & L5 & M5 & W5 as a group compared to ALL the other "groups" of values from the same columns...then if their is a duplicate "set", delete the entire row if X5 is orange?

  8. #8
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Delete a row based on condition

    Here's an adjusted version of my original macro. This actually should evaluate much faster on large datasets since we are no longer checking every single row for the orange color, only ones that are flagged to be checked by the duplication key I'm creating in column CC.

    Please Login or Register  to view this content.
    Last edited by JBeaucaire; 12-16-2009 at 04:53 AM.

  9. #9
    Forum Contributor vijay2482's Avatar
    Join Date
    03-03-2009
    Location
    Paris,France
    MS-Off Ver
    Excel 2003
    Posts
    263

    Re: Delete a row based on condition

    Thanks for this version of code.
    I executed the code, I got a run time error 1004, Method 'Range' of Object '_Global' failed.
    in the below line:
    Please Login or Register  to view this content.
    I dont understand the cause of this error message.

  10. #10
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Delete a row based on condition

    Quote Originally Posted by vijay2482 View Post
    I dont understand the cause of this error message.
    Hehe, you should. There's no such thing as ** in a range reference.

    The forum is corrupting my post above. I've tried to fix it twice and it keeps putting ** all through the code. Very odd.

    I'll try to post it here:
    Please Login or Register  to view this content.
    Last edited by JBeaucaire; 12-16-2009 at 01:25 PM. Reason: HD to change all the ** references to CE to stop the ** changes

  11. #11
    Forum Contributor vijay2482's Avatar
    Join Date
    03-03-2009
    Location
    Paris,France
    MS-Off Ver
    Excel 2003
    Posts
    263

    Re: Delete a row based on condition

    JBeaucaire,

    I get the same error in the below line:
    Please Login or Register  to view this content.
    There is "**" in this line.
    Last edited by vijay2482; 12-16-2009 at 05:13 AM.

  12. #12
    Forum Contributor vijay2482's Avatar
    Join Date
    03-03-2009
    Location
    Paris,France
    MS-Off Ver
    Excel 2003
    Posts
    263

    Re: Delete a row based on condition

    Have changed "**" to "CE".
    Now it works fine.
    Thanks a lot for your kind help.

+ 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