+ Reply to Thread
Results 1 to 12 of 12

Count Consecutive Values

  1. #1
    Registered User
    Join Date
    10-06-2009
    Location
    Diemen, The Netherlands
    MS-Off Ver
    Excel 2007
    Posts
    87

    Thumbs up Count Consecutive Values

    Good day everyone,

    I'm trying to use this formula to count consecutive values but somehow it doesn't work properly.
    Does anyone see what's going wrong here or is there a better formula to this?


    Thank you for any help offered,


    Roberto Lucesi


    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by roberto1111; 02-05-2010 at 05:34 AM.

  2. #2
    Registered User
    Join Date
    10-06-2009
    Location
    Diemen, The Netherlands
    MS-Off Ver
    Excel 2007
    Posts
    87

    Re: Count Consecutive Values

    bump
    ......

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

    Re: Count Consecutive Values

    If you're happy to use a UDF perhaps:

    Please Login or Register  to view this content.

    the above, stored in a Module in a Macro enabled file, could be called from cell A1 using:

    Please Login or Register  to view this content.

    using your example data this would return 2
    (note it's geared to look in upwards direction only - could be altered)

    You have the option of passing TRUE or FALSE as a 2nd parameter where FALSE would stipulate that blanks were not to be ignored (default is TRUE - ignore blanks)

  4. #4
    Valued Forum Contributor rwgrietveld's Avatar
    Join Date
    09-02-2008
    Location
    Netherlands
    MS-Off Ver
    XL 2007 / XL 2010
    Posts
    1,671

    Re: Count Consecutive Values

    It depends on what you think are "consecutive values". By the transpose you now look at
    how many are consecutive to the first +
    how many are consecutive to the second +
    .....
    how many are consecutive to the last.

    With 122 you have
    0,0,0 + 1,0,0 + 1,0,0 (actually twice the 1-2 combination)
    With 123 you have
    0,0,0 + 1,0,0 + 0,1,0 (1-2 and 2-3 combination)
    Looking for great solutions but hate waiting?
    Seach this Forum through Google

    www.Google.com
    (e.g. +multiple +IF site:excelforum.com/excel-general/ )

    www.Google.com
    (e.g. +fill +combobox site:excelforum.com/excel-programming/ )

    Ave,
    Ricardo

  5. #5
    Valued Forum Contributor rwgrietveld's Avatar
    Join Date
    09-02-2008
    Location
    Netherlands
    MS-Off Ver
    XL 2007 / XL 2010
    Posts
    1,671

    Re: Count Consecutive Values

    And this:

    =SUM(--(A2:A5-OFFSET(A2:A5,1,0)=-1))

    CSE (array function)

  6. #6
    Registered User
    Join Date
    10-06-2009
    Location
    Diemen, The Netherlands
    MS-Off Ver
    Excel 2007
    Posts
    87

    Re: Count Consecutive Values

    Thank you both for your help!,


    DonkeyOte, how should I modify the code+formula so it will also count 'reverse consecutive values'


    3 < the result
    6
    1 < 'reverse consecutive value' of 2
    2 <
    2

    8

    11
    15
    16

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

    Re: Count Consecutive Values

    Roberto, I am not sure my UDF actually does what you want...

    What is you're looking to do exactly...

    Are you looking to iterate each number in the data set and see how many other numbers within the dataset are within 1 of the value being iterated and sum the results of all iterations

    or

    Are you looking to cycle the values and see how many values follow the prior value ?

    Perhaps a bigger sample may help ?

  8. #8
    Registered User
    Join Date
    10-06-2009
    Location
    Diemen, The Netherlands
    MS-Off Ver
    Excel 2007
    Posts
    87

    Re: Count Consecutive Values

    Yes exactly, I'm looking to iterate each number in the data set and see how many other numbers within the dataset are within 1 of the value being iterated and sum the results of all iterations.

    A bigger example just would be more datasets (columns) next to each other where I want see the results from. (I hope I've explained it more clear now).


    Thanks!

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

    Re: Count Consecutive Values

    Still not sure I follow... wouldn't the answer be 6 ?

    Please Login or Register  to view this content.

    I say 6 based on:

    1: 2 instances of 2
    2: 1 instance of 1
    2: 1 instance of 1
    15: 1 instance of 16
    16: 1 instance of 15

    Perhaps I'm missing the underlying point...

  10. #10
    Registered User
    Join Date
    10-06-2009
    Location
    Diemen, The Netherlands
    MS-Off Ver
    Excel 2007
    Posts
    87

    Re: Count Consecutive Values

    No you're right, the answer would indeed be 6, my mistake..


    I tried to set the formula but got an error message (I made a screen pic).

    I hope you can tell me what I'm doing wrong here


    Thanks!
    Attached Images Attached Images

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

    Re: Count Consecutive Values

    Sorry, I forgot to adapt from UK to Dutch format - you need to change the comma to semi-colon:

    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    10-06-2009
    Location
    Diemen, The Netherlands
    MS-Off Ver
    Excel 2007
    Posts
    87

    Re: Count Consecutive Values

    Right, that's it!

    Thanks again DonkeyOte!

+ 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