+ Reply to Thread
Results 1 to 13 of 13

Thread: Counting cells in a row that are less than 0

  1. #1
    Registered User
    Join Date
    09-29-2005
    Posts
    56

    Counting cells in a row that are less than 0

    I need to count the largest string of cells that contains negative numbers in consecutive cells. See attached file. I hard coded column P.
    Attached Files Attached Files
    Last edited by Scorpvin; 09-09-2008 at 02:54 PM.

  2. #2
    Forum Guru mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2007/2010
    Posts
    3,004
    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.

  3. #3
    Cheeky Forum Moderator Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2003, 2007, 2010
    Posts
    3,701

    Counting cells in a row that are less than 0

    Using your posted workbook, this ARRAY FORMULA (committed with
    CTRL+SHIFT+ENTER, instead of just ENTER) seems to work:

    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)
    Copy Q1 and paste into Q2 and down as far as you need.

    Does that help?
    Regards,

    Ron
    Microsoft MVP - Excel
    (Oct 2006 - Sep 2012)

    Click here to see the Forum Rules

  4. #4
    Registered User
    Join Date
    09-29-2005
    Posts
    56

    Thanks Ron but I have another

    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.

  5. #5
    Cheeky Forum Moderator Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2003, 2007, 2010
    Posts
    3,701

    Counting cells in a row that are less than 0

    Perhaps the same ARRAY FORMULA with a small tweak at the beginning....

    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)
    Copy Q1 and paste into Q2 and down as far as you need.

    Does that help?
    Regards,

    Ron
    Microsoft MVP - Excel
    (Oct 2006 - Sep 2012)

    Click here to see the Forum Rules

  6. #6
    Registered User
    Join Date
    09-29-2005
    Posts
    56
    Thanks Ron. You're awesome! Have a blessed day!

  7. #7
    Registered User
    Join Date
    09-29-2005
    Posts
    56

    If A1 is negative need to count how many consecutive

    If A1 is negative I need to count how many cells including are negative consecutive cells including A1. See attached.
    Attached Files Attached Files

  8. #8
    Cheeky Forum Moderator Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2003, 2007, 2010
    Posts
    3,701

    Count consecutive negative cells in a row, including Col_1

    Maybe this....regular formula:
    Q1: =IF(AND(A1<0,COUNTIF(A1:O1,">=0")),MATCH(0,INDEX((A1:N1<0)*(B1:O1<0),0),0),0)
    Does that work for you?
    Regards,

    Ron
    Microsoft MVP - Excel
    (Oct 2006 - Sep 2012)

    Click here to see the Forum Rules

  9. #9
    Registered User
    Join Date
    09-29-2005
    Posts
    56

    Did not work for row 3

    Worked for row 1 and row 2. Unsuccessful for row 3.
    Attached Files Attached Files

  10. #10
    Forum Guru shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2007, 2010
    Posts
    25,770
    Maybe =IF(A1 >= 0, 0, IF(AND(A1:O1 < 0), COUNT(A1:O1), MATCH(TRUE, A1:O1 > 0, 0) - 1) )

  11. #11
    Registered User
    Join Date
    09-29-2005
    Posts
    56

    Unhappy It did not work

    Still need some help.

  12. #12
    Forum Guru NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    32,636
    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.

  13. #13
    Registered User
    Join Date
    09-29-2005
    Posts
    56

    Smile Problem Solved

    Thanks for all your help!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Counting individual coloured cells that are merged.
    By JohnSan in forum Excel Programming
    Replies: 0
    Last Post: 05-06-2008, 01:11 PM
  2. Counting conditionally formatted cells
    By Nigel in forum Excel Worksheet Functions
    Replies: 8
    Last Post: 04-27-2008, 04:00 PM
  3. counting cells with data without counting duplicates
    By labettis in forum Excel General
    Replies: 2
    Last Post: 11-05-2007, 11:10 AM
  4. Counting - based on part of a cells contents
    By Paul Sheppard in forum Excel General
    Replies: 2
    Last Post: 09-17-2007, 11:35 AM
  5. Searching for and counting blank cells
    By guerilla in forum Excel General
    Replies: 1
    Last Post: 12-08-2006, 03:40 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0