+ Reply to Thread
Results 1 to 4 of 4

COUNTIF Statements

  1. #1
    Registered User
    Join Date
    05-26-2011
    Location
    Newcastle
    MS-Off Ver
    Excel 2007
    Posts
    22

    COUNTIF Statements

    Evening everyone,

    I have a large spreadsheet with text strings in cells C5:DD32. Below are six examples of the format the text strings are in:

    Linda+1; George+2; Albert+4
    Albert+4; Linda+3
    George+2; Susan+6
    Albert+2; Linda+2
    Linda+1; George+2; Albert+4
    Linda+1; Albert+6; George+2;


    I would like a formulae where I can search for the number of times the combination ‘Linda+1; George+2; Albert+4’ occurs in these cells. So in this example, the output should be 2.

    NB. It should be noted that the order can change per cell.

    Ideally, I would like to be able to change the combination the function searches for by simply altering the values in given cells. So if I want to search for the number of times the combination ‘Linda+1; George+2; Albert+6’ occurs, I would have:

    In A1, I have ‘Linda’ and in B1 I have the number 1.
    In A2, I have ‘George’ and in B2 I have the number 2.
    In A3, I have ‘Albert’ and in B3 I have the number 6.

    NB. It should be noted that the order can change per cell.


    Lastly, if I was able to alter the combination the function searches for by simply altering the values in given cells, as listed above, I would also like it if when a 0 is placed in B1 for example, the function would only search for ‘George+2, Albert+6’ in any order i.e Both ‘George+2, Albert+6’ and ‘Albert+6’, George+2’.

    Many thanks for your help in advance.

  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: COUNTIF Statements

    Assuming the string ‘Linda+1; George+2; Albert+6’ is the full string all found in cell C5 (not split between other cells), then assuming your 6 examples above would thus be in cells C5:C10, this SUMPRODUCT() construct will do what you've asked initially:

    =SUMPRODUCT(--(ISNUMBER(SEARCH(A1&"+"&B1,$C$5:$C$10))), --(ISNUMBER(SEARCH(A2&"+"&B2,$C$5:$C$10))), --(ISNUMBER(SEARCH(A3&"+"&B3,$C$5:$C$10))))


    You could change the range to C5:DD32 and it should still work.
    _________________
    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
    Registered User
    Join Date
    05-26-2011
    Location
    Newcastle
    MS-Off Ver
    Excel 2007
    Posts
    22

    Re: COUNTIF Statements

    Thank you JBeaucaire for your help, that function works well on what I initially asked, however unfortunately I cannot get it to work on my last point!

    Keeping all of the functionality of that function, we still have the following:

    In A1, I have ‘Linda’ and in B1 I have the number 1.
    In A2, I have ‘George’ and in B2 I have the number 2.
    In A3, I have ‘Albert’ and in B3 I have the number 6.


    I would also like the function if when a 0 is placed in B1 for example, the function would only search for ‘George+2, Albert+6’ in any order i.e Both ‘George+2, Albert+6’ and ‘Albert+6’, George+2’.

    Cheers

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: COUNTIF Statements

    It's ugly, but it works:

    =SUMPRODUCT(--(ISNUMBER(SEARCH(IF(B1=0, "*", A1&"+"&B1), $C$5:$C$10))), --(ISNUMBER(SEARCH(IF(B2=0, "*", A2&"+"&B2), $C$5:$C$10))), --(ISNUMBER(SEARCH(IF(B3=0, "*", A3&"+"&B3), $C$5:$C$10))))

+ 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