如何计算 Excel 工作表中数据的行数?

发布于 2024-11-26 21:47:42 字数 284 浏览 0 评论 0原文

我正在尝试计算电子表格中几列中至少包含一个非空白值的行数:即

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

挽你眉间 2024-12-03 21:47:42

使用公式,您可以做的是:

  • 在新列(例如列 D - 单元格 D2)中,添加 =COUNTA(A2:C2)
  • 将此公式拖到末尾您的数据(在我们的示例中为单元格 D4
  • 添加最后一个公式来求和(例如在单元格 D5 中):=SUM(D2:D4)

With formulas, what you can do is:

  • in a new column (say col D - cell D2), add =COUNTA(A2:C2)
  • drag this formula till the end of your data (say cell D4 in our example)
  • add a last formula to sum it up (e.g in cell D5): =SUM(D2:D4)
穿越时光隧道 2024-12-03 21:47:42

如果您想要一个简单的衬线来为您完成所有操作(假设没有值,您意味着一个空白单元格):

=(ROWS(A:A) + ROWS(B:B) + ROWS(C:C)) - COUNTIF(A:C, "")

如果没有值,您意味着该单元格包含 0

=(ROWS(A:A) + ROWS(B:B) + ROWS(C:C)) - COUNTIF(A:C, 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):

=(ROWS(A:A) + ROWS(B:B) + ROWS(C:C)) - COUNTIF(A:C, "")

If by no value you mean the cell contains a 0

=(ROWS(A:A) + ROWS(B:B) + ROWS(C:C)) - COUNTIF(A:C, 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

走过海棠暮 2024-12-03 21:47:42

如果您不介意 VBA,这里有一个函数可以为您完成此任务。您的调用将类似于:

=CountRows(1:10) 
Function CountRows(ByVal range As range) As Long

Application.ScreenUpdating = False
Dim row As range
Dim count As Long

For Each row In range.Rows
    If (Application.WorksheetFunction.CountBlank(row)) - 256 <> 0 Then
        count = count + 1
    End If
Next

CountRows = count
Application.ScreenUpdating = True

End Function

它是如何工作的:我正在利用 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:

=CountRows(1:10) 
Function CountRows(ByVal range As range) As Long

Application.ScreenUpdating = False
Dim row As range
Dim count As Long

For Each row In range.Rows
    If (Application.WorksheetFunction.CountBlank(row)) - 256 <> 0 Then
        count = count + 1
    End If
Next

CountRows = count
Application.ScreenUpdating = True

End Function

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.

心碎的声音 2024-12-03 21:47:42

尝试以下场景:

Array = A1:C7A1-A3 有值,B2-B6 有值,C1C3C6有值。

要获取行数,请添加一列 D(您可以在设置公式后隐藏它),并在 D1 中输入公式 =If(Sum (A1:C1)>0,1,0)。复制从 D1D7 的公式(对于不熟悉 Excel 的其他搜索者,求和公式中的数字将更改为您所在的行,这很好) 。

现在,在 C8 中创建一个求和公式,将 D 列相加,答案应为 6。为了美观起见,隐藏列 D

Try this scenario:

Array = A1:C7. A1-A3 have values, B2-B6 have value and C1, C3 and C6 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 in D1 put formula =If(Sum(A1:C1)>0,1,0). Copy the formula from D1 through D7 (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 the D column and the answer should be 6. For visually pleasing purposes hide column D.

得不到的就毁灭 2024-12-03 21:47:42

您应该在 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.

痕至 2024-12-03 21:47:42

这是我最后想出来的,效果很好!

{=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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文