+ Reply to Thread
Results 1 to 10 of 10

Finding Sequences and Highlighting them in different ways

  1. #1
    Registered User
    Join Date
    03-28-2007
    Posts
    16

    Finding Sequences and Highlighting them in different ways

    Hello everyone.

    i was wondering how to go about finding sequences and highlighting them.

    here's an example list:

    7600
    7601
    7602
    7603
    7604
    7608
    7609
    7610
    7611

    now i need to find 3 things in this list.

    1) how many 'batches' of sequences there are in this list. The numbers 7600 to 7604 are a consecutive sequence of five numbers followed by another sequence from 7608 to 7611. that makes two sequences. i need a formula for one cell that would specify how many sequences there are in a given list (in this case they're two sequences in this list).

    2) is there any formula that can allow me to see each sequence highlighted in a different color (or any way to differentiate the sequences so i can copy paste them easily?). Pretty sure i'd have to use conditional formating on the entire list to do so but am clueless as to the implementation.

    3) a formula for a single cell that can state the largest sequence in the list. in the list above the largest seuqnce is 5 numbers so that would be the value i'm looking for.
    Last edited by Danyal; 03-21-2009 at 05:54 AM.

  2. #2
    Forum Expert
    Join Date
    03-23-2004
    Location
    London, England
    MS-Off Ver
    Excel 2019
    Posts
    7,064

    Re: Finding Sequences and Highlighting them in different ways

    Conditional formatting from A2 downwards

    in A2 =IF(A2=A1+1) set one colour else set another colour
    This will highlight the change start of sequences but not the entire sequence themselves but its a start
    Regards
    Special-K

    Ensure you describe your problem clearly, I have little time available to solve these problems and do not appreciate numerous changes to them.

  3. #3
    Forum Expert
    Join Date
    06-18-2004
    Location
    Canada
    MS-Off Ver
    Office 2016
    Posts
    1,474

    Re: Finding Sequences and Highlighting them in different ways

    Assuming that A2:A10 contains the data, the data does not contain duplicates, and the data is sorted in ascending order, try...

    To count the number of consecutive occurrences:

    Please Login or Register  to view this content.
    To return the maximum consecutive occurrence:

    Please Login or Register  to view this content.
    Hope this helps!
    Last edited by Domenic; 03-18-2009 at 07:15 AM.

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

    Re: Finding Sequences and Highlighting them in different ways

    for number 3
    =MAX(FREQUENCY(IF(IF(ABS(A1:A99-A2:A100)=1,1,0)=1,ROW(A1:A99)),IF(IF(ABS(A1:A99-A2:A100)=1,1,0)<>1,ROW(A1:A99))))+1
    array entered will return count of longest seq in range a1:a100 adjust range to suit
    "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

  5. #5
    Registered User
    Join Date
    03-28-2007
    Posts
    16

    Re: Finding Sequences and Highlighting them in different ways

    thanks a lot MartinDwilson. the formula works like a charm! part number 3 is solved.

    Special-K and Domenic appreciate the help . would it be possible however to provide me with a solution that doesn't involve sorting the numbers prior to implementation of the formula.

    additionally i'd greatly aprpecaite it if someone could assist me with part 2 of my query. part 3 and 2 are the real crux of my dilemma as i'm required to verify and provide this data on a regular basis.

    many thanks for all the help so far

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

    Re: Finding Sequences and Highlighting them in different ways

    well you could do as in attached but if two sequences follow each other it will highlite both together but it may help .two ways shown 1/ 2 /3 series or alternatively a 3/2/1 sequence
    Attached Files Attached Files

  7. #7
    Forum Expert
    Join Date
    06-18-2004
    Location
    Canada
    MS-Off Ver
    Office 2016
    Posts
    1,474

    Re: Finding Sequences and Highlighting them in different ways

    Assuming that the data does not contain duplicates, try...

    D2:

    =MIN(A2:A100)

    E2:

    =MAX(A2:A100)

    F2, confirmed with CONTROL+SHIFT+ENTER:

    =SUM(IF(FREQUENCY(A2:A100,IF(ISNA(MATCH(ROW(INDIRECT(D2&":"&E2)),A2:A100,0)),ROW(INDIRECT(D2&":"&E2))))>1,1))

    G2, confirmed with CONTROL+SHIFT+ENTER:

    =IF(N(F2),MAX(FREQUENCY(A2:A100,IF(ISNA(MATCH(ROW(INDIRECT(D2&":"&E2)),A2:A100,0)),ROW(INDIRECT(D2&":"&E2))))),0)

    Hope this helps!

  8. #8
    Registered User
    Join Date
    03-28-2007
    Posts
    16

    Re: Finding Sequences and Highlighting them in different ways

    Both Formulas worked like a charm! thank you so much for your help guys :D

    i really apprecaite it. problem solved!

    p.s. martindwilson i hate to nitpick but is there a way that each sequence could be highlighted in alternating colors (green then blue then green again) to make it easier to differentiate? if not, no issues

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

    Re: Finding Sequences and Highlighting them in different ways

    thought of away of highliting first one of each sequence to be a different colour than rest of sequence
    see attached each dark green is start of new sequence
    Attached Files Attached Files
    Last edited by martindwilson; 03-20-2009 at 05:55 AM.

  10. #10
    Registered User
    Join Date
    03-28-2007
    Posts
    16

    Re: Finding Sequences and Highlighting them in different ways

    Wow thats perfect! thank you so much Martidwilson :D

    problem solved and marked (btw sorry about the late reply)

+ 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