+ Reply to Thread
Results 1 to 11 of 11

Delete from 2 sheets if matching criteria

  1. #1
    Registered User
    Join Date
    03-25-2008
    Posts
    71

    Delete from 2 sheets if matching criteria

    Hi All,

    I'm looking for a Macro that will allow me to take information on two different sheets in a workbook, and delete out lines that match based on a "concatenate" formula. Each sheet has slightly different outputs as they are reports from two different systems. Based on the attached example, I'm looking for something that will allow the following:

    1) Sys 1 RPT will concatenate columns A, E, F.
    2) Sys 2 RPT will concatenate columns A, D, E.

    The Marco would then go through the two sheets and delete out lines in which rows with matching concatenated data string matches leaving each sheet with only rows that need to be looked at in more detail to recon and find out why they are not on the other report.

    I hope this makes sense, and I'm open to other methods, if there is something easier to work with.
    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 from 2 sheets if matching criteria

    I believe this will do what you want based on your example:
    Please Login or Register  to view this content.
    Last edited by JBeaucaire; 05-07-2009 at 04:44 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
    Registered User
    Join Date
    03-25-2008
    Posts
    71

    Re: Delete from 2 sheets if matching criteria

    Please Login or Register  to view this content.
    When the Macro get's the this code on the 'Sys 1 RPT' section, I get an error, no more lines detected. Then it appears that the filter being used hasn't fully completed.

    Thoughts?

  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 from 2 sheets if matching criteria

    I think you should go into the VBEditor and use F8 to walk through that macro one line at a time, then go look at the sheet and see what it's done so far. If it gets to that line in the code and there are NO visible cells, that would be an issue, I imagine. If you're stepping through the macro, you can see that the column I has no values of "1" for some reason.

    I am just using standard worksheet formulas to compare the two sheets and count the duplicates.

  5. #5
    Registered User
    Join Date
    03-25-2008
    Posts
    71

    Re: Delete from 2 sheets if matching criteria

    After walking thought it, it seems to work well till it gets to the filter aspect. The Auto filter hides the cells and doesn't go through the process of deleting rows that are still viable with a value of 1 (which appears to be the intent, correct?).

  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 from 2 sheets if matching criteria

    Hmm, a couple of minor tweaks here:
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    03-25-2008
    Posts
    71

    Re: Delete from 2 sheets if matching criteria

    This now works perfect! Awesome!

    Only question to take this one step father would be what the adjustment to the code would need to be to have the Filter fun through all the numbers that don't equal "0", and delete them as they match. As this has shown me, I have 4 on each sheet that matched that could be deleted as well. I was able to test this by changing the criteria from "1" to "4", but was curious to see the best way to have the macro to maybe circle though the numbers 1-9?

    Thanks again!

  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 from 2 sheets if matching criteria

    Change the criteria to ">0"

  9. #9
    Registered User
    Join Date
    03-25-2008
    Posts
    71

    Re: Delete from 2 sheets if matching criteria

    So I've been using the above with a lot of success and wanted to adjust it a tad to use in a very similar form. Basically, the criteria is less this time and and can change the columns to use, but the macro always errors out in the auto filter of the "Sys 1 RPT" sheet. Seems to be the range, but no matter what I change, it doesn't seem to work.

    Here is the code I'm using :

    Please Login or Register  to view this content.
    This is the line it always errors out on:

    Please Login or Register  to view this content.
    And I've attached a sample data workbook. I know this is simple, I just think I'm missing something very small.
    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 from 2 sheets if matching criteria

    The problem is you have to adjust the formulas we're using when you move columns around. To simplify things, I'm putting FORMULAS into columns G and H and then filtering rows based on the results. This keeps from having to do LOOPS through the sheets, and is faster.

    But just like if you were working on the sheet, if you move a column, the formula(s) have to be adjusted, too. I've highlighted the changes I made in the code so the columns YOU are now using are properly evaluated:
    Please Login or Register  to view this content.
    Last edited by JBeaucaire; 05-13-2009 at 12:37 PM.

  11. #11
    Registered User
    Join Date
    03-25-2008
    Posts
    71

    Re: Delete from 2 sheets if matching criteria

    Awesome! Thanks you soooo much!

+ 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