跳到主要内容

如何快速求和Excel中的每隔第n行/第n行?

众所周知,我们可以应用Sum函数添加一个单元格列表,但有时出于某种目的我们需要对其他所有单元格求和,而Excel没有标准函数允许我们对第n个单元格求和。 在这种情况下,我们如何才能在Excel中隔行相加或第n行/列相加?

每隔一个或第n行/列与公式求和

使用用户定义的函数求和每隔第n行/第n行

使用 Kutools for Excel 每隔或第 n 行/列求和/平均/计数


通过以下示例,我将向您展示如何应用将所有其他单元格相加的公式。

1.使用数组公式对其他所有行或列求和

在空白单元格中,请输入以下公式: =SUM(IF(MOD(ROW($B$1:$B$15),2)=0,$B$1:$B$15,0)), 然后按 Ctrl + Shift + Enter 键,以及B列中的所有其他单元格值都已求和。 查看屏幕截图:

doc-sum-other-cell1 2 doc-sum-other-cell2

笔记:

1.在上面的数组公式中,您可以将数字2更改为3、4、5…,这意味着每3行,每4行,每5行求和…

2.如果要对其他所有列求和,则可以输入以下公式: =SUM(IF(MOD(COLUMN($A$1:$O$1),2)=0,$A$1:$O$1,0)),然后按 Ctrl + Shift + Enter 获得结果的键。 看截图:

doc-sum-other-cell3

2.使用公式对其他所有行或列求和

这是另一个公式,可以帮助您对工作表中的每隔n个单元格求和。

在一个空单元格中,请输入以下公式: =SUMPRODUCT((MOD(ROW($B$1:$B$15),3)=0)*($B$1:$B$15))。 然后按 输入 键,并添加了每个第三个单元格。 查看屏幕截图:

doc-sum-other-cell4 2 doc-sum-other-cell5

笔记:

1.在上面的公式中,您可以将数字3更改为4、5、6…,这意味着每4行,每5行,每6行求和……

2.如果要对其他所有列求和,则可以输入以下公式: =SUMPRODUCT((MOD(COLUMN($A$1:$O$1),3)=0)*($A$1:$O$1)).

doc-sum-other-cell6


以下用户定义的函数还可以帮助您在Excel中添加每隔第n个单元格。

1。 按住 ALT + F11 键,然后打开 Microsoft Visual Basic应用程序 窗口。

2。 点击 插页 > 模块,然后将以下代码粘贴到“模块”窗口中。

Function SumIntervalRows(WorkRng As Range, interval As Integer) As Double
'Updateby Extendoffice
Dim arr As Variant
Dim total As Double
total = 0
arr = WorkRng.Value
For i = interval To UBound(arr, 1) Step interval
    total = total + arr(i, 1)
Next
SumIntervalRows = total
End Function
Function SumIntervalCols(WorkRng As Range, interval As Integer) As Double
Dim arr As Variant
Dim total As Double
total = 0
arr = WorkRng.Value
For j = interval To UBound(arr, 2) Step interval
    total = total + arr(1, j)
Next
SumIntervalCols = total
End Function

3。 然后保存此代码,并根据需要在空白单元格中键入以下公式,请参见屏幕截图:

用于汇总第四行: = SumIntervalRows(B1:B15,4)

doc-sum-other-cell7

用于汇总第四列: = SumIntervalCols(A1:O1,4)

doc-sum-other-cell8

4。 然后按 输入 键,您将得到计算。 查看屏幕截图:

每四行求和:

doc-sum-other-cell9

每四列求和:

doc-sum-other-cell10

备注:您可以将数字4更改为任何其他数字,例如2、3、5…,这意味着每隔第二行,每隔第三行,每隔第五行或每列求和。


也许对于大多数人来说,公式和用户定义函数都有些困难,在这里,我可以向您介绍一种解决此任务的简便方法。

Kutools for Excel选择间隔行和列,您可以先选择每个其他或第n个单元格,然后使用Sum函数对单元格求和,为选定的单元格定义一个名称。

Kutools for Excel : 带有300多个便捷的Excel加载项,可以在30天内免费试用. 

安装后 Kutools for Excel,请执行以下步骤:

1。 选择要对每隔两个或第n个单元求和的列。

2。 点击 库工具 > 选择 > 选择间隔行和列,请参见屏幕截图:

3。 在 选择间隔行和列 对话框中,根据需要指定操作,请参见屏幕截图:

doc-sum-other-cell12

4。 点击 OK,并且已经从第一行中选择了每隔一行,现在,您可以查看计算的结果,例如平均值,总和,计数显示在状态栏的底部。 看截图:

doc-sum-other-cell13

笔记:

1.使用此功能,您可以在中设置数字2、3、4… 间隔 选项,然后从第2步中范围的第一行开始选择间隔为3、4、3行的单元格。

