跳到主要内容

如何在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.选择一个空白单元格以输出结果。 在其中输入以下公式,然后按 输入 键(A2是将对单个数字求和的单元格)。

=SUMNUMS(A2)

5.然后拖动结果单元格的“填充手柄”,以将公式应用于其他需要的单元格。

备注:此用户定义的功能不适用于数字格式的单元格。


只需单击几下即可轻松将单个单元格中的数字相加

Kutools for Excel单元格中的总和 只需单击几下鼠标,公式即可帮助轻松地对单个单元格(包括文本格式的单元格和数字格式的单元格)中的数字求和。

申请前 Kutools for Excel首先下载并安装.

1.选择一个空白单元格以输出结果。 然后点击 库工具 > 公式助手 > 公式助手.

2.在 公式助手 对话框,请进行以下配置。

2.1)查找并选择 单元格中的总和 ,在 选择一个公式 框;
Tips:您可以检查 筛选器 框中,键入关键字以过滤所需的公式。
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 Tab 为 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