Counting consecutive numbers in a comma-separated list

mrc44

Board Regular
Joined
Aug 12, 2017
Messages
64
I tried to find a formula or a macro for this online but I couldn't find anything.

I need a way to calculate the consecutive numbers in a comma separated list. Thanks in advance.

Here is a sample data: ConsecutiveCount.xlsm

I'm using Excel 2016.

* In the sample file, I put the expected results in separate cells, but it can be in a single too.
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Please use the XL2BB add in to post your sample directly to the thread (link in my signature below), many people are unable to download linked files due to security restrictions.
 
Upvote 0
Thanks. this is what I did:

ConsecutiveCount.xlsm
ABCDEFGH
1DATA2 Consecutives3 Consecutives4 Consecutives5 consecutives6 consecutives7 consecutives8 consecutives
21,2,6,8,9,14,182
31,2,3,44
45,10,11,16,18,201
53,4,5,11,12,21,2313
610,13,14,15,16,171
7
Sheet1
 
Upvote 0
Having a list of numbers in one cell is not a good idea, it will be difficult to work with.

Is it possible that any given number could be repeated in any one cell?

Is there an absolute maximum number for the digits that appear in the cells? If we know that the numbers will always be less than 20 (as in the sample) then it can make things easier.
 
Upvote 0
there are no repetitions of numbers in the same cell. Yes, the number of cells is less than 20 in a cell.
 
Upvote 0
Yes, the number of cells is less than 20 in a cell.
That is actually incorrect, A5 in your example goes up to 23 (I looked too quickly and missed it when I was typing my earlier reply).
 
Upvote 0
I'm sorry, my mistake, I meant to say there will be less than 20 comma-separated values. so there are 7 values in A5. but this is just a sample. so there won't be any number higher than 20. thanks.
 
Upvote 0
With that in mind it should be possible with a reasonably simple formula. I'm not going to get chance now but will look at it tomorrow if it is not resolved by another member beforehand.
 
Upvote 0
As an example on row 5, it says 1 for 2 Consecutives, and 3 for 3 Consecutives.

Shouldn't those be 1 and 1? As in there is 1 pair of 2 consecutive numbers and 1 pair of 3 consecutive numbers?
 
Upvote 0
yes, sorry about that. it is 1 and 1. here is the corrected version:

ConsecutiveCount.xlsm
ABCDEFGH
1DATA2 Consecutives3 Consecutives4 Consecutives5 consecutives6 consecutives7 consecutives8 consecutives
21,2,6,8,9,14,182
31,2,3,44
45,10,11,16,18,201
53,4,5,11,12,21,2311
610,13,14,15,16,171
Sheet1
 
Upvote 0

Forum statistics

Threads
1,214,981
Messages
6,122,565
Members
449,089
Latest member
Motoracer88

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