简体   繁体   English

Excel 固定增量计数

[英]Excel count with fixed increment

I have a large table of more than 2000 rows, and 5 columns.我有一个超过 2000 行和 5 列的大表。 The values of these cells are either 1 or 0. For each column I want to be able to count the number of 1s in blocks of 20 rows starting from the first row.这些单元格的值为 1 或 0。对于每一列,我希望能够计算从第一行开始的 20 行块中 1 的数量。 Example: For each column count the number of 1s in the first 20 cells (A1:A20), then in cells 21 to 41 (A21:A41), then from 42 to 62 and so on.示例:对于每一列,计算前 20 个单元格 (A1:A20) 中 1 的数量,然后是单元格 21 到 41 (A21:A41) 中的 1,然后是 42 到 62 等等。 Any help is appreciated.任何帮助表示赞赏。

Many thanks,非常感谢,

egit出口

I have tried various combination of COUNTIF, ROW and OFFSET but did not work.我尝试了 COUNTIF、ROW 和 OFFSET 的各种组合,但都没有用。 Spent sometime reading various sites for suggestions but could not find the solution.花了一些时间阅读各种网站以寻求建议,但找不到解决方案。

=COUNTIF(OFFSET(A1,(ROW()-1)*19,0,20,1),1)

is used to count the number of 1s in blocks of 20 rows for column A.用于计算 A 列的 20 行块中 1 的数量。

The OFFSET function starts from the cell A1, which is the first cell of the first block of 20 rows. OFFSET function 从单元格 A1 开始,这是第一个 20 行块的第一个单元格。

Then it uses the ROW() function to determine the current row and subtracts 1 to start counting from the first row.然后它使用 ROW() function 确定当前行并减去 1 以从第一行开始计数。

Next, it multiplies the current row by 19 to offset the range by 19 rows for each row.接下来,它会将当前行乘以 19,以使每行的范围偏移 19 行。

This is done because the range is starting from A1, which is the first cell of the first block of 20 rows, so it needs to offset by 19 rows to look at the next block of 20 rows.这样做是因为范围从 A1 开始,它是第一个 20 行块的第一个单元格,因此它需要偏移 19 行才能查看下一个 20 行块。

The OFFSET function then selects a range of 20 rows starting from that point. OFFSET function 然后选择从该点开始的 20 行范围。

In the first row, the formula will look at cells A1:A20, in the second row it will look at cells A21:A40 and so on.在第一行中,公式将查看单元格 A1:A20,在第二行中它将查看单元格 A21:A40,依此类推。

So when you drag the formula down, it will always look at the next block of 20 rows, regardless of where you drag it.因此,当您向下拖动公式时,它总是会查看下一个 20 行的块,而不管您将它拖动到哪里。

The COUNTIF function then counts the number of 1s in the selected range and returns the result. COUNTIF function 然后计算所选范围内 1 的数量并返回结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM