+ Reply to Thread
Results 1 to 8 of 8

How to compare 2 columns using multiple criteria

  1. #1
    Registered User
    Join Date
    05-16-2012
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2007
    Posts
    63

    How to compare 2 columns using multiple criteria

    I apologize for the first 2 replies I completely re-did my post.

    I have 2 columns(A and B) both filled with numbers with an undefined number of rows as it will be different every time.
    Column A is labeled "/6" and column B is "/7 ".

    I need a way to add formulas in Column C based on these criteria

    IF /7 > /6 and both are positive. Then do this in column C: Subtract /6 from /7
    IF /7 < /6 and both are negative. Then do this in column C: subtract /7 from /6
    IF /7 is positive and /6 is negative. Then do this in column C: subtract /6 from /7
    IF /7 is negative Then do this in column C: =/7

    I was thinking of using a CASE statement, but can't figure how to code it.

    Thanks for any help!,

    Regards,

    Craig
    Last edited by csh8428; 10-02-2012 at 03:54 PM. Reason: added a lot of content

  2. #2
    Forum Contributor
    Join Date
    06-18-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    102

    Re: How to compare 2 columns using multiple criteria

    that code below isn't quite right. I am not sure how to make it work right. The first code was really close.
    Last edited by carden2; 10-02-2012 at 04:37 PM.

  3. #3
    Valued Forum Contributor
    Join Date
    03-17-2012
    Location
    Warsaw, Poland
    MS-Off Ver
    2007/2010
    Posts
    555

    Re: How to compare 2 columns using multiple criteria

    does this work? don't have excel open to test it thus its name ^^

    Please Login or Register  to view this content.
    pretty sure that even if it works, its not the best way to go around this problem.

  4. #4
    Registered User
    Join Date
    05-16-2012
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2007
    Posts
    63

    Re: How to compare 2 columns using multiple criteria

    Cardon and Bishon.. I apologize, but I modified my request heavily so I don't think your responses would fit it any longer.

  5. #5
    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,929

    Re: How to compare 2 columns using multiple criteria

    ok this is messy, and i dont have your data to test it, but try this in col C...
    =IF(AND(B2>A2,A2>0),B2-A2,IF(AND(B2<A2,A2<0),A2=B2,IF(AND(B2>0,A2<0),B2-A2,IF(B2<0,B2,""))))
    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

  6. #6
    Registered User
    Join Date
    05-16-2012
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2007
    Posts
    63

    Re: How to compare 2 columns using multiple criteria

    Fdibbins,

    I get an error when I used the code:

    Quote Originally Posted by FDibbins View Post
    ok this is messy, and i dont have your data to test it, but try this in col C...
    =IF(AND(B2>A2,A2>0),B2-A2,IF(AND(B2<A2,A2<0),A2=B2,IF(AND(B2>0,A2<0),B2-A2,IF(B2<0,B2,""))))
    The error is :
    Run-time error '1004'
    Applicaiton-defined or object-defined error

    Thanks,

    Craig

  7. #7
    Registered User
    Join Date
    05-16-2012
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2007
    Posts
    63

    Re: How to compare 2 columns using multiple criteria

    I think something like this might work, but I can only figure out how to code it for one cell(C1), and I"m not even sure if my syntax is right because I can't test it.

    Please Login or Register  to view this content.
    Could someone please correct my syntax and how would I get the macro to cycle through and go through the entire spreadsheet putting the correct formula in each successive cell in column C??

    Thanks,

  8. #8
    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,929

    Re: How to compare 2 columns using multiple criteria

    my sugesstion was meant to be for a formula, not for use in VBA. your initial post asked for a formula...

    Please Login or Register  to view this content.

+ 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