Count number of consecutive numbers

Martin Coates

New Member
Joined
Nov 8, 2004
Messages
31
Hi All
I'm trying to work out a formula to count the number of consecutive numbers in a row of numbers e.g if I have a series of numbers, say 1, 3, 4 ,5 12, 15, 16 I want to know how many numbers are consecutive, in this example 3,4 +5 =3 consecutive numbers and 15 + 16 = 2 consecutive numbers. I've tried Frequency and Countif but can't seem to get the right result.
Any thoughts anyone?
Martin
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
I probably should have added that I'm only interested in the longest sequence of consecutive numbers, in the example this would be 3 (3, 4 +5) but there might be occasions where the sequence contains two runs of the same number.
 
Upvote 0
Like this? It is an array formula so should be entered without the {} but confirmed with Ctrl+Shift+Enter, not just Enter. If confirmed correctly, Excel will insert the {}.

Excel Workbook
ABC
113
23
34
45
512
615
716
8
Count Consecutive
 
Upvote 0
Hi Peter
Thank you for your reply but it hasn't quite worked. This may be because my data is stored horizontally and I've incorrectly adapted the formula.

Product Week 1 Week 2 Week 3 Week 4 Week 5 Week 6 Formula Result
XR1-12 5 8 9 10 38 53 3 =1+MAX(FREQUENCY(B2:F2-A2:E2=1,ROW(B2:F2)),IF(B2:F2-A2:E2<>1,ROW(B2:F2)))
XR1-18A 3 12 15 29 51 58 4 =1+MAX(FREQUENCY(B3:F3-A3:E3=1,ROW(B3:F3)),IF(B3:F3-A3:E3<>1,ROW(B3:F3)))
B400 CB 8 26 27 29 49 58 5 =1+MAX(FREQUENCY(B4:F4-A4:E4=1,ROW(B4:F4)),IF(B4:F4-A4:E4<>1,ROW(B4:F4)))
PRT4 29 33 43 45 49 56 6 =1+MAX(FREQUENCY(B5:F5-A5:E5=1,ROW(B5:F5)),IF(B5:F5-A5:E5<>1,ROW(B5:F5)))
KEY 2 10 19 28 29 31 7 =1+MAX(FREQUENCY(B6:F6-A6:E6=1,ROW(B6:F6)),IF(B6:F6-A6:E6<>1,ROW(B6:F6)))

Where have I gone wrong?
Cheers
Martin
 
Upvote 0
Where have I gone wrong?
:) A few things ..
- You are including column A in the check but column A is not numerical,
- You didn't make the change from ROWS to COLUMNS in the formula, and
- You have lost the IF() function from the original

Try this

Excel Workbook
ABCDEFGH
1ProductWeek 1Week 2Week 3Week 4Week 5Week 6Result
2XR1-125891038533
3XR1-18A312152951581
4B400 CB826272949582
5PRT42933434549561
6KEY210192829312
Count Consecutive (2)
 
Upvote 0
Peter, that's perfect, thank you. As you can probably tell I'm fairly new to excel, despite being 62 but they say you're never too old to learn something new.
Your help is much appreciated.
Cheers
Martin
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,242
Members
452,623
Latest member
russelllowellpercy

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