+ Reply to Thread
Results 1 to 11 of 11

identifying rows to delete based on multiple conditions

  1. #1
    Registered User
    Join Date
    05-21-2014
    Posts
    59

    Angry identifying rows to delete based on multiple conditions

    Maybe this has been taken care of in another thread, but still:

    ROW ID NUM OCC K OCC I
    1 222222 0 0
    2 222222 0 0
    3
    4 333333 0 0
    5 333333 0 0
    6 333333 0 0
    7
    8 444455 1 1
    9 444455 1 1

    I have a situation like above, but what I want to do is:

    =FOR(ROW1:ROW9, IF COUNT ROWS(ID_NUM)>= 2,

    (create name for set?)

    AND

    IF OCC_K AND OR OCC_I VALUES >= 0,

    THEN DELETE ROWS(within set) >=2

    Or more simply:

    If there are rows with multiple Accident ID numbers, name that set,
    and if OCC_K and/or OCC_K values are BOTH >= 0,
    then delete all duplicate rows?

    Yes I figure there needs to be some way to distinguish Row 1 from Row 2, (flagging one of the two?) so that ROW 2 can be identified, and similarly with Row 4 from Row 5 from Row 6, but the general flow of commands is what I'm trying to get at.

    Is it also possible to use AND and OR in the same line? Or BOTH?

    (I have other variations on this that I also like to ask about, such as multiple rows within a set that meet certain conditions that are identified in a different field, but for now this is a simpler version.)

    I would like to think I'm not going to need a macro, and that I can do this in a Formula.

    Thanks kindly,

    Dan B

  2. #2
    Valued Forum Contributor ranman256's Avatar
    Join Date
    07-29-2012
    Location
    Kentucky
    MS-Off Ver
    Excel 2003
    Posts
    1,177

    Re: identifying rows to delete based on multiple conditions

    You have to delete rows backwards or the rowcount screws up...
    use:
    Please Login or Register  to view this content.

  3. #3
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: identifying rows to delete based on multiple conditions

    Hi

    I find that a little difficult to follow. Would you upload the workbook so that we can see the request in context. Paint the rows you want to delete with a specific colour and add some notes explaining how you have selected them.

    A formula can't delete rows, in fact it can't DO anything other than tell you something. If you want to delete them without VBA you will need to manually delete them, which you can simplify somewhat by filtering them first.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  4. #4
    Registered User
    Join Date
    05-21-2014
    Posts
    59

    Re: identifying rows to delete based on multiple conditions

    Ranman256:

    Thank you for getting back to me so quickly, but until I hear otherwise, I don't know if I can use a VBA macro or script.

    I also don't know what you mean by "delete rows backwards or row count screws up?" I should mention as well that the files I am working with have blank rows between each set of duplicates. Should I delete all the blank rows or can something like what you are posting work on what I've got?

    I can tell you that the Range is the number of rows with the same ACC ID (i.e., the number of duplicates). Would this help?


    Dan

  5. #5
    Registered User
    Join Date
    05-21-2014
    Posts
    59

    Re: identifying rows to delete based on multiple conditions

    I've attached a basic spreadsheet.

    For background:

    The database covers Traffic Accidents. The Severity of the Accident needs to be determined first (click on cell E2 for the formula that in part determines the severity).
    For my sake:

    IF the there is a duplicate set (2 records or more) of values (i.e. 0 or more killed and 0 or more injured), like what I showed in my initial post, then what I want to do is delete the second record, and if there are more than 2 records, delete all other records if they have the same values (i.e., 2 or more other sets of 0 killed 0 injured).

    I will clarify more soon.

    Dan B

  6. #6
    Registered User
    Join Date
    05-21-2014
    Posts
    59

    Re: identifying rows to delete based on multiple conditions

    Sorry. Here is the database. Will clarify more if needbe on Friday PST in U.S.

    Dan B
    Attached Files Attached Files

  7. #7
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,939

    Re: identifying rows to delete based on multiple conditions

    Put this in a helper column and copy down...
    =COUNTIFS($A$2:$A2,A2,$B$2:$B2,B2,$C$2:$C2,C2)

    Then, apply filters, filter on everything less than 2 (uncheck 0 and 1), then delete all that show
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  8. #8
    Valued Forum Contributor ranman256's Avatar
    Join Date
    07-29-2012
    Location
    Kentucky
    MS-Off Ver
    Excel 2003
    Posts
    1,177

    Re: identifying rows to delete based on multiple conditions

    Sorry, i was deleting the rows. You just wanted to paint them. So going backwards is irrelevant.

  9. #9
    Registered User
    Join Date
    05-21-2014
    Posts
    59

    Re: identifying rows to delete based on multiple conditions

    FDibbins,

    Thank you kindly for your efforts; this was helpful (with a small tweaking--for now, my supervisor just wants to know What to Do when we have 2 or more sets of 0,0). When I selected all the sets that have 2 or more 0,0 and copied them over to another Sheet, if I unchecked everything not = 1, I got exactly what I was looking for.

    I will say that on the main sheet, when I dragged your formula all the way down, I saw the Green Triangle pop up in the corner of a good number of cells, which then led to a message of "The formula in this cell refers to a range that has additional numbers adjacent to it."

    When I did the same thing with the sheet of just the sets of 0,0, I didn't have this problem.

    Anyhow I have a sense this might work.
    Attached Files Attached Files

  10. #10
    Registered User
    Join Date
    05-21-2014
    Posts
    59

    Question Re: identifying rows to delete based on multiple conditions

    FDibbins,

    For starters, your formula works well, but there is a problem. See the attached file with the comments.

    Yes I admit I probably should have put in the basic scenario that I have at the top, because this helps clarify which ACC_NUM out of the set of duplicates to keep, but what I am wondering about mainly is if there is a way of extending the formula that you have to a situation like:

    after unchecking everything = 0 or > 1, if there are two ACC_NUM records = 1, which one to delete?

    Or: is there a way to have the formula you have linked to the SEVERITY scenario on top? Can I have "1"s (in text format) be treated in the same way as numbers would be?

    For example with 3548948, both 2-1 and 2-0 will make it a K, but is there a way to have the formula compare one of the 2-1s vs the 2-0?

    Dan
    Attached Images Attached Images

  11. #11
    Registered User
    Join Date
    05-21-2014
    Posts
    59

    Re: identifying rows to delete based on multiple conditions

    FDibbins,

    Even if we correct this error, it still may not give me the end result I want, but at the same time, why is it I am getting an error of some kind (little green triangle) for certain records and not others after I copy-paste your formula?

    What would you think is causing this?

    Dan

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Delete rows with multiple conditions
    By kishoremcp in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-22-2013, 03:41 PM
  2. [SOLVED] VBA code to delete duplicate rows based on multiple conditions
    By pjsween in forum Excel General
    Replies: 5
    Last Post: 06-27-2012, 01:15 PM
  3. delete row based on multiple conditions
    By nervous_pilchard in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 10-24-2011, 09:59 AM
  4. Delete Rows Based on Two Conditions
    By ExcelGuy160 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 09-20-2010, 02:44 PM
  5. Delete rows, multiple conditions
    By rm7302 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 07-22-2009, 08:28 AM

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.6.0 RC 1