+ Reply to Thread
Results 1 to 7 of 7

Count continuous occurences, restart counting when condition met, exclude conditions met

  1. #1
    Registered User
    Join Date
    12-04-2014
    Location
    sweden
    MS-Off Ver
    2010
    Posts
    5

    Count continuous occurences, restart counting when condition met, exclude conditions met

    Hi

    I'm trying to count the number of occurences in A column downwards. See attached *xlsx file with description. Column A only has 3 Values. "A", "B" and "C" in no particular pattern. There will be values inserted every day in A column, so the total number of rows is unknown. But it's ok to copy formula downwards ahead of time.
    The rules are:
    The counting occures in column B (and column C in *.xlsx example file). Values to be counted exists in column A.
    When counting value "A", the counting should restart counting downwards when encountering a value of "C".
    However, if it encounters a value of "B", it should skip it as if uninterrupted, and continue counting "A" until interrupted by a "C".

    So a series of values downwards A column should result in the following in the B column. Please see attached *.xlsx file for example

    Excelforum_count_contious_and_skipped - Copy.xlsx

    A - 1
    A - 2
    B -
    A - 3
    C -
    A - 1
    C -
    A - 1
    B -
    A - 2
    A - 3
    A - 4

    I've tried Countif and IF(S) and searched a lot, but I could only partially solve it. Is it doable in formulas?

    Regards
    Last edited by onni; 01-13-2024 at 06:53 PM. Reason: Solved

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,953

    Re: Count continuous occurences, restart counting when condition met, exclude conditions m

    Administrative Note:

    Welcome to the forum.

    Is your forum profile showing the Excel PRODUCT that you need this to work for?

    Members will tailor the solutions they offer to the Office PRODUCT (Excel, NOT Windows) that you have. Please check that your forum profile is up-to-date in this respect. If you aren't sure, in Excel go to File | Account and report what it says below the MS logo at the top of that page. If your product is for Mac, please also state this.

    The three most recent Excel products are Excel 2019, Excel 2021 and MS365 - if you are using MS365, please give this name along with the version number in your profile (e.g. MS365 Version 2306). This is in the About Excel section further down the Account page.

    Thanks.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  3. #3
    Forum Guru HansDouwe's Avatar
    Join Date
    06-21-2022
    Location
    Nederland
    MS-Off Ver
    365 V2403 (Build 17330.20000)
    Posts
    6,435

    Re: Count continuous occurences, restart counting when condition met, exclude conditions m

    This solution works in Excel 2007 and newer:

    Please try in B2 and copy down:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    and try in C2 and copy down:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Last edited by HansDouwe; 01-13-2024 at 07:58 AM.

  4. #4
    Registered User
    Join Date
    12-04-2014
    Location
    sweden
    MS-Off Ver
    2010
    Posts
    5

    Re: Count continuous occurences, restart counting when condition met, exclude conditions m

    Wow Thanks !!
    It worked perfectly. Now I'm just trying to understand it

    Again, many thanks for this solution. It helped me a lot.

    Cheers



    Ps I tried later in D column to find Values in B column (or C column ) above value 2 then condition (Text for example), but it returned True also when it was less than 2. I managed to work around that though so all is good . Any ideas why that might happen?
    Formula: copy to clipboard
    Please Login or Register  to view this content.

  5. #5
    Forum Guru HansDouwe's Avatar
    Join Date
    06-21-2022
    Location
    Nederland
    MS-Off Ver
    365 V2403 (Build 17330.20000)
    Posts
    6,435

    Re: Count continuous occurences, restart counting when condition met, exclude conditions m

    You are Welcome!

    Thanks for the feedback and glad to have helped.

    Without seeing a workbook, I have no idea why =B2>2 returns true when it was less than 2.

    =B2>2 returns TRUE if B2>2 or (if B2 = not numeric and B2 is not empty) (B2>2 returns also TRUE if a formula in B2 returns "".)
    =B2>2 returns FALSE if B2 equal to or less than B2 or if B2 is empty (if there is a formula in B2 the cell is never empty, even if the formula returns "").

  6. #6
    Registered User
    Join Date
    12-04-2014
    Location
    sweden
    MS-Off Ver
    2010
    Posts
    5

    Re: Count continuous occurences, restart counting when condition met, exclude conditions m

    Quote Originally Posted by HansDouwe View Post
    You are Welcome!
    (if there is a formula in B2 the cell is never empty, even if the formula returns "").
    I believe this to be the answer. I use the same workbook as in this thread, just added "=IF(B2>2;1;0)" to D2 and copy downwards. It returns "True",(1) on cells that have formulas in them instead of the expected only if the cell has a value higher than 2. It would be nice of it didn't but I worked my way around that anyways

    Cheers

  7. #7
    Forum Guru HansDouwe's Avatar
    Join Date
    06-21-2022
    Location
    Nederland
    MS-Off Ver
    365 V2403 (Build 17330.20000)
    Posts
    6,435

    Re: Count continuous occurences, restart counting when condition met, exclude conditions m

    If you want 1 only when the value is a number higher than 2 please try
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    . If there is in B2 a formula that returns "", this formula will then return 0 in this case.

+ 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] count and restart when condition meet
    By pedersenn in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 10-03-2022, 04:37 AM
  2. [SOLVED] Restart count function after meeting condition
    By Jepri in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 12-18-2017, 03:38 AM
  3. vba code for count restart formula if condition
    By pedersenn in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 09-18-2017, 02:29 AM
  4. [SOLVED] Trying to count occurences if 2 conditions are met
    By Mangesh Yadav in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 09-06-2005, 07:05 AM
  5. Trying to count occurences if 2 conditions are met
    By NLithgow in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 01:05 AM
  6. [SOLVED] Trying to count occurences if 2 conditions are met
    By NLithgow in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 09-05-2005, 11:05 PM
  7. count up the occurences of non continuous value
    By koala in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-13-2005, 06:44 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