+ Reply to Thread
Results 1 to 24 of 24

Formula to count rows equals to zero but without mentioning its range

  1. #1
    Registered User
    Join Date
    06-19-2013
    Location
    brazil
    MS-Off Ver
    Excel 2007
    Posts
    64

    Formula to count rows equals to zero but without mentioning its range

    Please, I need a formula to count how many cells are equal to zero before some.
    This is for a group of lateral columns.
    I will drag the formula, so that it shows this information again and again until the last row:

    A B
    1
    0
    0
    1 2 (there are 2 rows equal to zero until the previous number 1)
    0
    0
    0
    1 3 (there are 3 rows equal to zero until the previous number 1)
    0
    1 1 (there is 1 row equal to zero until the previous number 1)

    Something like (in B2):
    =IF(B2<>0,(COUNT HOW MANY ROWS ARE EQUAL TO ZERO UNTILL PREVIOUS NUMBER<>0),"")

    But I don't want to define how many rows there can be between the numbers different of 0, could be 1 or 500 or more.
    How to do this without mentioning its range?

  2. #2
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Formula to count rows equals to zero but without mentioning its range

    How about something like this:

    0.....
    0.....
    0.....3
    1.....
    0.....
    0.....2
    1.....
    0.....
    0.....2


    Enter this formula in B2 and copy down as needed:

    =IF(A2=1,"",IF(OR(A2<>A3,A3=""),COUNTIF(A$2:A2,0)-SUM(B$1:B1),""))

    Note how the formula references cell B1. B1 must not contain a number!
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  3. #3
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Formula to count rows equals to zero but without mentioning its range

    If you enter that formula in cell B2 you'll get a circular reference warning.

  4. #4
    Valued Forum Contributor
    Join Date
    05-20-2013
    Location
    Ohio, USA
    MS-Off Ver
    Excel 2013
    Posts
    941

    Re: Formula to count rows equals to zero but without mentioning its range

    Quote Originally Posted by Tony Valko View Post
    If you enter that formula in cell B2 you'll get a circular reference warning.
    Had the formula right the first time, for B2 down (I think, can't remember exactly what the formula was as I edited it). Anyway...

    In B1 enter...

    =IF(A1<>0,0,"")

    In B2 and down enter...

    =IF(A2<>0,ROW()-SUM(B$1:B1)-COUNT(B$1:B2),"")
    Last edited by jhren; 07-19-2013 at 09:51 PM.

  5. #5
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Formula to count rows equals to zero but without mentioning its range

    Same thing...

    In B2 and down enter...

    =IF(A2<>0,ROW()-SUM(B$1:B1)-COUNT(B$1:B2),"")
    The formula is being entered in a cell that the formula references resulting in a circular reference.

  6. #6
    Valued Forum Contributor
    Join Date
    05-20-2013
    Location
    Ohio, USA
    MS-Off Ver
    Excel 2013
    Posts
    941

    Re: Formula to count rows equals to zero but without mentioning its range

    I thought about that... but I don't get a circular reference warning.

    Here's an alternative...

    =IF(A2<>0,ROW()-SUM(B$1:B1)-COUNT(B$1:B1)-1,"")
    Last edited by jhren; 07-19-2013 at 10:08 PM.

  7. #7
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Formula to count rows equals to zero but without mentioning its range

    Enter a 1 in cell A2.

    Now do you get the warning?

  8. #8
    Valued Forum Contributor
    Join Date
    05-20-2013
    Location
    Ohio, USA
    MS-Off Ver
    Excel 2013
    Posts
    941

    Re: Formula to count rows equals to zero but without mentioning its range

    Quote Originally Posted by Tony Valko View Post
    Enter a 1 in cell A2.

    Now do you get the warning?
    No.....???

  9. #9
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Formula to count rows equals to zero but without mentioning its range

    Hmmm...

    Do you have iterative calculation enabled?

    File>Options>Formulas>Calculation Options>Enable iterative calculation

  10. #10
    Valued Forum Contributor
    Join Date
    05-20-2013
    Location
    Ohio, USA
    MS-Off Ver
    Excel 2013
    Posts
    941

    Re: Formula to count rows equals to zero but without mentioning its range

    Yes....???

    max iterations 100
    max change 0.01

  11. #11
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Formula to count rows equals to zero but without mentioning its range

    Normally, you DON'T want that setting enabled. That's for very specialized math calculations.

    If you uncheck that setting then you'll get the circular reference warning.

  12. #12
    Valued Forum Contributor
    Join Date
    05-20-2013
    Location
    Ohio, USA
    MS-Off Ver
    Excel 2013
    Posts
    941

    Re: Formula to count rows equals to zero but without mentioning its range

    I don't remember ever enabling it. I do know what iterations are... but I always thought that it was enabled by default when I installed. Should I disable it?

  13. #13
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Formula to count rows equals to zero but without mentioning its range

    Quote Originally Posted by jhren View Post
    Should I disable it?
    Yes, disable it.

  14. #14
    Registered User
    Join Date
    06-19-2013
    Location
    brazil
    MS-Off Ver
    Excel 2007
    Posts
    64

    Re: Formula to count rows equals to zero but without mentioning its range

    Tony, I've tried your formula and it works fine:
    =IF(A2=1,"",IF(OR(A2<>A3,A3=""),COUNTIF(A$2:A2,0)-SUM(B$1:B1),""))

    Thank you.
    But, I realise that it could be better for me if slightly modfifed.

    I've tried this:
    =IF(A2=1,"",IF(OR(A2<>A3,A3=""),(COUNTIF(A$2:A2,0)+1)-SUM(B$1:B1),""))

    Or:
    =IF(A2=1,"",IF(OR(A2<>A3,A3=""),(COUNTIF(A$2:A2,0)-(SUM(B$1:B1)-1),""))

    To have the numbers in column B plus 1 (the first number doesn't have to be exact, the most important are the last ones), like:
    0.....
    0.....
    0.....
    1.....4
    0.....
    0.....
    1.....3
    0.....
    0.....2

    But that's not working.
    If you could show how to alterate the formula.

  15. #15
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Formula to count rows equals to zero but without mentioning its range

    Why are you adding the +1?

    Isn't your intention to count the consecutive 0s?

  16. #16
    Valued Forum Contributor
    Join Date
    05-20-2013
    Location
    Ohio, USA
    MS-Off Ver
    Excel 2013
    Posts
    941

    Re: Formula to count rows equals to zero but without mentioning its range

    Quote Originally Posted by dualaudio454252 View Post
    ...
    If you could show how to alterate the formula.
    Try this one in B1 down...

    =IF(OR(A1=1,A2=""),COUNTIF(A$1:A1,0)-IFERROR(SUM(INDIRECT("B1:B"&ROW()-1)),0),"")


    ...and as Tony brings up, this is to count immediately preceding zero(es).

  17. #17
    Registered User
    Join Date
    06-19-2013
    Location
    brazil
    MS-Off Ver
    Excel 2007
    Posts
    64

    Distance between 2 not empty cells

    Please, I have another thread:
    http://www.excelforum.com/excel-form...02#post3330702

    But I decided to start a new thread.
    Cause that's another point and I've spent 1 day searching into this and another forums, and trying to change some solutions to what I need.

    I need to know the distance between 2 not empty cells in the same column.
    The first cell may have a text (or number) or not.
    And the distance may vary from 1 to 5 to 500 or more.
    Like:

    A B

    peanut (this one don't show a number, cause there's no other occurrence before)


    tomato 3






    banana 7



    basket 4

    That's it.

  18. #18
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,592

    Re: Distance between 2 not empty cells

    use this in B2 (if your data start from A1, anyway one row down):

    Formula: copy to clipboard
    Please Login or Register  to view this content.

  19. #19
    Registered User
    Join Date
    06-19-2013
    Location
    brazil
    MS-Off Ver
    Excel 2007
    Posts
    64

    Smile Re: Distance between 2 not empty cells

    Zbor, I've tried your formula and it works.
    Thank you!!!!!

    But, later, I blended your formula and the one of Tony Valko in the other thread to make this in B2:

    =IF(A2<>"",ROW()-SUM(B$1:B1),"")

    Which is even simpler!

    Of course, I just come to this after you, Zbor, and Tony Valko helped me!

    Thank you so much for your efforts!!!!!!
    Attached Images Attached Images
    Last edited by dualaudio454252; 07-21-2013 at 01:49 PM. Reason: I didn't attached the image

  20. #20
    Registered User
    Join Date
    06-19-2013
    Location
    brazil
    MS-Off Ver
    Excel 2007
    Posts
    64

    Re: Formula to count rows equals to zero but without mentioning its range


  21. #21
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Distance between 2 not empty cells

    You're welcome. We appreciate the feedback!

  22. #22
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Formula to count rows equals to zero but without mentioning its range

    dualaudio,

    As per forum rule 5, you shouldnt create duplicate threads. Have merged them for now, but please keep in mind for future.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  23. #23
    Registered User
    Join Date
    06-19-2013
    Location
    brazil
    MS-Off Ver
    Excel 2007
    Posts
    64

    Re: Formula to count rows equals to zero but without mentioning its range

    I guessed I was doing exactly what should be better, but thank you for the advice!

  24. #24
    Registered User
    Join Date
    06-19-2013
    Location
    brazil
    MS-Off Ver
    Excel 2007
    Posts
    64

    Re: Formula to count rows equals to zero but without mentioning its range

    I guess this way is more appropriate to what I really need:

    http://www.excelforum.com/excel-form...51#post3333551

    Thank you for 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. [SOLVED] Countifs to count a row equals another row
    By ncurran217 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 03-13-2013, 12:06 PM
  2. need formula for a range of values equals another value
    By missmiller in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 07-27-2012, 08:22 AM
  3. Replies: 2
    Last Post: 03-30-2010, 12:41 PM
  4. Count if the value equals
    By akbar in forum Excel General
    Replies: 3
    Last Post: 02-27-2008, 11:12 PM
  5. if a:a (range) equals january and c:c equals gas then add g:g ($)
    By BCOz in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 12-29-2005, 03:45 PM

Tags for this Thread

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.6.0 RC 1