跳到主要內容

如何快速將Excel中的每隔一行或第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))。 然後按 Enter 鍵,並添加了每個第三個單元格。 查看屏幕截圖:

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 for Applications 窗口。

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。 然後按 Enter 鍵,您將得到計算。 查看屏幕截圖:

每四行求和:

doc-sum-other-cell9

每四列求和:

doc-sum-other-cell10

備註:您可以將數字4更改為任何其他數字,例如2、3、5…,這意味著每隔第二行,每隔第三行,每隔第五行或每列求和。


也許對於大多數人來說,公式和用戶定義函數都有些困難,在這裡,我可以向您介紹一種解決此任務的簡便方法。

這款獨特的敏感免洗唇膜採用 Moisture WrapTM 技術和 Berry Mix ComplexTM 成分, Excel的Kutools選擇間隔行和列,您可以先選擇每個其他或第n個單元格,然後使用Sum函數對單元格求和,然後為選定的單元格定義一個名稱。

Excel的Kutools : 帶有300多個便捷的Excel加載項,可以在30天內免費試用. 

安裝後 Excel的Kutools,請執行以下步驟:

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!


Excel的Kutools:具有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選項卡為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