+ Reply to Thread
Results 1 to 5 of 5

Find Sequences within a Row

  1. #1
    Registered User
    Join Date
    11-17-2010
    Location
    Nottingham
    MS-Off Ver
    Excel 2007
    Posts
    4

    Find Sequences within a Row

    Hi,

    I'm looking for a formula that will find the longest sequense in a column of numbers. For example:

    A1 - A10 are populated with either 1,2 or 3:

    1
    1
    2
    3
    3
    3
    3
    1
    2
    2

    I can see the longest sequences are:

    1 - 2
    2 - 2
    3 - 4

    How would I formulate this, as unfortunately I have more than 10 cells to check.

  2. #2
    Registered User
    Join Date
    08-12-2010
    Location
    Dublin
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: Find Sequences within a Row

    Quote Originally Posted by sammy2xx View Post
    Hi,

    I'm looking for a formula that will find the longest sequense in a column of numbers. For example:

    A1 - A10 are populated with either 1,2 or 3:

    1
    1
    2
    3
    3
    3
    3
    1
    2
    2

    I can see the longest sequences are:

    1 - 2
    2 - 2
    3 - 4

    How would I formulate this, as unfortunately I have more than 10 cells to check.

    Hello

    I would say there is a better way than this but anyway:

    In cell B1 enter 1. In B2 enter this formula:

    Please Login or Register  to view this content.

    Then drag that formula down however many rows you want (10 in the example you gave; so drag it from B2 to B10). What this formula does is increment by 1 if the cell in A matches the one above it, otherwise it resets to 1.

    You can find the biggest sequence by using the MAX function. E.g. here it would be:

    Please Login or Register  to view this content.

    Hopefully that does the trick.

  3. #3
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Find Sequences within a Row

    see attached this array formula in D1 dragged down will give the longest sequence of each number in col C (See link in my sig. "how to enter array formula"
    =MAX(FREQUENCY(IF($A$2:$A$11=C2,ROW($A$2:$A$11)),IF($A$2:$A$11<>C2,ROW($A$2:$A$11))))
    Attached Files Attached Files
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  4. #4
    Registered User
    Join Date
    11-17-2010
    Location
    Nottingham
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Find Sequences within a Row

    Quote Originally Posted by ReportMaker View Post
    Hello

    I would say there is a better way than this but anyway:

    In cell B1 enter 1. In B2 enter this formula:

    Please Login or Register  to view this content.

    Then drag that formula down however many rows you want (10 in the example you gave; so drag it from B2 to B10). What this formula does is increment by 1 if the cell in A matches the one above it, otherwise it resets to 1.

    You can find the biggest sequence by using the MAX function. E.g. here it would be:

    Please Login or Register  to view this content.

    Hopefully that does the trick.
    So simple! Thaks very much, does what I need fine.

  5. #5
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Find Sequences within a Row

    Have a look at your other post
    http://www.excelforum.com/excel-gene...-a-column.html

    Post #3 does a fair bit more that might be of interest.
    If you need any more information, please feel free to ask.

    However,If this takes care of your needs, please select Thread Tools from menu above and set this topic to SOLVED. It helps everybody! ....

    Also
    اس کی مدد کرتا ہے اگر
    شکریہ کہنے کے لئے سٹار کلک کریں
    If you are satisfied by any members response to your problem please consider using the small Star icon bottom left of their post to show your appreciation.

+ 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