+ Reply to Thread
Results 1 to 10 of 10

Calculate number of cells with two numbers

  1. #1
    Registered User
    Join Date
    05-08-2010
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    8

    Calculate number of cells with two numbers

    Hello!

    Imagine this:

    I have two rows.
    Row A has number from 0 to 99
    Row B has number from 0 to 30, so, for example:

    (A) (B)
    1 1
    1 1
    1 1
    1 2
    1 2
    1 3
    ........
    7 1
    7 1
    9 2
    10 6


    I then want to now: The number of Row B cells with the number 1 and with A=1, then the number of row b cells with the number 2 and A=1, then the number of rob b cells with the number 3, but with A=1. It would be: 3, 2, 4 ... and I want this to continue for a couple hundred (200) cells. For example then it would be ... The number of cells with B=1 and A=7 will be 2,

    Thanks for all assistance.
    Last edited by WIMP; 05-08-2010 at 02:38 PM.

  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: Calculate number of cells with two numbers

    The SUMPRODUCT() can be used to do a multi-criteria countif in the manner you're describing.

    1) Assuming values in A and B through 300 rows
    2) Assuming the A value you want to match is in C1 (1)
    3) Assuming the B value you want to match is in D1 (1)
    4) Put this formula in E1

    =SUMPRODUCT(--($A$1:$A$300=C1), --($B$1:$B$300=D1))

    Now put more rows of search data in C2 - D2, then C3 - D3 and copy that E1 cell downward to get more counts.
    _________________
    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
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Calculate number of cells with two numbers

    perhaps this
    Attached Files Attached Files
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  4. #4
    Registered User
    Join Date
    05-08-2010
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Calculate number of cells with two numbers

    @ JBeaucaire: This is excellent, thanks.

    @ martindwilson: Hi. For some reason I can not download anything but is it possible for you to explain? Thanks
    EDIT: Thanks! I see it's kinda similiar to JBeaucaires.
    Last edited by WIMP; 05-08-2010 at 02:38 PM. Reason: deleted quotes

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Calculate number of cells with two numbers

    A portion of Martin's workbook:
    Please Login or Register  to view this content.
    The formula in D3 and copied down and across is

    =SUMPRODUCT(($B$2:$B$101=D$2)*($A$2:$A$101=$C3))
    Entia non sunt multiplicanda sine necessitate

  6. #6
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Calculate number of cells with two numbers

    ok with your pairs of numbers starting in a2 and b2 downwards
    from d2 to z2 put the numbers 0 to 23 that represents your possible b values
    in c3 to d34 number down to 0 to 31 that represents your possible a values
    in d3 put =SUMPRODUCT(($B$2:$B$101=D$2)*($A$2:$A$101=$C3)) drag across and down
    youll now have a grid where you can read off the count if yoy have more that 100 rows increase range into match
    note ive changed it from above to start both from 0 not 1.
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    05-08-2010
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Calculate number of cells with two numbers

    This can be deleted, original post is what counts.
    Last edited by WIMP; 05-08-2010 at 02:35 PM.

  8. #8
    Registered User
    Join Date
    05-08-2010
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Calculate number of cells with two numbers

    This can be deleted, original post is what counts.
    Last edited by WIMP; 05-08-2010 at 02:35 PM.

  9. #9
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Calculate number of cells with two numbers

    i think you are probably over complicating things. are you saying col a will have 1 23 times then 2 23 times then 3 23 times all the way up to 31 23 times?? and b will be any number between 1 and 23? down to the end of col a ?
    then with your rows starting a1 and b1 in c1 =SUMPRODUCT((B1:B1089=E1)*(A1:A1089=F1)) put value of b in e2 and value of a in f1 say 10 and 2 that will count all the times b=10 and f=2 if thats not right attach a work book
    Last edited by martindwilson; 05-08-2010 at 02:19 PM.

  10. #10
    Registered User
    Join Date
    05-08-2010
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Calculate number of cells with two numbers

    Working on it. Thank you all
    Last edited by WIMP; 05-08-2010 at 02:45 PM.

+ 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