+ Reply to Thread
Results 1 to 14 of 14

Help please, trying to get a function to detect 4 cells in a row.

  1. #1
    Registered User
    Join Date
    06-17-2012
    Location
    Albany, New York
    MS-Off Ver
    Excel 2010
    Posts
    3

    Help please, trying to get a function to detect 4 cells in a row.

    I'm trying to get Microsoft Excel to check to see if this variable is true or not. Example would be that I would flip 10 coins and what I'd need it to do is to get it to tell me that if somewhere within those 10 coin flips, if 4 of them where in a row (not total).

    Example would be: (H for Heads, T for Tails)

    THTTHHHHTTT <--- How would I get Excel to look at that (in 10 different cells going from A-J) and tell me "yes, no, true or false?

    Thank you for taking the time to read this.

  2. #2
    Forum Contributor
    Join Date
    11-02-2011
    Location
    Rugby, England
    MS-Off Ver
    Office 365
    Posts
    846

    Re: Help please, trying to get a function to detect 4 cells in a row.

    Hello,
    If your information is in Cell A1, in CellA2 please type -
    Please Login or Register  to view this content.
    galvinpaddy

  3. #3
    Forum Contributor
    Join Date
    11-02-2011
    Location
    Rugby, England
    MS-Off Ver
    Office 365
    Posts
    846

    Re: Help please, trying to get a function to detect 4 cells in a row.

    You could also put in -
    Please Login or Register  to view this content.
    that will show you OK if either HHHH or TTTT exist, but it will only check if 4 or more exist in a row, not if its ONLY 4

  4. #4
    Registered User
    Join Date
    06-17-2012
    Location
    Albany, New York
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Help please, trying to get a function to detect 4 cells in a row.

    Is there any way to search multiple cells? For some reason (even after changing the name from HHHH to what I needed) it continues to say Not OK.

  5. #5
    Forum Contributor
    Join Date
    11-02-2011
    Location
    Rugby, England
    MS-Off Ver
    Office 365
    Posts
    846

    Re: Help please, trying to get a function to detect 4 cells in a row.

    The part that says 'A1' you need to change that to reflect what range you are after.

  6. #6
    Forum Contributor
    Join Date
    11-02-2011
    Location
    Rugby, England
    MS-Off Ver
    Office 365
    Posts
    846

    Re: Help please, trying to get a function to detect 4 cells in a row.

    If you load a sample sheet I may be able to help more.

  7. #7
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: Help please, trying to get a function to detect 4 cells in a row.

    I think you'd need to CONCATENATE() the results into one cell before using those formulas on that cell.

  8. #8
    Forum Contributor
    Join Date
    11-02-2011
    Location
    Rugby, England
    MS-Off Ver
    Office 365
    Posts
    846

    Re: Help please, trying to get a function to detect 4 cells in a row.

    Agreed, my original post assumed all info was in one cell (A1) however, after re-reading the OP i now see it states is different cells! (sry for the confusion)
    CONCATENATE() is indeed what you need.

  9. #9
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Help please, trying to get a function to detect 4 cells in a row.

    There is a way using MAX() & FREQUENCY(), but I can't get my head around it ...

    Try this SUMPRODUCT() attempt, it counts the number of times there are 4 consecutive matching characters, including overlaps, i.e. if there are 10 consecutive matching characters, the formula will return 7.
    [EDIT]
    See the second table, it highlights the first of 4 consecutive matching characters.

    In A2
    Please Login or Register  to view this content.
    Select from the dropdown in A1
    Attached Files Attached Files
    Last edited by Marcol; 06-17-2012 at 11:53 AM. Reason: Added to the attachment
    If you need any more information, please feel free to ask.

    However,If this takes care of your needs, please select Thread Tools from menu above and set this topic to SOLVED. It helps everybody! ....

    Also
    اس کی مدد کرتا ہے اگر
    شکریہ کہنے کے لئے سٹار کلک کریں
    If you are satisfied by any members response to your problem please consider using the small Star icon bottom left of their post to show your appreciation.

  10. #10
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: Help please, trying to get a function to detect 4 cells in a row.

    Quote Originally Posted by KatenKotsu View Post
    THTTHHHHTTT <--- How would I get Excel to look at that (in 10 different cells going from A-J) and tell me "yes, no, true or false?
    11 coin flips in 10 cells could confuse the formula

    Assuming that was a typo, try the formula below array confirmed with Shift Ctrl Enter,

    Please Login or Register  to view this content.

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

    Re: Help please, trying to get a function to detect 4 cells in a row.

    Good day,

    Firstly, in column K get all values of A-J together using

    Please Login or Register  to view this content.
    Then use the following to determine whether there are 4 consecutive instances

    Please Login or Register  to view this content.

  12. #12
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Help please, trying to get a function to detect 4 cells in a row.

    I got a bee in my bunnet with this thread ...

    Compare the methods SUMPRODUCT(),FREQUENCY(),MATCH(), and CONCATENATE() in this workbook

    Select from the drop-down in A1 to find out if there is a series of 4 or more Heads/Tails in a row.
    The second column in each case indicates if there is a series of 4 or more of either in the row.
    Attached Files Attached Files

  13. #13
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: Help please, trying to get a function to detect 4 cells in a row.

    Some revised formula for you to play with Marcol

    These are all for H / T combined check

    =SUMPRODUCT((A2:J2={"T";"H"})*(B2:K2={"T";"H"})*(C2:L2={"T";"H"})*(D2:M2={"T";"H"}))>0

    {=OR(ISNUMBER(MATCH(REPT({"H","T"},4),A2:J2&B2:K2&C2:L2&D2:M2,0)))}

    =OR(ISNUMBER(SEARCH(REPT({"T","H"},4),A2&B2&C2&D2&E2&F2&G2&H2&I2&J2)))

    The same method won't work with the frequency formula.

    And another formula that came to mind

    =MAX(COUNTIF(OFFSET($A2:$G2,,{0,1,2,3,4,5,6},1,4),{"T";"H"}))=4

    I'm sure there are many other ways to get the same results.

    edit:-

    If you try to analyse the formula construction note that the array constants in the sumproduct and countif formula are vertical, a horizontal array would give incorrect results.
    Last edited by jason.b75; 06-18-2012 at 12:53 PM.

  14. #14
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Help please, trying to get a function to detect 4 cells in a row.

    Good stuff Jason ...

+ 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