+ Reply to Thread
Results 1 to 9 of 9

Find 4 consecutive occurrences

Hybrid View

  1. #1
    Forum Expert swatsp0p's Avatar
    Join Date
    10-07-2004
    Location
    Kentucky, USA
    MS-Off Ver
    Excel 2010
    Posts
    1,545

    Find 4 consecutive occurrences

    My sheet is used to enter lab test results in a row. I am entering the test date and result (e.g. cells H4:K4 - "3/13 N"; "3/20 P"; "3/27 N"; "4/3 N"...). My goal is to have a Status cell (B4) return a "Yes" when four consecutive "N" results (negative) appear (informing me that the testing for that variable can stop). The Status cell would need to return "No" until such time as four consecutive "N" results are entered. Macro is an option, formula would be preferred. Excel 2003. Any ideas? Thanks for your time... Bruce
    Bruce
    The older I get, the better I used to be.
    USA

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Find 4 consecutive occurrences

    Assuming you have contiguous data set then perhaps:

    =IF(COUNTIF(INDEX($H4:$Z4,MATCH(REPT("Z",255),$H4:$Z4)-MIN(3,COUNTA($H4:$Z4))):$Z4,"*N")=4,"Yes","No")

    modify range to suit of course...

  3. #3
    Forum Expert Palmetto's Avatar
    Join Date
    04-04-2007
    Location
    South Eastern, USA
    MS-Off Ver
    XP, 2007, 2010
    Posts
    3,978

    Re: Find 4 consecutive occurrences

    See this link: Count At Least 4 Consecutive Values

    It's not clear from your post, but if you are entering the date and result (i.e. "3/13 N") into the same cell it will may be more difficult to determine if you have four consecutive results if the data portion is changing. If all tests are concluded on the same date then it should not be an issue.

    One possible approach might be to use a simple COUNTIF formula in a helper cell and use a MATCH formula to change status to "Yes" when the count of consecutive occurences equals 4.

    =COUNTIF(B3:E3,"N")=4
    =IF(ISERROR(MATCH(TRUE,E4:I4,0)),"No","Yes")

    See attached- which assumes separate entries for dates and results (recommended).
    Attached Files Attached Files
    Palmetto

    Do you know . . . ?

    You can leave feedback and add to the reputation of all who contributed a helpful response to your solution by clicking the star icon located at the left in one of their post in this thread.

  4. #4
    Forum Expert swatsp0p's Avatar
    Join Date
    10-07-2004
    Location
    Kentucky, USA
    MS-Off Ver
    Excel 2010
    Posts
    1,545

    Re: Find 4 consecutive occurrences

    Here is the sheet I am working on. The formulas given don't seem to return the desired result.

    You will see the format for lab results entry ("3/27 P") in one cell. I am open to a better way to enter this data to achieve the desired result.

    Thanks for the quick response.
    Attached Files Attached Files
    Last edited by swatsp0p; 03-27-2010 at 12:20 PM. Reason: file not attached

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

    Re: Find 4 consecutive occurrences

    i cant see 3/27 P anywhere on that sheet! but assuming its just those y/n then donkyotes function still holds true
    =IF(COUNTIF(INDEX($B3:$Z3,MATCH(REPT("Z",255),$B3:$Z3)-MIN(3,COUNTA($B3:$Z3))):$Z3,"*N")=4,"Yes","No")
    "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

  6. #6
    Forum Expert Palmetto's Avatar
    Join Date
    04-04-2007
    Location
    South Eastern, USA
    MS-Off Ver
    XP, 2007, 2010
    Posts
    3,978

    Re: Find 4 consecutive occurrences

    Cell references adjusted per the sample workbook - it returns the correct value.
    =IF(COUNTIF(INDEX($G6:$S6,MATCH(REPT("Z",255),$G6:$S6)-MIN(3,COUNTA($G6:$S6))):$S4,"*N")=4,"Yes","No")

    My suggested solution is not valid given the structure of the sample workbook, but was provided before the workbook was made available.

  7. #7
    Forum Expert swatsp0p's Avatar
    Join Date
    10-07-2004
    Location
    Kentucky, USA
    MS-Off Ver
    Excel 2010
    Posts
    1,545

    Re: Find 4 consecutive occurrences

    OK, I've update the sheet to show the full scenario. Notice in B6 and B7 the formula returns "No", when, in fact, the four consecutive "N"egative results are in K6:N6 and J7:M7. This should return "Yes" in B6 and B7 , meaning the re-testing can be terminated. Thanks again for your time.
    Attached Files Attached Files

  8. #8
    Forum Expert Palmetto's Avatar
    Join Date
    04-04-2007
    Location
    South Eastern, USA
    MS-Off Ver
    XP, 2007, 2010
    Posts
    3,978

    Re: Find 4 consecutive occurrences

    Notice in B6 and B7 the formula returns "No", when, in fact, the four consecutive "N"egative results are in K6:N6 and J7:M7.
    As I showed and as DO mentioned: adjust the cell references.

    It must be $G$6:$S$6 ( not $Z$6 )

  9. #9
    Forum Expert swatsp0p's Avatar
    Join Date
    10-07-2004
    Location
    Kentucky, USA
    MS-Off Ver
    Excel 2010
    Posts
    1,545

    Re: Find 4 consecutive occurrences

    Excellent. Not sure why column 'S' was the sticking point, but it works now.

    Thanks to all for your input and time.

+ 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