Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.newusers
external usenet poster
 
Posts: 18
Default Counting the largest number of consecutive 1's in a column

Hello, I have a column with 1000+ rows, each row having a 0 or 1. I'm
looking for a formula that will give me the highest number of consecutive
1's in the entire column. Just in case I didn't explain this correctly, here
is an example with a column fragment laid sideways:
0101100001111000111110010101. In this example the formula was produce a
result of 5. I'm not sure if this is possible. Thanks for your help, David


  #2   Report Post  
Posted to microsoft.public.excel.newusers
external usenet poster
 
Posts: 22,906
Default Counting the largest number of consecutive 1's in a column

How about a UDF?

Function FindMax(MyLetter As String, myRange _
As Range) As Integer
Dim C As Range, TempMax As Integer, _
fReset As Boolean
For Each C In myRange.Cells
If C.Value Like MyLetter Then
TempMax = TempMax + 1
Else
TempMax = 0
End If
FindMax = Application.WorksheetFunction _
.Max(FindMax, TempMax)
Next
End Function

=FindMax(1,A1:A1200)

If search item is text surround with double-quotes

e.g. =FindMax("a",range)


Gord Dibben MS Excel MVP


On Thu, 16 Nov 2006 22:26:14 -0000, "DavidS" wrote:

Hello, I have a column with 1000+ rows, each row having a 0 or 1. I'm
looking for a formula that will give me the highest number of consecutive
1's in the entire column. Just in case I didn't explain this correctly, here
is an example with a column fragment laid sideways:
0101100001111000111110010101. In this example the formula was produce a
result of 5. I'm not sure if this is possible. Thanks for your help, David


  #3   Report Post  
Posted to microsoft.public.excel.newusers
external usenet poster
 
Posts: 256
Default Counting the largest number of consecutive 1's in a column

By formula...

=MAX(FREQUENCY(IF(A2:A1000=1,ROW(A2:A1000)),IF(A2: A1000<1,ROW(A2:A1000))
))

....confirmed with CONTROL+SHIFT+ENTER, not just ENTER.

Hope this helps!

In article ,
"DavidS" wrote:

Hello, I have a column with 1000+ rows, each row having a 0 or 1. I'm
looking for a formula that will give me the highest number of consecutive
1's in the entire column. Just in case I didn't explain this correctly, here
is an example with a column fragment laid sideways:
0101100001111000111110010101. In this example the formula was produce a
result of 5. I'm not sure if this is possible. Thanks for your help, David

  #4   Report Post  
Posted to microsoft.public.excel.newusers
external usenet poster
 
Posts: 266
Default Counting the largest number of consecutive 1's in a column

"DavidS" skrev i en meddelelse
...
Hello, I have a column with 1000+ rows, each row having a 0 or 1. I'm
looking for a formula that will give me the highest number of consecutive
1's in the entire column. Just in case I didn't explain this correctly,
here is an example with a column fragment laid sideways:
0101100001111000111110010101. In this example the formula was produce a
result of 5. I'm not sure if this is possible. Thanks for your help, David


David

For a generic formula, which will look for any number or text entered in F1,
this array formula will do the job:

=MAX(FREQUENCY(IF(A1:A1000=F1,COUNTIF(OFFSET(A1,,, ROW(INDIRECT("1:"&ROWS(A1:A1000)))),"<"&F1)),ROW( INDIRECT("1:"&ROWS(A1:A1000)))-1))

To be confirmed with <Shift<Ctrl<Enter, also if edited later.

--
Best regards
Leo Heuser

Followup to newsgroup only please.




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Lookup function/sum function Secret Squirrel Excel Discussion (Misc queries) 24 November 21st 06 01:46 AM
Conditional Format as a MACRO Gunjani Excel Worksheet Functions 3 March 29th 06 05:22 PM
Need to Improve Code Copying/Pasting Between Workbooks David Excel Discussion (Misc queries) 1 January 6th 06 03:56 AM
Counting number of consecutive zeros at the end of a list [email protected] Excel Discussion (Misc queries) 2 September 22nd 05 12:47 PM
find the largest number in column Jack Excel Discussion (Misc queries) 5 April 13th 05 03:40 PM


All times are GMT +1. The time now is 03:05 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"