|
-
Apr 1st, 2005, 01:51 PM
#1
Thread Starter
Hyperactive Member
*Resolved* Determining Longest Run of Consecutive Numbers
Hi all,
How would I get Excel to determine the longest 'run' of a given number in a list of numbers? E.g. suppose I have the following data in column A:
24
34
0
12
0
0
67
54
0
0
0
99
Now suppose I want Excel to look at that data and tell me what the longest consecutive run of zero's are. In this case it would be 3 zero's. But how does I do this?
Thanks
-Rob
Last edited by TheRobster; Apr 5th, 2005 at 10:44 AM.
-
Apr 1st, 2005, 02:51 PM
#2
Re: MS Excel Question
No easy to do this other then a loop and a counter.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Apr 1st, 2005, 03:13 PM
#3
Thread Starter
Hyperactive Member
Re: MS Excel Question
Hi RobDog,
Can you elaborate please? I don't know what you mean.
*Edit* The number I want to look at will always be zero, if this makes it any easier to do.
Thanks
-Rob
-
Apr 1st, 2005, 03:58 PM
#4
Re: MS Excel Question
Something like iterating through the cells like so.
VB Code:
dim i as integer
dim iPrev as integer
For i = 1 to ActiveSheet.Cells.Range.SpecialCells(xlTypeCellLastCell).Row
If Cells(i, 1).Value = 0 then
'increment a continuity counter.
if iPrev = i - 1 then
'add to an array or some list or continuous rows.
endif
endif
next
I just typed it in the reply box so it probably has errors but it should get you started.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Apr 5th, 2005, 10:43 AM
#5
Thread Starter
Hyperactive Member
Re: MS Excel Question
Obtained a solution from another forum. Just in case anyone needs a similar one in future, here it is:
I'm not sure if this will do, but try the following...
1) Enter the text value 'End' at the end of your list of numbers, in this case A13.
2) Enter the following formula in B1, and copy down:
=IF(A1=0,MATCH(TRUE,A1:A13<>0,0)-1,"")
...confirmed with CONTROL+SHIFT+ENTER, not just ENTER.
3) Enter the following formula in C1:
=MAX(B1:B12)
Notice that the range used by the MATCH function includes A13, which contains the text value 'End'. You could always choose to hide this value using 'Conditional Formatting', if you wish.
Hope this helps!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|