跳到主要內容

如何在Excel中的單個單元格中求和或相加數字?

在許多情況下,您可能需要對單個單元格中的所有數字求和。 例如,在單元格A1中有一個文本字符串Class 2 Grade 1,這些數字相加的結果為1 + 2 = 3。 本文將詳細介紹在單個單元格中添加數字的方法。

具有用戶定義功能的單個單元格中的總數
只需單擊幾下即可輕鬆將單個單元格中的數字相加


具有用戶定義功能的單個單元格中的總數

您可以使用以下用戶定義的函數對單個單元格中的數字求和。

1。 按 其他 + F11 同時打開 Microsoft Visual Basic應用程序 窗口。

2。 在裡面 Microsoft Visual Basic應用程序 窗口中,單擊 插入 > 模塊。 然後將下面的VBA複製到 模塊 窗口。

VBA:單個單元格中的總和

Function SumNums(pWorkRng As Range, Optional xDelim As String = " ") As Double
	Dim arr As Variant
	Dim xIndex As Long
	arr = Split(pWorkRng, xDelim)
	For xIndex = LBound(arr) To UBound(arr) Step 1
		SumNums = SumNums + VBA.Val(arr(xIndex))
	Next
End Function

3.Press 其他 + Q 關閉鍵 Microsoft Visual Basic應用程序 窗口。

4.選擇一個空白單元格以輸出結果。 在其中輸入以下公式,然後按 Enter 鍵(A2是您將對單個數字求和的單元格)。

=SUMNUMS(A2)

5.然後拖動結果單元格的“填充手柄”以將公式應用於其他所需的單元格。

備註:此用戶定義的功能不適用於數字格式的單元格。


只需單擊幾下即可輕鬆將單個單元格中的數字相加

Excel的Kutools單元格中的總和 只需單擊幾下鼠標,公式即可幫助輕鬆地對單個單元格(包括文本格式的單元格和數字格式的單元格)中的數字求和。

申請前 Excel的Kutools首先下載並安裝.

1.選擇一個空白單元格以輸出結果。 然後點擊 庫工具 > 公式助手 > 公式助手.

2。 在裡面 公式助手 對話框,請進行以下配置。

2.1)查找並選擇 單元格中的總和 ,在 選擇一個公式 框;
保養竅門:您可以檢查 篩選 框中,鍵入關鍵字以過濾所需的公式。
2.2)在 細胞 框,指定一個單元格,其中包含您將求和的數字;
2.3)點擊 OK 按鈕。 看截圖:

3.然後將結果填充到選定的單元格中。 選擇結果單元格,然後向下拖動其“填充手柄”以獲取其他結果。

  如果您想免費試用(30天)此實用程序, 請點擊下載,然後按照上述步驟進行操作。


使用Kutools for 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 (8)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
The VBA function code works really well. Thank you. 
This comment was minimized by the moderator on the site
How do I add +1 digit to numbers in one cell (word or excell or notepad, doesn't matter). But at My work I often have: 14,17,28,31,35,38,50,53,70,73,80,83,90,93,120,123,135,138,150,153,165,168,180,183,210,213,250,253,275,278,300,303 something like that.

And I need to make them like: 15,18,29,32,36,39,51,54,71,74,81,84,91,94,121,124,136,139,151,154,166,169,181,184,211,214,251,254,276,279,301,304. I do it manually, but maybe there is a fast way to do it?
This comment was minimized by the moderator on the site
I have a list of numbers that I want to automatically add 30 to each number in each single cell. Is that possible?
This comment was minimized by the moderator on the site
You can also very easily just type "=" in the cell. So if you had a cell that was 3 but wanted to add 1+2 it would be "=1+2" in the cell
This comment was minimized by the moderator on the site
The problem with this tool is that it adds all the digits. The problem is 125 + 2 is not 127. The tool would add it as 1 + 2 + 5 + 2. Not sure how this is useful to someone that needs to add all the numbers. Even in the example it does not make sense or seem practical. Did I miss something?
This comment was minimized by the moderator on the site
Incorrect if the numbers are entered into the cell separately, for example 125 2 and the formula is entered into the next cell. The cell with the formula will calculate 127.
This comment was minimized by the moderator on the site
Hi Michael,
Sorry for the mistake. Please enter the following VBA code into the Module (Code) window, and then apply this formula: =SUMNUMS(A1,"") to sum all digits in a cell.

Function SumNums(pWorkRng As Range, Optional xDelim As String = " ") As Double
'Updated by ExtendOffice 20221122
    If pWorkRng.CountLarge > 0 Then Exit Function
    On Error Resume Next
    Application.Volatile
    
    Dim arr As Variant
    Dim xIndex As Long
    If xDelim <> "" Then
        arr = Split(pWorkRng, xDelim)
        For xIndex = LBound(arr) To UBound(arr) Step 1
            SumNums = SumNums + VBA.Val(arr(xIndex))
        Next
    Else
        For xIndex = 1 To Len(pWorkRng) Step 1
            If IsNumeric(Mid(pWorkRng, xIndex, 1)) Then
                SumNums = SumNums + VBA.Val(Mid(pWorkRng, xIndex, 1))
            End If
        Next
    End If
End Function
This comment was minimized by the moderator on the site
THANKSSSSSS SOOO MUCH THE MODULE IDEA IS AMAZING ! I NEVER KNEW IT EXISTED
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations