+ Reply to Thread
Results 1 to 12 of 12

Counting Consecutive occurences a letter appears in a row

  1. #1
    Registered User
    Join Date
    07-24-2015
    Location
    London
    MS-Off Ver
    2007
    Posts
    6

    Counting Consecutive occurences a letter appears in a row

    I use a excel sheet to keep track of employee holiday, sickness and rota'd shift. This is done by marking "D" as day to work "S" for sick "T" for training and "H" for holiday. With blanks in between for days off. I need a way of tracking the occurrences that someone is sick in a year.

    I have attached a copy of what it looks like.

    A3 is the row with the dates in.
    So in Row 7 I want it to give a value of 2. As there is 2 occurrences of sick as there was a day worked in between.
    Then in Row 9 it should give a value of 1, as it is 2 days but 1 occurrence.

    If anyone can give me an answer it would be great have been searching a long time to try and work a solution!
    Attached Images Attached Images

  2. #2
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,939

    Re: Counting Consecutive occurences a letter appears in a row

    HI, welcome to the forum

    To do a count like this, you would probably need to use =COUNTIF()
    =COUNTIF(row-range,"D")
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  3. #3
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,587

    Re: Counting Consecutive occurences a letter appears in a row

    Pl see attached file with UDF CountIf_Special
    Please Login or Register  to view this content.
    Attached Files Attached Files

  4. #4
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,063

    Re: Counting Consecutive occurences a letter appears in a row

    You posted a picture. On an Excel forum that's of limited use. An Excel sheet is FAR better. However, adjust the rnges in this to suit your sheet, and it should work perfectly. If not, attach an Excel sheet.

    =SUM(IF(FREQUENCY(IF(D5:Y5="S",COLUMN(D5:Y5)),IF(D5:Y5<>"S",COLUMN(D5:Y5))),1))
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU.

    Temporary addition of accented to illustrate ongoing problem to the TT: L? fh?ile P?draig sona dhaoibh

  5. #5
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,939

    Re: Counting Consecutive occurences a letter appears in a row

    yeah, I should have focused more on the heading, and less on the post - missed that 1 altogether

  6. #6
    Registered User
    Join Date
    07-24-2015
    Location
    London
    MS-Off Ver
    2007
    Posts
    6

    Re: Counting Consecutive occurences a letter appears in a row

    This is very close to what I want, so thank you for your response.
    But the correct answer for "S" that I want should be 4. As I don't want it to stop counting the occurrence til a day has been worked again.
    So K4 - O4 as in your spreadsheet would be one occurrence as a day hadn't been worked in between.

  7. #7
    Registered User
    Join Date
    07-24-2015
    Location
    London
    MS-Off Ver
    2007
    Posts
    6

    Re: Counting Consecutive occurences a letter appears in a row

    Quote Originally Posted by kvsrinivasamurthy View Post
    Pl see attached file with UDF CountIf_Special
    Please Login or Register  to view this content.
    This is very close to what I want, so thank you for your response.
    But the correct answer for "S" that I want should be 4. As I don't want it to stop counting the occurrence til a day has been worked again.
    So K4 - O4 as in your spreadsheet would be one occurrence as a day hadn't been worked in between.

  8. #8
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,063

    Re: Counting Consecutive occurences a letter appears in a row

    Try this array formula out (using kvsrivasamurthy's excel sheet)

    =SUM(IF(FREQUENCY(IF(A4:R4="S",IF(A4:R4<>"",COLUMN(A4:R4))),IF(A4:R4<>"S",IF(A4:R4<>"",COLUMN(A4:R4)))),1))


    Array Formulae are a little different from ordinary formulas in that they MUST be confirmed by pressing CTRL+SHIFT+ENTER to activate the array, not just ENTER.

    You will know the array is active when you see curly braces { } appear around the outside of your formula. If you do not CTRL+SHIFT+ENTER you will (almost always) get an error message or an incorrect answer. Press F2 on that cell and try again.

    Don't type the curly braces yourself - it won't work...

  9. #9
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,063

    Re: Counting Consecutive occurences a letter appears in a row

    Here's the sheet with the formula in place.
    Attached Files Attached Files

  10. #10
    Registered User
    Join Date
    07-24-2015
    Location
    London
    MS-Off Ver
    2007
    Posts
    6

    Re: Counting Consecutive occurences a letter appears in a row

    Works perfectly! Very much appreciated for your help!

  11. #11
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,063

    Re: Counting Consecutive occurences a letter appears in a row

    You're welome and thanks for the rep...

  12. #12
    Forum Guru samba_ravi's Avatar
    Join Date
    07-26-2011
    Location
    Hyderabad, India
    MS-Off Ver
    Excel 2021
    Posts
    8,914

    Re: Counting Consecutive occurences a letter appears in a row

    Quote Originally Posted by Glenn Kennedy View Post
    Try this array formula out (using kvsrivasamurthy's excel sheet)

    =SUM(IF(FREQUENCY(IF(A4:R4="S",IF(A4:R4<>"",COLUMN(A4:R4))),IF(A4:R4<>"S",IF(A4:R4<>"",COLUMN(A4:R4)))),1))


    Array Formulae are a little different from ordinary formulas in that they MUST be confirmed by pressing CTRL+SHIFT+ENTER to activate the array, not just ENTER.

    You will know the array is active when you see curly braces { } appear around the outside of your formula. If you do not CTRL+SHIFT+ENTER you will (almost always) get an error message or an incorrect answer. Press F2 on that cell and try again.

    Don't type the curly braces yourself - it won't work...
    =SUM(IF(FREQUENCY(IF(A4:R4="S",IF(A4:R4<>"",COLUMN(A4:R4))),IF(A4:R4<>"S",IF(A4:R4<>"",COLUMN(A4:R4)))),1))
    I think "IF(A4:R4<>""," is not required
    Samba

    Say thanks to those who have helped you by clicking Add Reputation star.

+ 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. [SOLVED] appears a consecutive series
    By Dumy in forum Excel General
    Replies: 12
    Last Post: 07-21-2015, 02:47 PM
  2. Return Max Number of Consecutive Occurences of '4' or More
    By Brumbot in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 11-14-2014, 12:00 PM
  3. How to Count the # of consecutive occurences >2 in a row of data
    By bparrott in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-29-2013, 05:03 PM
  4. How do I count the number of consecutive occurences within a data range?
    By PhDScience in forum Excel Formulas & Functions
    Replies: 13
    Last Post: 08-07-2013, 11:01 PM
  5. Replies: 2
    Last Post: 02-25-2012, 06:41 AM
  6. Count Consecutive Occurences
    By ctrapper in forum Excel General
    Replies: 1
    Last Post: 11-17-2009, 11:51 AM
  7. Replies: 3
    Last Post: 09-29-2009, 06:42 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