+ Reply to Thread
Results 1 to 32 of 32

Delete all occurrences when parameter has been met.

  1. #1
    Forum Contributor
    Join Date
    06-17-2010
    Location
    Donemana, NI
    MS-Off Ver
    Excel 2007
    Posts
    386

    Delete all occurrences when parameter has been met.

    Hi,
    I am looking code that will delete all occurrences of a record "Key Field" in column "E" if the anyone of the following parameters are in column "A", "D51", "D54", "D55", "D56", "D58", Can anyone help me with this?
    Thanks
    in advance.
    Johnny
    Attached Files Attached Files
    Last edited by Burt_100; 09-30-2016 at 04:22 AM.

  2. #2
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,815

    Re: Delete all occurrences when parameter has been met.

    Try this macro on a copy of your file:
    Please Login or Register  to view this content.
    You can say "THANK YOU" for help received by clicking the Star symbol at the bottom left of the helper's post.
    Practice makes perfect. I'm very far from perfect so I'm still practising.

  3. #3
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,523

    Re: Delete all occurrences when parameter has been met.

    Burt_100,

    xl2007 should accepts array criteria.
    Please Login or Register  to view this content.

  4. #4
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,815

    Re: Delete all occurrences when parameter has been met.

    Hello jindon. That's a very interesting approach. Would you mind explaining how the ".Offset(1).ClearContents" works? How does the macro delete only the visible cells?

  5. #5
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,523

    Re: Delete all occurrences when parameter has been met.

    When the range is filtered, the range only refer to visible rows, so offset(1) will exclude header row.
    Help?

  6. #6
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,815

    Re: Delete all occurrences when parameter has been met.

    That is very helpful. Thank you. In the macro I suggested, I used
    Please Login or Register  to view this content.
    It looks like
    Please Login or Register  to view this content.
    would also work without referring to the visible cells. I suppose that this would work on any action you want to perform on the visible range, for example
    Please Login or Register  to view this content.
    or
    Please Login or Register  to view this content.
    Is this true?

  7. #7
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,523

    Re: Delete all occurrences when parameter has been met.

    That's correct, only when filtered.

  8. #8
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,815

    Re: Delete all occurrences when parameter has been met.

    Thank you so much for all your help and patience. It was very helpful.

  9. #9
    Forum Contributor
    Join Date
    06-17-2010
    Location
    Donemana, NI
    MS-Off Ver
    Excel 2007
    Posts
    386

    Re: Delete all occurrences when parameter has been met.

    Thanks for your help but the code only seams to delete a few of the entries and not all of them?

  10. #10
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,815

    Re: Delete all occurrences when parameter has been met.

    I have tried my macro and the one jindon suggested on your sample file and both macros seemed to work properly.

  11. #11
    Forum Contributor
    Join Date
    06-17-2010
    Location
    Donemana, NI
    MS-Off Ver
    Excel 2007
    Posts
    386

    Re: Delete all occurrences when parameter has been met.

    They work but they don't delete all instances for some reason even when I download the example file I uploaded and copied the macro in

  12. #12
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,815

    Re: Delete all occurrences when parameter has been met.

    Can you attach a copy of the file that is not working properly. Highlight in red the instances that are not deleted after running the macro.

  13. #13
    Forum Contributor
    Join Date
    06-17-2010
    Location
    Donemana, NI
    MS-Off Ver
    Excel 2007
    Posts
    386

    Re: Delete all occurrences when parameter has been met.

    Hi,
    See attached file as requested filename; "Example2".
    Many Thanks
    Johnny
    Attached Files Attached Files

  14. #14
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,815

    Re: Delete all occurrences when parameter has been met.

    In your original post you asked to
    delete all occurrences of a record "Key Field" in column "E" if the anyone of the following parameters are in column "A", "D51", "D54", "D55", "D56", "D58"
    . The macro does exactly that. The file you posted has no data in column E where column A contains "D51", "D54", "D55", "D56", "D58".

  15. #15
    Forum Contributor
    Join Date
    06-17-2010
    Location
    Donemana, NI
    MS-Off Ver
    Excel 2007
    Posts
    386

    Re: Delete all occurrences when parameter has been met.

    Quote Originally Posted by Mumps1 View Post
    In your original post you asked to. The macro does exactly that. The file you posted has no data in column E where column A contains "D51", "D54", "D55", "D56", "D58".
    Sorry I understand the confusion now, I need the entire row deleted not just the key field in column "E", sorry its totally my fault for not being clear.

  16. #16
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: Delete all occurrences when parameter has been met.

    How does this work for you?
    Please Login or Register  to view this content.
    Last edited by bakerman2; 10-04-2016 at 06:42 AM.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  17. #17
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,815

    Re: Delete all occurrences when parameter has been met.

    It looks like bakerma2 has given you the solution.

  18. #18
    Forum Contributor
    Join Date
    06-17-2010
    Location
    Donemana, NI
    MS-Off Ver
    Excel 2007
    Posts
    386

    Re: Delete all occurrences when parameter has been met.

    Works great but have found another problem sorry, I need the code to delete all earlier occurrences of the key field (row) if the parameter "D51", "D54", "D55", "D56", "D58" is met

  19. #19
    Forum Contributor
    Join Date
    06-17-2010
    Location
    Donemana, NI
    MS-Off Ver
    Excel 2007
    Posts
    386

    Re: Delete all occurrences when parameter has been met.

    Can anyone help with this?

  20. #20
    Forum Contributor
    Join Date
    06-17-2010
    Location
    Donemana, NI
    MS-Off Ver
    Excel 2007
    Posts
    386

    Re: Delete all occurrences when parameter has been met.

    Can anyone help with this?

  21. #21
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,523

    Re: Delete all occurrences when parameter has been met.

    Quote Originally Posted by Burt_100 View Post
    I need the code to delete all earlier occurrences of the key field (row) if the parameter "D51", "D54", "D55", "D56", "D58" is met
    What do you mean?

  22. #22
    Forum Contributor
    Join Date
    06-17-2010
    Location
    Donemana, NI
    MS-Off Ver
    Excel 2007
    Posts
    386

    Re: Delete all occurrences when parameter has been met.

    I mean that once a parameter has been met not only does it delete that occurrence but also all other occurrences with the same key field in column E. Hope this is clear enough

  23. #23
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,523

    Re: Delete all occurrences when parameter has been met.

    Column E?
    Both of your files uploaded has no matched data in Col.E.

    You should upload a file with your desired result clearly showing how EXACTLY you want.

  24. #24
    Forum Contributor
    Join Date
    06-17-2010
    Location
    Donemana, NI
    MS-Off Ver
    Excel 2007
    Posts
    386

    Re: Delete all occurrences when parameter has been met.

    See attached file "Example_all", I have highlighted a few rows which meet the criteria and should be deleted, Hope this clears things up.
    Many Thanks
    Johnny

    Quote Originally Posted by jindon View Post
    Column E?
    Both of your files uploaded has no matched data in Col.E.

    You should upload a file with your desired result clearly showing how EXACTLY you want.
    Attached Files Attached Files

  25. #25
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,523

    Re: Delete all occurrences when parameter has been met.

    Quote Originally Posted by Burt_100 View Post
    I need the code to delete all earlier occurrences of the key field (row) if the parameter "D51", "D54", "D55", "D56", "D58" is met
    Again, there's no matched row(s) in Col.E.

  26. #26
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: Delete all occurrences when parameter has been met.

    In your earlier example file (example2) all cells in column E with the matching parameter in column A were empty so there was nothing to match in column E.
    So this whole Column E thing is a new ball game which you will have to explain further because right now we have not a single clue (at least I don't) what you are trying to achieve.

  27. #27
    Forum Contributor
    Join Date
    06-17-2010
    Location
    Donemana, NI
    MS-Off Ver
    Excel 2007
    Posts
    386

    Re: Delete all occurrences when parameter has been met.

    Sorry for the confusion, what I need is to do is if any of the parameters D51", "D54", "D55", "D56", "D58 are met in column A then I need the code to search all of column E and delete any occurrences (row) of the same key field.

    In simple terms once the parameter has been met I want to delete all occurrences associated with that field.

  28. #28
    Forum Contributor
    Join Date
    06-17-2010
    Location
    Donemana, NI
    MS-Off Ver
    Excel 2007
    Posts
    386

    Re: Delete all occurrences when parameter has been met.

    Sorry for the confusion, what I need is to do is if any of the parameters D51", "D54", "D55", "D56", "D58 are met in column A then I need the code to search all of column E and delete any occurrences (row) of the same key field.

    In simple terms once the parameter has been met I want to delete all occurrences associated with that field.

  29. #29
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: Delete all occurrences when parameter has been met.

    So what it comes down to is to create a unique list of all occurences in column E that meets one of the parameters.
    Then using that unique list filter column E on all of the elements of that list and delete all the rows accordingly, disregarding the value in column A.
    Does that describe it a bit?

  30. #30
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,523

    Re: Delete all occurrences when parameter has been met.

    Quote Originally Posted by Burt_100 View Post
    Sorry for the confusion, what I need is to do is if any of the parameters D51", "D54", "D55", "D56", "D58 are met in column A then I need the code to search all of column E and delete any occurrences (row) of the same key field.

    In simple terms once the parameter has been met I want to delete all occurrences associated with that field.
    You mean check the content of col.E where col.A meat the criteria then delete all the rows that have same col.E content regardless of Col.A?
    If so
    Please Login or Register  to view this content.

  31. #31
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,523

    Re: Delete all occurrences when parameter has been met.

    Burt_100

    Received rep.

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

  32. #32
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: Delete all occurrences when parameter has been met.

    Thanks for adding rep points.

+ 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. Replies: 2
    Last Post: 10-06-2014, 08:15 AM
  2. Replies: 0
    Last Post: 10-06-2014, 07:35 AM
  3. Parameter Query that takes parameter value from Excel Cell
    By Aquamore in forum Access Tables & Databases
    Replies: 1
    Last Post: 01-23-2014, 03:43 PM
  4. Replies: 0
    Last Post: 11-12-2013, 03:57 AM
  5. [SOLVED] Delete all the Rows on Work sheet using three week parameter
    By kesavanprabhu in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-05-2013, 08:44 AM
  6. [SOLVED] How to delete rows if set parameter is satisfied
    By Adam1987 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-10-2012, 10:16 AM
  7. Delete all occurrences of a character
    By Harleygrrl814 in forum Excel - New Users/Basics
    Replies: 8
    Last Post: 05-11-2005, 01:06 PM

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