Find consecutive strings of numbers from out of order list, and calculate which string is the longest

ollyhughes1982

Well-known Member
Joined
Nov 27, 2018
Messages
677
Office Version
  1. 365
Platform
  1. MacOS
Hi I am trying to find a solution to problem I want to solve on my parkrun results spreadsheet. The definition of the calculation I need to make is: 'The total streak of finish positions, but starting anywhere, in any order. e.g. If you have finished: 123, 120, 304, 122, 201, 121 It would be 4, since you have: 120,121,122 and 123.

I have just manually checked my 'floating finish position' from the 'Finishing Position #' (F) column in the 'All Completed Runs' worksheet of my parkrun spreadsheet, and the answer is 24 - running from 70th-93rd. If anyone might be able to find a way to achieve this in an Excel formula, I would be really grateful. I have tried and failed! I want to populate the yellow cell (B43) in the 'Summary' worksheet with the correct result. I would also like, if possible to put these sequences in a list in the 'All Completed Runs - FFP-I' worksheet (also highlighted yellow).

My file is here:
https://1drv.ms/x/s!AtIvkRgReIvwgTdNIGandjTeGGdr?e=vXp7cq

Thanks!

Also posted Find consecutive strings of numbers from out of order list, and calculate longest string
and here on Reddit
 
Last edited by a moderator:

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Someone else suggested as per below, which will likely work and is great, but would really like to try and achieve it without extra columns or vbA, if at all possible.

If your finishing positions are all in one column you will need a couple of helper columns to facilitate the calculation. Firstly you want a column of unique finishing positions sorted in ascending order. Assuming your finish positions are in column A, in Google Sheets, I'd use =SORT(UNIQUE(A1:A999)) and I'm sure Excel will have some similar functions.

Now you have your finish positions in column A and a sorted list of unique finish positions in, say, column B.

In column C we'll want to make a column that checks if the number in the column to the left is consecutive or not, so put a "0" in C1 because we know that's the start of a consecutive run, then in C2 the formula =IF(B2-B1=1,C1+1,0) will check if the next number down is consecutive; if it is it adds 1 to the run so it counts up and if it's not it'll put a zero to indicate the start of a new run. Then just drag that formula down for however many rows you need.

Finally, find the highest number in column C and add 1 using =MAX(C1:C999)+1
 
Upvote 0

Forum statistics

Threads
1,213,531
Messages
6,114,172
Members
448,554
Latest member
Gleisner2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top