[英]How do I Count cells in excel, starting with a cell that has a specified value?
The question is slightly confusing, so I will do my best to elaborate. 这个问题有些令人困惑,所以我会尽力加以阐述。 I have a series of cells in a row with all of the cells in the row with a value of 0 and one cell having a value of 1. I want to use the COUNT function to count all of the cells to the right of the cell that contains the value of 1, including that cell. 我在一行中有一系列单元格,该行中的所有单元格的值为0,而一个单元格的值为1。我想使用COUNT函数对单元格右边的所有单元格进行计数包含值1(包括该单元格)。 I would then use this number of counted cells in another equation. 然后,我将在另一个方程式中使用此数量的计数单元格。 Does anyone have any suggestions on how to do this? 有人对此有任何建议吗? I have tried using a lookup function inside of the count function, but it has not worked. 我试过在count函数中使用查找函数,但是没有用。 This is my closest guess: 这是我最接近的猜测:
=COUNT(Lookup(1,A1:J1):J1)
This results in an error. 这会导致错误。 Do I need to use VBA to make this work or should I be able to write an equation? 我需要使用VBA来完成这项工作还是应该写一个方程式? I appreciate the help, or if there are any other strategies that I can use to attain the result I am looking for. 我很感谢您的帮助,或者如果我可以使用其他任何方法来获得想要的结果。
Edit: I am adding in some sample data and expected results. 编辑:我正在添加一些示例数据和预期结果。 I am trying to count all of the cells to the right of the "1" including the cell containing the "1". 我正在尝试计算“ 1”右边的所有单元格,包括包含“ 1”的单元格。 So in this example, I would expect the formula to return "13" as there are 12 cells to the right of the "1" 因此,在此示例中,我希望公式返回“ 13”,因为“ 1”的右侧有12个单元格
You can use OFFSET() and MATCH(): 您可以使用OFFSET()和MATCH():
That last "50" is a bit of a guess since I'm not sure how far to the right you want to count... 最后一个“ 50”有点猜测,因为我不确定您要计算的右边有多远...
...and re-reading your question it's not clear if you only want to count values of 1 or if you also need to count other values as long as they're to the right of the first 1. ...并重新阅读您的问题,不清楚是只想计数1还是只需要计数其他值在第一个1的右边。
You can use this formula: 您可以使用以下公式:
=COUNTA(INDEX($A$1:$J$1,1,MATCH(1,$A$1:$J$1,0)):INDEX($A$1:$J$1,1,10))
The benefit to use this is it is not a volatile function, and it will also work for 1
appears in the last column. 使用它的好处是它不是易失性函数,并且也适用于最后一栏中出现的1
。
Assuming your range of 0
and 1
values is in row 2, starting from column B, use this formula in B3 and copy it across for as far as you need: 假设您的0
和1
值范围在第2行中,从B列开始,请在B3中使用此公式,并根据需要复制它:
=IFERROR(COUNT($B2:B2)+1-MATCH(1,$B2:B2,0),0)
You could also use a formula of 您还可以使用以下公式
=IF(A3>0,1+A3,IF(B2=1,1,0))
but that could cause issues if you have something in cell A3 itself. 但是如果您在A3单元格中有东西,可能会导致问题。
You can use "COUNTIF" formula to count number of occurrences of specific number in a range of cells. 您可以使用“ COUNTIF”公式来计算一系列单元格中特定数字的出现次数。
To count no of occurrences in a row. 连续计数没有发生的次数。
=COUNTIF(1:1,1) = COUNTIF(1:1,1)
If it is in a column then 如果在列中
=COUNTIF(A:A,1) = COUNTIF(A:A,1)
Hope you are looking for a countif function. 希望您正在寻找一个countif函数。
COUNTIF(A1:A10, 1)
The above function counts the cell that has value 1 within the range A1:A10 上面的函数计算范围A1:A10中值为1的单元格
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.