+ Reply to Thread
Results 1 to 6 of 6

Counting number of 1s in a row until blank cell is reached.

  1. #1
    Registered User
    Join Date
    08-12-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    2

    Counting number of 1s in a row until blank cell is reached.

    Hello everyone,

    Besides being a casual user of Excel, also the use of a forum is new to me, so if you feel my post doesn't belong here, please advise.

    I am currently in an internship for a Dutch research company which investigates the labor market (in this case, unemployment spells), and my job is to combine data from several years and make the data easier to use. However, I am having an issue that I can't seem to resolve by myself, despite Googling for at least 1 hour. Hopefully, I came to the right place.

    Anyway, the situation is as follows. My Excel file contains header columns with dates, i.e. Jan2003, Feb2003, Mar2003 etc. If an individual is unemployed in a certain month, the value of the cell is 1, otherwise it's empty. What I eventually want to create is just 2 columns per unemployment spell: one column with the header 'Start of UE Spell 1' and the other 'Duration of UE Spell 1'. The main problem here is duration. I cannot simply sum all 1s, because an individual might have more than one unemployment spell during the observed period. Hence, I want to count the number of 1s in a row until a blank cell is reached.

    I did try out the formula in this thread, but somehow it seems to only work when the first 1 is in the very first column.

    Probably, my describing skills are not perfect, so I attached a small example. In the cells I marked blue, you find the answer that the correct formula should give me. As I have thousands of observations, it would save me many days of work doing this manually if one of you happens to know a formula that works.

    Thank you very very much for any help in advance.

    PS. In case it matters, I am using Excel 2010.
    Attached Files Attached Files

  2. #2
    Forum Expert dilipandey's Avatar
    Join Date
    12-05-2011
    Location
    Dubai, UAE
    MS-Off Ver
    1997 - 2016
    Posts
    8,191

    Re: Counting number of 1s in a row until blank cell is reached.

    Hi Wjhansen,

    Welcome to the forum.

    Basis the title provided by you, use below formula to count 1s until a blank cell is reached :-

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    This is an array formula and need to be entered with key combination ctrl + shift + Enter

    see attached:- count 1s till first blank.xlsx


    Regards,
    DILIPandey

    <click on below 'star' if this helps>
    DILIPandey, Excel rMVP
    +919810929744 (India), +971528225509 (Dubai), dilipandey@gmail.com

  3. #3
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Counting number of 1s in a row until blank cell is reached.

    Hi,
    O2:
    =MATCH(TRUE,INDEX(OFFSET(C2:N2,0,MATCH(1,C2:N2,FALSE))="",0),0)
    P2:
    IF(COUNTIF(C2:N2,1)=O2,0,12-COUNTBLANK(C2:N2)-O2)

    copied down as necessary
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  4. #4
    Registered User
    Join Date
    08-12-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: Counting number of 1s in a row until blank cell is reached.

    Thank you very much guys! I was in quite a bit of stress since yesterday because of this, and I'm very grateful you managed to help me out.

    I ended up using Richard Buttrey's formulas, as those were easiest to use for me, and they work perfectly. Thanks again!

  5. #5
    Registered User
    Join Date
    04-23-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    1

    Re: Counting number of 1s in a row until blank cell is reached.

    Thanks for this, have been racking my brain trying to reolve a similar issue, ahve just saved me hours of work.

  6. #6
    Forum Expert dilipandey's Avatar
    Join Date
    12-05-2011
    Location
    Dubai, UAE
    MS-Off Ver
    1997 - 2016
    Posts
    8,191

    Re: Counting number of 1s in a row until blank cell is reached.

    Sounds great Marclwms Cheers

    welcome to forum.


    Regards,
    DILIPandey
    <click on below * if this helps>

+ 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