+ Reply to Thread
Results 1 to 9 of 9

Compare and count 2 columns

  1. #1
    Registered User
    Join Date
    01-29-2010
    Location
    Québec
    MS-Off Ver
    Excel 2003
    Posts
    4

    Compare and count 2 columns

    Hi,
    I'm desperately looking for THE formula.

    Here's the context :
    ---------A----------B--------
    1------CR------Marie
    2------CR------
    3------CR------Alex
    4------CR------Martin
    5------CR------

    In another sheet of my file, I want to calculate how many persons (col B) have the CR code (col A).
    I must specify that there's many other different codes (col A) and that sometimes there's no person specified for a code (see my example). In my example, the answer i'm looking for is 3.
    I tried with IF, AND, OR, ...without success.

    Thanks for any help.

  2. #2
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Compare and count 2 columns

    Try

    =Sumproduct(--(Sheet1!A1:A100="CR"),--(Sheet1!B1:B100<>""))

    adjust ranges and sheetnmame to suit
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

  3. #3
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Compare and count 2 columns

    Hi,

    One way using a helper column C

    Please Login or Register  to view this content.
    then use
    Please Login or Register  to view this content.
    You could use a
    Please Login or Register  to view this content.
    formula, which may be better if you only have a few rows otherwise since it's an array formula it will take longer to calculate.

    HTH
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  4. #4
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Compare and count 2 columns

    NBVC's solution will work if names are not repeated. I had trouble doing it without a helper or dummy column. In the dummy column, I used this formula dragged down(column C)
    Please Login or Register  to view this content.
    which returns "True" whenever a name appears for the first time. Then this formula works
    Please Login or Register  to view this content.
    Will that work for you?
    ChemistB
    My 2?

    substitute commas with semi-colons if your region settings requires
    Don't forget to mark threads as "Solved" (Edit First post>Advanced>Change Prefix)
    If I helped, Don't forget to add to my reputation (click on the little star at bottom of this post)

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  5. #5
    Registered User
    Join Date
    01-29-2010
    Location
    Québec
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Compare and count 2 columns

    Thanks, I think that would be it !!! But Excel won't accept this formula ?? The error message : "The formula you entered contains an error ...". Here's my formula :
    =Sumproduct(--('Jan 2010'!F3:F100="CR"),--('Jan 2010'!I3:I100<>"")). The comma between the 2 arrays seems to be the problem !!?!? I tried with other symbols ( ; * / ). No error message as above, but they won't let excel return anything good (normal u will say !!).

    Thanks

  6. #6
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Compare and count 2 columns

    Your version of Excel probably uses semi colon instead of comma. When you say it doesn't return anything normal, what does it return (when using semicolon)? Upload a dummy workbook if you want us to troubleshoot it.

  7. #7
    Registered User
    Join Date
    01-29-2010
    Location
    Québec
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Compare and count 2 columns

    Thanks ChemistB,

    Here you go with a dummy file. 2 sheets in it : Jan 2010 with some data and Stats for the results.
    Semi-colon returns a $NAME? error
    Attached Files Attached Files

  8. #8
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Compare and count 2 columns

    See attached...
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    01-29-2010
    Location
    Québec
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Compare and count 2 columns

    Excellent,

    Thanks

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

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