2.通过上述步骤,您还可以根据需要对每隔第n列进行求和。

如果您想进一步了解此功能,请单击 选择间隔行和列.

立即下载和免费试用Excel的Kutools!


Kutools for Excel:具有300多个方便的Excel加载项,可以在30天内免费试用,没有任何限制。 立即下载并免费试用!

相关文章:

如何在Excel中仅汇总经过过滤或可见的单元格?

如何在Excel中求和绝对值?

最佳办公生产力工具

🤖 Kutools 人工智能助手:基于以下内容彻底改变数据分析: 智能执行   |  生成代码  |  创建自定义公式  |  分析数据并生成图表  |  调用 Kutools 函数...
热门特色: 查找、突出显示或识别重复项   |  删除空白行   |  合并列或单元格而不丢失数据   |   不使用公式进行四舍五入 ...
超级查询: 多条件VLookup    多值VLookup  |   跨多个工作表的 VLookup   |   模糊查询 ....
高级下拉列表: 快速创建下拉列表   |  依赖下拉列表   |  多选下拉列表 ....
列管理器: 添加特定数量的列  |  移动列  |  切换隐藏列的可见性状态  |  比较范围和列 ...
特色功能: 网格焦点   |  设计图   |   大方程式酒吧    工作簿和工作表管理器   |  资源库 (自动文本)   |  日期选择器   |  合并工作表   |  加密/解密单元格    按列表发送电子邮件   |  超级筛选   |   特殊过滤器 (过滤粗体/斜体/删除线...)...
前 15 个工具集12 文本 工具 (添加文本, 删除字符,...)   |   50+ 图表 类型 (甘特图,...)   |   40+ 实用 公式 (根据生日计算年龄,...)   |   19 插入 工具 (插入二维码, 从路径插入图片,...)   |   12 转化 工具 (小写金额转大写, 货币兑换,...)   |   7 合并与拆分 工具 (高级组合行, 分裂细胞,...)   |   ... 和更多

使用 Kutools for Excel 增强您的 Excel 技能,体验前所未有的效率。 Kutools for Excel 提供了 300 多种高级功能来提高生产力并节省时间。  单击此处获取您最需要的功能...

产品描述


Office Tab 为 Office 带来选项卡式界面,让您的工作更加轻松

  • 在Word,Excel,PowerPoint中启用选项卡式编辑和阅读,发布者,Access,Visio和Project。
  • 在同一窗口的新选项卡中而不是在新窗口中打开并创建多个文档。
  • 每天将您的工作效率提高50%,并减少数百次鼠标单击!
Comments (20)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
the above given codes work but when the file is closed and reopen, it doesn't work. again the same codes needs to copy and paste. pls give permanent solution
This comment was minimized by the moderator on the site
Hello,
After pasting the code, when you close the workbook, you should save the workbook as Excel Macro-Enabled Workbook format to save the code.
When you open the workbook next time, click the Enable Content button in the security warning bar.
Please try, thank you!
This comment was minimized by the moderator on the site
Hi i want to sum up every 4 row, but my new table for these sum-up values has an interval of every 12 rows, any idea?
Ex: Sum-up every 4 months data and put those data in a new table at every new year Jan (12 interval row).
This comment was minimized by the moderator on the site
Sorry final question is there a way this can be done in one array in a Sumproduct formula as I'd like the values to still be kept individually.
This comment was minimized by the moderator on the site
That VBA code is helpful, can it be amended so it also sums the first value of the sequence?
This comment was minimized by the moderator on the site
These vma tutorials are the best thing ever. Very helpful thank you guys!
This comment was minimized by the moderator on the site
The formula is not working for the column can anyone please help me to add odd column
This comment was minimized by the moderator on the site
Hi, Nilesh,
If you want to sum the cell values in all odd row, the below formula may help you! (Please change the cell references to your need.)

=SUMPRODUCT(B1:B15,MOD(ROW(B1:B15)+0,2))

Please try, hope it can help you!
This comment was minimized by the moderator on the site
Is there a way to add another criteria to this formula? I want to add every 9th row that is great than -40. I would appreciate your help. Thanks in advance!
This comment was minimized by the moderator on the site
Used the visual basic programming – excellent! The other options worked fine except for row n.º 1.
This comment was minimized by the moderator on the site
sir I have used visual basic for SumIntervalCols function as stated above and saved the file as macro enable worksheet. when next time open the file the user define command is missing from drop down function menu Please help how to fix user define macro and can be used for other excel sheets. regards D KUMAR
This comment was minimized by the moderator on the site
This method does not work for me. I entered the 15 numbers in the column B (B1:B15) as in the example and copy the formula to a blank cell, the result is 0. If I change the if statement to IF(MOD(ROW($B$1:$B$15),2)=1, the result is 3795 that is sum(B1:B15). What is wrong?
There are no comments posted here yet
Load More
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations