+ Reply to Thread
Results 1 to 7 of 7

Array formula to count cells matching various texts

  1. #1
    Registered User
    Join Date
    01-17-2014
    Location
    home
    MS-Off Ver
    Excel 2007
    Posts
    4

    Array formula to count cells matching various texts

    Apologies if this has been answered, but I couldn't find anything quite suiting what I need.

    I have a set of cells that may contain numeric values, or letters indicating something specific. 8 = 8 hours worked, A = absence, V = vacation, P = paid leave and so on. I'm trying to sum and count the various values. I have a worksheet function the does the job, but it's messy, and I'd like a cleaner version. What I have now is a series of CountIfs: CountIf(a1:a10,"A") + CountIf(a1:a10,"V") + CountIf(a1:a10,"P").

    I found a post in another forum showing how to do this with an array formula, like this: =IF(OR(A3=1, A3=4, A3=7, A3=10),1,0) can be replaced by this: =(OR( A1 = {1,4,7,10} ) ) * 1

    However, I have been unable to adapt this to my own use. I either get errors or wrong values. What I am trying to build is something like this: CountIf(or( J10:AN10 = {"N";"O";"P";"V";"D";"A";"S"} ))

    I have entered many version of it, as a normal formula and array formula, neither works. Is this even possible?

    Pete

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

    Re: Array formula to count cells matching various texts

    One way...

    =SUM(COUNTIF(J10:AN10,{"N";"O";"P";"V";"D";"A";"S"}))
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  3. #3
    Registered User
    Join Date
    01-17-2014
    Location
    home
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Array formula to count cells matching various texts

    Yes, that did it. Thank you. Is there also a way to put the internal array into a named cell and use that as the parameter to CountIf? I've read about ways to do that, but none of the syntaxes I've tried have worked.

    Instead of =SUM(COUNTIF(J10:AN10,{"N";"O";"P";"V";"D";"A";"S"})), can I do something like ={"N";"O";"P";"V";"D";"A";"S"} into a cell, name the cell (say, Fred), and use =SUM(COUNTIF(J10:AN10,Fred))?

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

    Re: Array formula to count cells matching various texts

    You can put the values in individual cells like:

    A1 = N
    A2 = O
    A3 = P
    A4 = V
    A5 = D
    A6 = A
    A7 = S

    Give the range a defined name like Fred.

    Then use this formula:

    =SUMPRODUCT(COUNTIF(J10:AN10,Fred))

  5. #5
    Registered User
    Join Date
    01-17-2014
    Location
    home
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Array formula to count cells matching various texts

    Great. That works very nicely - appreciate it. I've been trying to learn how to work with arrays, since they're so useful in so many situations, but the syntax is often puzzling, and error messages unhelpful. I'll keep working on getting a grip on the array method, but this solves my current problem. Many thanks.

    Pete

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

    Re: Array formula to count cells matching various texts

    You're welcome. Thanks for the feedback!

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

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

    See if this helps wrt array formulas:

    http://www.cpearson.com/Excel/ArrayFormulas.aspx

  7. #7
    Registered User
    Join Date
    01-17-2014
    Location
    home
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Array formula to count cells matching various texts

    Already marked, and reputation added. Thanks for the link - I've known about Chip's site for years, and used it a lot, but I missed it this time around. Got a bit of reading and experimenting for this evening.

+ 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. Count certain texts in cells and provide percentage overall
    By JaynRW in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 01-16-2014, 10:01 AM
  2. Append texts into one string from 4 cells that each cell has a formula
    By Rocky2013 in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 07-28-2013, 09:57 AM
  3. Matching of strings & texts
    By bapsie in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 05-02-2013, 12:08 AM
  4. [SOLVED] Excel formula or array to count if certain text is in adjscent cells
    By rbrown63 in forum Excel General
    Replies: 7
    Last Post: 05-01-2012, 09:02 AM
  5. [SOLVED] sumif function when left 4 texts are matching
    By Vikram Dhemare in forum Excel General
    Replies: 1
    Last Post: 04-25-2006, 03:30 AM

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