+ Reply to Thread
Results 1 to 10 of 10

Comparing data in two pairs of columns, and automatically deleting based on relative value

  1. #1
    Registered User
    Join Date
    01-23-2016
    Location
    Wales
    MS-Off Ver
    2016
    Posts
    6

    Comparing data in two pairs of columns, and automatically deleting based on relative value

    I have two columns, the first contains the name of a chemical, the second contains a numerical concentration for that chemical.

    I need to compare these two columns to a second pair of columns containing the same two variables, and delete any compounds in the first pair which are present in the second pair, unless the concentrations of the first pair are 20 times greater than that of the second pair.

    Is there a way to do this using COUNTIF or something similar? I would be happy to provide more information if needed, and grateful for any advice.

  2. #2
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: Comparing data in two pairs of columns, and automatically deleting based on relative v

    Probably COUNTIFS if you are dealing with more than one column. An example worksheet would be useful.
    Martin

  3. #3
    Registered User
    Join Date
    01-23-2016
    Location
    Wales
    MS-Off Ver
    2016
    Posts
    6

    Re: Comparing data in two pairs of columns, and automatically deleting based on relative v

    Thank you for the quick reply, I have attached an example worksheet.
    Attached Files Attached Files

  4. #4
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: Comparing data in two pairs of columns, and automatically deleting based on relative v

    Decided to use a user defined function.

    Please Login or Register  to view this content.
    Open the VBA editor by hitting Alt F11.
    Insert a new module with Insert - Module
    Paste in the above function
    Go back to the sheet by hitting Alt F11.

    In a cell C3, enter =Compare($E$3:$E$5,A3,$F$3:$F$5,B3)

    Remember to save the workbook as a macro enabled workbook .xlsm

  5. #5
    Registered User
    Join Date
    01-23-2016
    Location
    Wales
    MS-Off Ver
    2016
    Posts
    6

    Re: Comparing data in two pairs of columns, and automatically deleting based on relative v

    Hi mrice,

    I cannot thank you enough for taking the time to help me with this, it has completely solved my problem! Would this work if the columns changed their titles, or if more chemicals were added to pair 2? If not, which parts of the code would I need to alter?
    Last edited by Crashed; 01-23-2016 at 05:10 PM.

  6. #6
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967
    The column names aren't read so you can call them what you wish.

  7. #7
    Registered User
    Join Date
    01-23-2016
    Location
    Wales
    MS-Off Ver
    2016
    Posts
    6

    Re: Comparing data in two pairs of columns, and automatically deleting based on relative v

    Amazing, thank you so much!

  8. #8
    Registered User
    Join Date
    01-23-2016
    Location
    Wales
    MS-Off Ver
    2016
    Posts
    6

    Re: Comparing data in two pairs of columns, and automatically deleting based on relative v

    Sorry to be a major pain, but I have a #Value error when using the code you provided and I cannot figure out why it is giving it. It seems to work with everything else apart from a particular compound name, as soon as I change the compound name in the second pair it works again. I have attached the worksheet and highlighted the relevant cells in red. Any help would be greatly appreciated.
    Attached Files Attached Files

  9. #9
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: Comparing data in two pairs of columns, and automatically deleting based on relative v

    This slight modification explicitly specifying the match type seems to help.

    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    01-23-2016
    Location
    Wales
    MS-Off Ver
    2016
    Posts
    6

    Re: Comparing data in two pairs of columns, and automatically deleting based on relative v

    Thank you so much for this, and all the other help you've given!

+ 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: 3
    Last Post: 08-25-2015, 02:03 PM
  2. [SOLVED] Comparing data in two different columns and deleting entire row
    By Erik_with_a_K in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-14-2013, 11:42 AM
  3. Comparing columns and deleting those that do not match
    By Insert Name in forum Excel General
    Replies: 11
    Last Post: 01-01-2013, 06:16 PM
  4. Deleting rows based on a cells value that is relative to the cell above it
    By makoman82 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-08-2011, 06:27 PM
  5. Comparing & deleting data in 2 columns
    By Carl Chip in forum Excel General
    Replies: 4
    Last Post: 04-19-2009, 09:29 AM
  6. Comparing Columns and Deleting values
    By oneblueaugust in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 11-06-2007, 02:43 PM
  7. Replies: 2
    Last Post: 12-19-2006, 11:44 AM

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