+ Reply to Thread
Results 1 to 9 of 9

Counting cells in B based on text in column A

  1. #1
    Registered User
    Join Date
    02-12-2013
    Location
    Philadelphia
    MS-Off Ver
    Excel 20010
    Posts
    16

    Counting cells in B based on text in column A

    Hello,

    I have a 2 column Excel sheet: Column A contains a random assortment of months (January - December). Column B contains various names (see attachment).

    I would like a cell in a separate workbook to give me the total cells in column B that have January in column A. However, there may be duplicates, which I do not want (There could be multiple rows that have January in column A & Sarah in column B, but they should only count as 1).

    So far I've been able to use COUNTIF to count how many cells are in a column, minus the duplicates: =SUM(1/COUNTIF(Range1,Range1))
    I've also been able to use COUNTIFS to get a sum of how many cells contain a specific string of text:=COUNTIFS(Range2,"criteria2")

    I think I need to combine these 2 in some way, but I can't quite figure out how to do it.

    Can anyone help me out here? I'd really appreciate it!

    Thanks =]

    Jackie
    Attached Files Attached Files

  2. #2
    Forum Expert Ace_XL's Avatar
    Join Date
    06-04-2012
    Location
    UAE
    MS-Off Ver
    2016
    Posts
    6,074

    Re: Counting cells in B based on text in column A

    In your sample sheet use

    =SUMPRODUCT((A2:A8<>"")/COUNTIFS(A2:A8,A2:A8&"",B2:B8,B2:B8&""))

    make sure range does not include any blank rows
    Life's a spreadsheet, Excel!
    Say thanks, Click *

  3. #3
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Counting cells in B based on text in column A

    Try this array formula**.

    D2 = some month like Jan

    Then, this array formula** entered in E2:

    =SUM(IF(FREQUENCY(IF(A2:A8=D2,MATCH(B2:B8,B2:B8,0)),ROW(B2:B8)-ROW(B2)+1),1))

    ** array formulas need to be entered using the key
    combination of CTRL,SHIFT,ENTER (not just ENTER).
    Hold down both the CTRL key and the SHIFT key
    then hit ENTER.
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  4. #4
    Registered User
    Join Date
    02-12-2013
    Location
    Philadelphia
    MS-Off Ver
    Excel 20010
    Posts
    16

    Re: Counting cells in B based on text in column A

    Thanks for the quick responses! I'm having some issues though.

    Ace_XL -- Your formula tells me how many names I have, minus the duplicates (6), but I'm looking for how many names have January next to them, minus duplicates, so the number displayed should be 1. Are we on the same page here?

    Tony -- Your formula seems to work well. However, I have to apply this concept to a much larger, more complex book of data, so I'd like to know exactly how it works. If you have time, would you mind explaining what the formula does step by step?

    Thanks again to both of you!

  5. #5
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Counting cells in B based on text in column A

    Quote Originally Posted by Jackie5467 View Post

    Tony -- Your formula seems to work well. If you have time, would you mind explaining what the formula does step by step?
    Here's an explanation I wrote at another forum.

    The mechanics of the formula are exactly the same, just the data is different.

    http://www.mrexcel.com/forum/showpos...7&postcount=10

  6. #6
    Registered User
    Join Date
    02-12-2013
    Location
    Philadelphia
    MS-Off Ver
    Excel 20010
    Posts
    16

    Re: Counting cells in B based on text in column A

    Thanks a lot, Tony! That explanation was very helpful--one last area I'm confused about though:

    I assumed that if you were to add additional columns you could just add an AND statement to your above formula. However, that doesn't seem to be the case. For instance, if I add a new column B to the left of our Names column, let's say a column of random numbers, and now we were looking for the unique number of rows that have January in column A, the number 2 in column B, and Sarah in column C, I thought this formula would work: =SUM(IF(FREQUENCY(IF(AND(A2:A8=D2,B2:B8=D3),MATCH(C2:C8,C2:C8,0)),ROW(C2:C8)-ROW(C2)+1),1)), where we've set D3 equal to 2.

    However, I keep getting an #VALUE! error. Can you explain why?

  7. #7
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Counting cells in B based on text in column A

    For multiple conditions we just use additional levels of IF functions:

    =SUM(IF(FREQUENCY(IF(A2:A8=D2,IF(B2:B8=D3,MATCH(C2:C8,C2:C8,0))),ROW(C2:C8)-ROW(C2)+1),1))

    Still array entered.

  8. #8
    Registered User
    Join Date
    02-12-2013
    Location
    Philadelphia
    MS-Off Ver
    Excel 20010
    Posts
    16

    Re: Counting cells in B based on text in column A

    Ah, so simple! Thanks again, Tony!

  9. #9
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Counting cells in B based on text in column A

    You're welcome. Thanks for the feedback!


    If your question has been solved please mark the thread as being solved.

    In the menu bar above the very first post select Thread Tools, then select Mark this thread as solved.

+ 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. counting blank cells in range based on condition using another column
    By TheBlueBell in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-14-2013, 04:58 PM
  2. Counting Text based on specific criteria in another column
    By djreddy in forum Excel Formulas & Functions
    Replies: 26
    Last Post: 08-26-2013, 09:35 AM
  3. Counting Unique text in column B based on a criteria from column a
    By clocmasta in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 06-18-2013, 06:40 PM
  4. Counting cells in offset column based on contents of another column.
    By Big Chris in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 04-10-2008, 09:25 AM
  5. COUNTING TEXT CELLS IN A COLUMN
    By Maureen in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 05-09-2005, 02:06 PM

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