+ Reply to Thread
Results 1 to 8 of 8

Counting contiguous rows of numbers in a spreadsheet

  1. #1
    Registered User
    Join Date
    03-24-2014
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    4

    Counting contiguous rows of numbers in a spreadsheet

    Hi there,

    I've not really done any excel programming before, but I'm not aware of any functions that would allow me to achieve the following:

    I have data for the presence of fish (1 - present, 'blank' not present) at discreet time intervals (the columns), with each fish in the observation having its own separate row. Please see attached simplified example.fish_residency_data.jpg

    '1's in a contiguous line (i.e. without a blank space separating them) are treated as a single 'residency period', so in the example Fish 1 & 2 have a single residency period (fish 2 being there for less time than fish 1), and Fish 3 has two residency periods. I need to extract residency data from this table i.e. for each fish, how many residency periods and how long is each period (how many '1's in a contiguous line).

    Does anyone have a recommendation for how best to tackle this problem in excel please? Happy to provide more info if required.

    Many thanks,

    James

  2. #2
    Valued Forum Contributor
    Join Date
    03-22-2013
    Location
    Australia,NSW, Wirrimbi
    MS-Off Ver
    Excel 2013
    Posts
    1,057

    Re: Counting contiguous rows of numbers in a spreadsheet

    Hi..

    Something like this works on your sample data..

    It uses static ranges.. but can be adapted to be dynamic (more time periods etc)..

    I gotta go play basketball.. will do that if you need it later..

    Please Login or Register  to view this content.
    Attached Files Attached Files

  3. #3
    Registered User
    Join Date
    03-24-2014
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Counting contiguous rows of numbers in a spreadsheet

    Thanks man - hope basketball was good!

    Not sure if it needs to be dynamic, the real data I use has 50 time periods, and an unknown number of rows.

    Here is an section from my actual dataset: New Data example.xlsx
    (the day/eve column needs to be there, but don't worry about it)

    Ideally the output would give the length of each residency period in a separate cell on that same row.

    If you have time to look at it again I'd be really grateful.

    Thanks again,

    James

  4. #4
    Valued Forum Contributor
    Join Date
    03-22-2013
    Location
    Australia,NSW, Wirrimbi
    MS-Off Ver
    Excel 2013
    Posts
    1,057

    Re: Counting contiguous rows of numbers in a spreadsheet

    No worries.. can you show me (re attach a sample file).. exactly how you would like the end result to look like for the Sample data posted in post #3.

  5. #5
    Registered User
    Join Date
    03-24-2014
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Counting contiguous rows of numbers in a spreadsheet

    Thanks once again. Example attached, it would be useful to have the output on the original dataset as I'll probably pull it all out using a pivot table thereafter.

    Cheers,

    James

    Out example.xlsx

  6. #6
    Valued Forum Contributor
    Join Date
    03-22-2013
    Location
    Australia,NSW, Wirrimbi
    MS-Off Ver
    Excel 2013
    Posts
    1,057

    Re: Counting contiguous rows of numbers in a spreadsheet

    Hi.. Done..

    Press the "Do It!" button to see results..

    Please Login or Register  to view this content.
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    03-24-2014
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Counting contiguous rows of numbers in a spreadsheet

    You're a legend - great job - thanks so much.

    Could you just tell me how to paste the code/button into my own datasheet (it's the same format as the one you just did this for).

    Cheers,

    James

  8. #8
    Valued Forum Contributor
    Join Date
    03-22-2013
    Location
    Australia,NSW, Wirrimbi
    MS-Off Ver
    Excel 2013
    Posts
    1,057

    Re: Counting contiguous rows of numbers in a spreadsheet

    Hi..

    * Add a ActiveX CommandButton. You do this via the Developer Tab.. if this Tab is not enabled in the Ribbon Menu.. goto the Options and enable it.. it will open a whole new world to you...

    * In the Developer Tab.. click on Insert > Active X Controls > CommandButton. Place your button on your sheet in the position you want with a left click.

    * Then.. (Make Sure Design Mode) is enabled in the Developer Tab... and double click on the Command Button you just added.

    * Paste the code from Post # 6 (not including the 1st line(Private Sub....) and the last line(End Sub)).. as it will already be there..

    * Exit Design Mode (by pressing the Design mode button again).. and the button will now be active with the code attached to it..

+ 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. Counting Contiguous Cells if > 140
    By danpool in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 12-20-2012, 05:44 PM
  2. [SOLVED] How to delete multiple contiguous (and/or) non-contiguous rows, in an excel table
    By jimmalk in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-03-2012, 05:48 AM
  3. Replies: 2
    Last Post: 11-04-2012, 12:18 AM
  4. Counting rows in Excel spreadsheet.
    By Jim15 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-02-2006, 05:17 PM
  5. cells() and counting number or rows on spreadsheet
    By HeatherO in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 03-02-2005, 07:06 AM

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