+ Reply to Thread
Results 1 to 14 of 14

Delete Multiple Rows based on Criteria

  1. #1
    Registered User
    Join Date
    06-12-2013
    Location
    Rochester, Minnesota
    MS-Off Ver
    Excel 2007
    Posts
    80

    Delete Multiple Rows based on Criteria

    Hello,

    Have an interesting question today:

    I have a spreadsheet containing several thousand rows.

    My column headers are: Group Number, Field Name, and Value.

    I am looking to delete all rows if Value Column = 4 or 7.

    So if Group 1 has a Value of 4 and/or 5, Then delete all Group 1.
    Group 2 does not have a value of 1 or 2 so it is fine.
    Group 3 has a value of 4 so delete all Group 3 rows.

    Any thoughts?

    Thanks
    Attached Files Attached Files

  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 Multiple Rows based on Criteria

    Try this:

    Please Login or Register  to view this content.
    _________________
    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
    Registered User
    Join Date
    06-12-2013
    Location
    Rochester, Minnesota
    MS-Off Ver
    Excel 2007
    Posts
    80

    Re: Delete Multiple Rows based on Criteria

    THANK YOU! This totally worked for the sample but I am having problems adapting it to my real life data that I cannot show on here.

    Would you be willing to walk me through each step?

  4. #4
    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 Multiple Rows based on Criteria

    It's putting formulas in columns D and E.

    Comment out the last 3 lines of code, then run it, you will see the formulas entered. Perhaps you can edit them. To get the new syntax after you've edited the formulas as needed, turn on the macro recorder and edit/enter in D2 and E2, then turn off the recorder. That will give you the syntax of those formulas in VBA.

  5. #5
    Registered User
    Join Date
    06-12-2013
    Location
    Rochester, Minnesota
    MS-Off Ver
    Excel 2007
    Posts
    80

    Re: Delete Multiple Rows based on Criteria

    Ok, I've been fiddling around and can't seem to get it.

    What if we changed Group ID from a single digit to a string of digits:

    35701224
    35701224
    35701224
    35701224
    39162952
    25269192
    91116622
    91116622
    91116622

  6. #6
    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 Multiple Rows based on Criteria

    Should work identically.

  7. #7
    Registered User
    Join Date
    06-12-2013
    Location
    Rochester, Minnesota
    MS-Off Ver
    Excel 2007
    Posts
    80

    Re: Delete Multiple Rows based on Criteria

    In the real sheet it deletes all rows but the header.

  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 Multiple Rows based on Criteria

    OK, let's see an small example set of that actual sheet along with your edited version of the macro.

  9. #9
    Registered User
    Join Date
    06-12-2013
    Location
    Rochester, Minnesota
    MS-Off Ver
    Excel 2007
    Posts
    80

    Re: Delete Multiple Rows based on Criteria

    Here you go. Thanks very much for your help.
    Attached Files Attached Files

  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 Multiple Rows based on Criteria

    Please Login or Register  to view this content.

    We've moved the "activity" out to columns Y:Z since D:E are not empty.

  11. #11
    Registered User
    Join Date
    06-12-2013
    Location
    Rochester, Minnesota
    MS-Off Ver
    Excel 2007
    Posts
    80

    Re: Delete Multiple Rows based on Criteria

    Still deleting all columns/rows upon migrating to "real" sheet. I wonder if the size of the size of the sheet matters? The real sheet is several thousand rows long..

  12. #12
    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 Multiple Rows based on Criteria

    No, shouldn't matter.

  13. #13
    Registered User
    Join Date
    06-12-2013
    Location
    Rochester, Minnesota
    MS-Off Ver
    Excel 2007
    Posts
    80

    Re: Delete Multiple Rows based on Criteria

    I know this is frustrating but any ideas as to what might be happening then?

  14. #14
    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 Multiple Rows based on Criteria

    No, the macro is pretty simple based on your requirements. The results are clearly setting every group to "delete", so something in your data doesn't match your samples so far. Zip up the real file with a password and post it, then PM me the password, I'll see what's going on in the real file.

+ 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