I need to count the largest string of cells that contains negative numbers in consecutive cells. See attached file. I hard coded column P.
Last edited by Scorpvin; 09-09-2008 at 02:54 PM.
No attachment?
Martin
Eighty Twenty Spreadsheet Automation http://homepage.ntlworld.com/martin.rice1/ for all your Excel customisation and consulting needs.
If my solution has saved you time and/or money, please consider donating to Cancer Research UK.
Using your posted workbook, this ARRAY FORMULA (committed with
CTRL+SHIFT+ENTER, instead of just ENTER) seems to work:
Copy Q1 and paste into Q2 and down as far as you need.Q1: =IF(COUNT(1/((A1:N1<0)*(B1:O1<0))),MAX(FREQUENCY( IF((A1:N1<0)*(B1:O1<0),COLUMN(A1:N1)),IF((A1:N1<0)*(B1:O1>=0), COLUMN(A1:N1))))+1,0)
Does that help?
It worked! Thank you!
Same sample, new problem.
If column A2 is negative I need to count the consecutive negative cells from A2 on. The result for Q2 is 4. For Q1 it would be 0 because A1 is positive.
Perhaps the same ARRAY FORMULA with a small tweak at the beginning....
Copy Q1 and paste into Q2 and down as far as you need.Q1: =IF((A1<0)*COUNT(1/((A1:N1<0)*(B1:O1<0))),MAX(FREQUENCY( IF((A1:N1<0)*(B1:O1<0),COLUMN(A1:N1)),IF((A1:N1<0)*(B1:O1>=0), COLUMN(A1:N1))))+1,0)
Does that help?
Thanks Ron. You're awesome! Have a blessed day!
If A1 is negative I need to count how many cells including are negative consecutive cells including A1. See attached.
Maybe this....regular formula:
Does that work for you?Q1: =IF(AND(A1<0,COUNTIF(A1:O1,">=0")),MATCH(0,INDEX((A1:N1<0)*(B1:O1<0),0),0),0)
Worked for row 1 and row 2. Unsuccessful for row 3.
Maybe =IF(A1 >= 0, 0, IF(AND(A1:O1 < 0), COUNT(A1:O1), MATCH(TRUE, A1:O1 > 0, 0) - 1) )
Still need some help.![]()
Perhaps:
=IF(COUNTIF(A1:O1,"<0")=COUNT(A1:O1),COUNT(A1:O1),IF(A1<0,MATCH(0,INDEX((A1:N1<0)*(B1:O1<0),0),0),0))
Microsoft MVP - Excel
Where there is a will there are many ways. Pick One!
Please read the Forum Rules
If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below
Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.
Preferred Charities: Lupus Canada and Sick Kids Foundation.
Feel Free to Donate if you want to, for the assistance you received today.
Thanks for all your help!![]()
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks