PC Review


Reply
Thread Tools Rate Thread

Counting consecutive negative value

 
 
Wallace
Guest
Posts: n/a
 
      20th Apr 2010
Hi,

I have a column with positive and negative numbers.
I need to count the largest number of consecutive negative numbers and don't
really know how to do it.
Thanks in advance.

Wallace
 
Reply With Quote
 
 
 
 
Joe User
Guest
Posts: n/a
 
      20th Apr 2010
"Wallace" wrote:
> I have a column with positive and negative numbers.
> I need to count the largest number of consecutive
> negative numbers and don't really know how to do it.


First, do you really want to count "consecutive negative numbers" per se, or
do you really want to count "number of consecutive cells with negative
numbers"?

In the first case, consecutive cells with values -1, -2 and -4 would count
as 2; in the second case, they would count as 3.

You should be able to adapt the following approach in either case. But if
you need assistance with that, you need to be more precise.

This might not be the best approach, but it's simple. I believe someone (T
"Biff" Valko?) was able to implement this approach in a single array formula.

Suppose your numbers are in A1:A30. In B1, put the formula =--(A1<0). And
put the following formula into B2 and copy down: =(A2<0)*(B1+1).

Then =MAX(B1:B30) is the largest number of consecutive cells with negative
numbers.

 
Reply With Quote
 
Harlan Grove
Guest
Posts: n/a
 
      20th Apr 2010
Wallace <Wall...@discussions.microsoft.com> wrote...
>I have a column with positive and negative numbers.
>I need to count the largest number of consecutive negative numbers and don't
>really know how to do it.


If you mean consecutive cells containing negative numbers, you could
do this in a single cell array formula. If the data were in a single
column, multiple row range named X, try the array formula

=MAX(LARGE((ROW(X)-MIN(ROW(X))+1)*(X<0)
*SIGN((MMULT(--(ROW(X)+1=TRANSPOSE(ROW(X))),--X)>=0)
+(ROW(X)=MAX(ROW(X)))),ROW(X)-MIN(ROW(X))+1)
-LARGE((ROW(X)-MIN(ROW(X)))*(X<0)
*SIGN((MMULT(--(ROW(X)-1=TRANSPOSE(ROW(X))),--X)>=0)
+(ROW(X)=MIN(ROW(X)))),ROW(X)-MIN(ROW(X))+1))

Simpler using ancillary formulas/cells.
 
Reply With Quote
 
RagDyeR
Guest
Posts: n/a
 
      20th Apr 2010
This *array* formula will return max number of consecutive negatives,
*BUT* ... will *not* allow empty or zero cells to break the negative
sequence count:

=MAX(FREQUENCY(IF(A1:A20<0,ROW(A1:A20)),IF(A1:A20>0,ROW(A1:A20))))


This *array* formula will return max number of consecutive negatives,
*BUT* ... will only count *actual* consecutive negative cells:

=MAX(FREQUENCY(IF(A1:A20<0,ROW(A1:A20)),IF(A1:A20>=0,ROW(A1:A20))))

--
Array formulas are entered using CSE, <Ctrl> <Shift> <Enter>, instead of the
regular <Enter>, which will *automatically* enclose the formula in curly
brackets, which *cannot* be done manually. Also, CSE *must* be used when
revising the formula.

--

HTH,

RD
=====================================================
Please keep all correspondence within the Group, so all may benefit!
=====================================================


"Wallace" <(E-Mail Removed)> wrote in message
news:AC0400E6-D90E-48B2-9D09-(E-Mail Removed)...
Hi,

I have a column with positive and negative numbers.
I need to count the largest number of consecutive negative numbers and don't
really know how to do it.
Thanks in advance.

Wallace


 
Reply With Quote
 
T. Valko
Guest
Posts: n/a
 
      20th Apr 2010
Try this array formula** :

=MAX(FREQUENCY(IF(A2:A25<0,ROW(A2:A25)),IF(A2:A25>=0,ROW(A2:A25))))

** array formulas need to be entered using the key combination of
CTRL,SHIFT,ENTER (not just ENTER). Hold down both the CTRL key and the SHIFT
key then hit ENTER.

--
Biff
Microsoft Excel MVP


"Wallace" <(E-Mail Removed)> wrote in message
news:AC0400E6-D90E-48B2-9D09-(E-Mail Removed)...
> Hi,
>
> I have a column with positive and negative numbers.
> I need to count the largest number of consecutive negative numbers and
> don't
> really know how to do it.
> Thanks in advance.
>
> Wallace



 
Reply With Quote
 
T. Valko
Guest
Posts: n/a
 
      20th Apr 2010
Explanation on how that formula works:

http://www.mrexcel.com/forum/showpos...78&postcount=9

--
Biff
Microsoft Excel MVP


