如何计算 Excel 工作表中数据的行数?
我正在尝试计算电子表格中几列中至少包含一个非空白值的行数:即
row 1 has a text value in column A
row 2 has a text value in column B
row 3 has a text value in column C
row 4 has no values in A, B or C
公式将等于 3,因为行 1、2、& 3 至少一列中有文本值。同样,如果第 1 行的每列(A、B 和 C)中都有一个文本值,则这将被计为 1。
I am trying to count the number of rows in a spreadsheet which contain at least one non-blank value over a few columns: i.e.
row 1 has a text value in column A
row 2 has a text value in column B
row 3 has a text value in column C
row 4 has no values in A, B or C
The formula would equate to 3, because rows 1, 2, & 3 have a text value in at least one column. Similarly if row 1 had a text value in each column (A, B, & C) this would be counted as 1.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
使用公式,您可以做的是:
D2
)中,添加=COUNTA(A2:C2)
D4
)D5
中):=SUM(D2:D4)
With formulas, what you can do is:
D2
), add=COUNTA(A2:C2)
D4
in our example)D5
):=SUM(D2:D4)
如果您想要一个简单的衬线来为您完成所有操作(假设没有值,您意味着一个空白单元格):
如果没有值,您意味着该单元格包含 0
该公式的工作原理是首先将所有行相加A、B 和 C 列(如果需要计算更多行,只需增加范围内的列即可。例如
ROWS(A:A) + ROWS(B:B) + ROWS(C:C) + ROWS (D:D) + ... +行(Z:Z)
)。然后,该公式计算同一范围内空白值(或第二个示例中的 0)的数量。
最后,该公式从总行数中减去没有值的单元格总数。这将为您留下每行中包含值的单元格数量
If you want a simple one liner that will do it all for you (assuming by no value you mean a blank cell):
If by no value you mean the cell contains a 0
The formula works by first summing up all the rows that are in columns A, B, and C (if you need to count more rows, just increase the columns in the range. E.g.
ROWS(A:A) + ROWS(B:B) + ROWS(C:C) + ROWS(D:D) + ... + ROWS(Z:Z)
).Then the formula counts the number of values in the same range that are blank (or 0 in the second example).
Last, the formula subtracts the total number of cells with no value from the total number of rows. This leaves you with the number of cells in each row that contain a value
如果您不介意 VBA,这里有一个函数可以为您完成此任务。您的调用将类似于:
它是如何工作的:我正在利用 256 行限制这一事实。工作表公式 CountBlank 将告诉您一行中有多少个单元格为空白。如果该行没有包含值的单元格,那么它将是 256。所以我只需负 256,如果它不是 0,那么我知道某处有一个具有某些值的单元格。
If you don't mind VBA, here is a function that will do it for you. Your call would be something like:
How it works: I am exploiting the fact that there is a 256 row limit. The worksheet formula CountBlank will tell you how many cells in a row are blank. If the row has no cells with values, then it will be 256. So I just minus 256 and if it's not 0 then I know there is a cell somewhere that has some value.
尝试以下场景:
Array =
A1:C7
。A1-A3
有值,B2-B6
有值,C1
、C3
和C6有值。
要获取行数,请添加一列
D
(您可以在设置公式后隐藏它),并在D1
中输入公式=If(Sum (A1:C1)>0,1,0)
。复制从D1
到D7
的公式(对于不熟悉 Excel 的其他搜索者,求和公式中的数字将更改为您所在的行,这很好) 。现在,在
C8
中创建一个求和公式,将D
列相加,答案应为6
。为了美观起见,隐藏列D
。Try this scenario:
Array =
A1:C7
.A1-A3
have values,B2-B6
have value andC1
,C3
andC6
have values.To get a count of the number of rows add a column
D
(you can hide it after formulas are set up) and inD1
put formula=If(Sum(A1:C1)>0,1,0)
. Copy the formula fromD1
throughD7
(for others searching who are not excel literate, the numbers in the sum formula will change to the row you are on and this is fine).Now in
C8
make a sum formula that adds up theD
column and the answer should be6
. For visually pleasing purposes hide columnD
.您应该在 Excel 中使用 sumif 函数:
=SUMIF(A5:C10;"Text_to_find";C5:C10)
该函数采用像 A5:C10 这样的正方形范围,然后您有一些文本可以找到它文本可以位于 A 或 B 中,然后它将添加 C 行中的数字。
You should use the sumif function in Excel:
=SUMIF(A5:C10;"Text_to_find";C5:C10)
This function takes a range like this square A5:C10 then you have some text to find this text can be in A or B then it will add the number from the C-row.
这是我最后想出来的,效果很好!
{=SUM(IF((ISTEXT('工作表名称!A:A))+(ISTEXT('CCSA Associates'!E:E)),1,0))-1}
Don'不要忘记,因为它是一个数组,所以要在不带“{}”的情况下键入上面的公式,并且要按 CTRL + SHIFT + ENTER 而不是仅按 ENTER 才能显示“{}”并正确输入。
This is what I finally came up with, which works great!
{=SUM(IF((ISTEXT('Worksheet Name!A:A))+(ISTEXT('CCSA Associates'!E:E)),1,0))-1}
Don't forget since it is an array to type the formula above without the "{}", and to CTRL + SHIFT + ENTER instead of just ENTER for the "{}" to appear and for it to be entered properly.