"T. Valko" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Try this array formula** :
>
> =MAX(FREQUENCY(IF(A2:A25<0,ROW(A2:A25)),IF(A2:A25>=0,ROW(A2:A25))))
>
> ** array formulas need to be entered using the key combination of
> CTRL,SHIFT,ENTER (not just ENTER). Hold down both the CTRL key and the
> SHIFT key then hit ENTER.
>
> --
> Biff
> Microsoft Excel MVP
>
>
> "Wallace" <(E-Mail Removed)> wrote in message
> news:AC0400E6-D90E-48B2-9D09-(E-Mail Removed)...
>> Hi,
>>
>> I have a column with positive and negative numbers.
>> I need to count the largest number of consecutive negative numbers and
>> don't
>> really know how to do it.
>> Thanks in advance.
>>
>> Wallace

>
>



 
Reply With Quote
 
Steve Dunn
Guest
Posts: n/a
 
      20th Apr 2010
Slight variation, which doesn't need to be array entered:

=LARGE(FREQUENCY((A2:A25<0)*ROW(A2:A25),(A2:A25>=0)*ROW(A2:A25)),2)

MAX in this case would return the total number of negative values, so
LARGE(,2) is the figure we're looking for.



"T. Valko" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Try this array formula** :
>
> =MAX(FREQUENCY(IF(A2:A25<0,ROW(A2:A25)),IF(A2:A25>=0,ROW(A2:A25))))
>
> ** array formulas need to be entered using the key combination of
> CTRL,SHIFT,ENTER (not just ENTER). Hold down both the CTRL key and the
> SHIFT key then hit ENTER.
>
> --
> Biff
> Microsoft Excel MVP
>
>
> "Wallace" <(E-Mail Removed)> wrote in message
> news:AC0400E6-D90E-48B2-9D09-(E-Mail Removed)...
>> Hi,
>>
>> I have a column with positive and negative numbers.
>> I need to count the largest number of consecutive negative numbers and
>> don't
>> really know how to do it.
>> Thanks in advance.
>>
>> Wallace

>
>


 
Reply With Quote
 
Joe User
Guest
Posts: n/a
 
      20th Apr 2010
"Steve Dunn" <(E-Mail Removed)> wrote:
> Slight variation, which doesn't need to be array entered:
> =LARGE(FREQUENCY((A2:A25<0)*ROW(A2:A25),(A2:A25>=0)*ROW(A2:A25)),2)


Does not work in a number of specific cases. For example, when A2:A25
contains only negative numbers. For another example, 12 consecutive
negative numbers, then zero, then 11 consecutive negative numbers.

Interestingly, using MAX instead of LARGE works in those cases. But MAX
does not work in random cases. I suspect for the same reason that LARGE
fails in the cases above.

Apparently, the problem is: as written above, the first FREQUENCY parameter
contains zeroes for cells where the condition is false. Those increase the
"bin" for the first row that meets the condition A2:A25>=0.

In contrast, with the array formula using IF(A2:A25<0,ROW(A2:A25)), the
first FREQUENCY parameter contains FALSE truth values instead of zero.
Apparently, FREQUENCY ignores truth values as well as blank and text cells.
(Not documented in the Excel 2003 offline Help page.)


----- original message -----

"Steve Dunn" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Slight variation, which doesn't need to be array entered:
>
> =LARGE(FREQUENCY((A2:A25<0)*ROW(A2:A25),(A2:A25>=0)*ROW(A2:A25)),2)
>
> MAX in this case would return the total number of negative values, so
> LARGE(,2) is the figure we're looking for.
>
>
>
> "T. Valko" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> Try this array formula** :
>>
>> =MAX(FREQUENCY(IF(A2:A25<0,ROW(A2:A25)),IF(A2:A25>=0,ROW(A2:A25))))
>>
>> ** array formulas need to be entered using the key combination of
>> CTRL,SHIFT,ENTER (not just ENTER). Hold down both the CTRL key and the
>> SHIFT key then hit ENTER.
>>
>> --
>> Biff
>> Microsoft Excel MVP
>>
>>
>> "Wallace" <(E-Mail Removed)> wrote in message
>> news:AC0400E6-D90E-48B2-9D09-(E-Mail Removed)...
>>> Hi,
>>>
>>> I have a column with positive and negative numbers.
>>> I need to count the largest number of consecutive negative numbers and
>>> don't
>>> really know how to do it.
>>> Thanks in advance.
>>>
>>> Wallace

>>
>>

>


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Counting consecutive cells OM Microsoft Excel Discussion 3 31st Jul 2011 10:36 AM
Counting Consecutive Instances =?Utf-8?B?Y2FybA==?= Microsoft Excel Worksheet Functions 3 24th Sep 2007 07:08 PM
count the # of consecutive negative #'s in a range newToExcel Microsoft Excel Misc 5 13th Nov 2005 01:14 AM
Counting consecutive cells =?Utf-8?B?bmVpbA==?= Microsoft Excel Misc 5 17th Nov 2004 07:55 AM
Count consecutive cells if negative deacs Microsoft Excel Misc 3 31st Dec 2003 04:36 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:08 PM.