跳到主要内容

如何在Excel中用文字和数字对单元格求和?

例如,我有一个包含数字和文本字符串的值列表,现在,我只想对基于相同文本的数字求和,请看以下屏幕截图。 通常,您不能直接使用文本字符串将列表中的值求和,在这里,我将向您介绍一些公式来处理此任务。


对包含文本和数字的单元格求和,这些文本和数字基于带有公式的某些文本

您可以使用数组公式根据单元格中对应的文本字符串对数字求和,请执行以下操作:

1. 首先,您可以写下您要对列单元格中的相对数字求和的文本字符串。

2。 然后在空白单元格中键入以下公式,在此示例中,我将在单元格E2中输入公式,然后按 Ctrl + Shift + Enter 键在一起,它将根据特定文本从列表中返回总值。 看截图:

=SUM(IF(ISNUMBER(FIND(D2,$B$2:$B$9)),VALUE(LEFT($B$2:$B$9,FIND(D2,$B$2:$B$9)-1)),0))

备注:在以上公式中, D2 是您要使用的标准,并且 B2:B9 表示要求和的单元格范围。

3。 然后选择公式单元格,并将填充手柄向下拖动到要应用此公式以获取结果的单元格:


总和单元格包含基于某些文本的文本和数字,并具有方便的功能

如果上述公式难以理解, Kutools for Excel 提供了有用的工具- 基于相同文本的总和,使用此功能,您可以在一个混合了数字和文本的单元格中获得总结果,而无需记住任何公式。

请注意:应用这些 基于相同文本的总和 功能,首先,您应该下载 Kutools for Excel,然后快速轻松地应用这些功能。

安装后 Kutools for Excel,请执行以下操作:

1。 单击以选择要在其中输出结果的单元格,请参见屏幕截图:

Tips:为防止循环引用,请不要将此公式插入工作表的第一行。

2。 然后点击 库工具 > 公式助手 > 公式助手,请参见屏幕截图:

3。 在 公式助手 对话框,请执行以下操作:

  • 选择 统计 来自 公式类型 下拉列表;
  • 选择一个公式 列表框,单击以选中 基于相同文本的总和 选项;
  • 那么,在 参数输入 部分,选择包含您要在其中求和的文本和数字的单元格范围 范围 文本框,然后在中选择要对值求和的文本单元格 文本 文本框。
Tips: 在里面 文本 文本框,应将默认的绝对单元格引用更改为相对单元格引用,以正确拖动公式。

4。 然后,单击 Ok 按钮,将首先计算结果,然后将填充手柄拖动到其他单元格中以填充公式,请参见屏幕截图:


包含文本和数字的求和单元格使用用户定义函数忽略文本

如果您具有以下混合了文本和数字的数据,而您只想提取和累加每个单元格中的数字,那么如何在Excel中快速完成呢?

要解决此问题,您可以创建一个 用户定义功能,请这样做:

1。 按住 ALT + F11 键打开 Microsoft Visual Basic for Applications窗口.

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

VBA代码:仅对包含数字和文本的单元格中的数字求和

Function SumNumbers(rngS As Range, Optional strDelim As String = " ") As Double
'Updateby Extendoffice
    Dim xNums As Variant, lngNum As Long
    xNums = Split(rngS, strDelim)
    For lngNum = LBound(xNums) To UBound(xNums) Step 1
        SumNumbers = SumNumbers + Val(xNums(lngNum))
    Next lngNum
End Function

3。 然后保存并关闭此代码,返回到工作表,然后输入此公式 = SumNumbers(A2) (A2 表示要对数字求和的单元格),然后将填充手柄向下拖动到要填充公式的单元格,并且仅将每个单元格中的数字加在一起,请参见屏幕截图:


更多相关文章:

  • 合并重复的行并求和Excel中的值
  • 在Excel中,当您具有一系列包含某些重复项的数据时,您可能总是会遇到此问题,现在您想要合并重复数据并在另一列中求和相应的值,如下面的屏幕快照所示。 您如何解决这个问题?
  • 将两列相乘,然后在Excel中求和
  • 在Excel中,我们大多数人可能会遇到两列相乘然后相加的问题,当然,我们可以将每一项相乘然后相加,但是如果要计算成百上千的行,这将很麻烦。 在Excel中,有一个强大的功能– SUMPRODUCT,有了它,我们可以快速将两列相乘然后相加。 在本文中,我将讨论如何应用此功能。
  • 根据Excel中的条件求和前3个或N个值
  • 通常,我们可以使用一个简单的公式将一个单元格区域的前n个值相加,但是您是否曾经尝试过根据某些条件对前n个值进行相加。 本文中,我将介绍一些公式,用于将Excel中具有特定条件的前n个值相加。
  • 根据Excel中的条件求和唯一值
  • 例如,我现在有一系列数据,其中包含“名称”和“订单”列,以根据“名称”列仅对“订单”列中的唯一值求和,如下图所示。 如何在Excel中快速轻松地解决此任务?
  • 根据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 (50)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Hi,
I want to have a formula that count text. But what I want is that he count a criterium/ text like as 0,5 and not as 1. Like for example I have one column with T, TO and TM. T I want to count as 1 and TO/ TM as 0,50. I have tried several things, but can not solve it. Hopefully can someone help me out?
This comment was minimized by the moderator on the site
Hi, I am trying to check approximately 8 different types of leave. I am using conditional formatting to colour code letters and then calculate as numbers. It works well, I like it. I did not factor in a half day.

Can anyone tell me how to account for a half day, and still have Excel recognize the Alpha symbol.
This comment was minimized by the moderator on the site
Hi, how do I sum something like the following:
Column A
Row 1 2D
Row 2 2N
Row 3 1D+2N

I have no issues summing the Ds but when I try summing the Ns I would encounter a problem. The string 1D+2N is the culprit, so how do I go about this?
Any help is very much appreciated.

Thank you.
This comment was minimized by the moderator on the site
I must be doing something incorrect. When I try to use the SumNumbers() VB code nothing happens? excel does not recognize it as code? I am using a macro enabled document. Image attached.
https://ibb.co/6vRtD6N

[img]https://ibb.co/6vRtD6N[/img]
This comment was minimized by the moderator on the site
Hi, Michael,
I have tested the code based on the data you provied, it can work well.
This is User Defined Function, so, you needn't run the code, you just need to insert the formula SumNumbers(A1), and press Enter key to get the result. See screenshot:
https://www.extendoffice.com/images/stories/comments/comment-skyyang/doc-sum-text-number.png

Please try, hope it can help you!
This comment was minimized by the moderator on the site
How to do this, but with decimal places? When using decimals, it returns 0...
This comment was minimized by the moderator on the site
HOW TO MULTIPLY COLUM 1 , 2 PCS , COLOUM 2 RATE 1 USD TOTAL AMOUNT ?
This comment was minimized by the moderator on the site
kindly reply to "I want to use this formula to sum only numbers in all columns like =SumNumbers(A1:G1) but it gives error VALUE. how it can be fixed?"
This comment was minimized by the moderator on the site
You need to use the VBA for that to work. the VBA code defines the SumNumbers as a function.
This comment was minimized by the moderator on the site
I have used VBA for that but it doesn't work. Can you plz take a look?
This comment was minimized by the moderator on the site
I have used VBA for that but it does not work. Can you take a look plz?
This comment was minimized by the moderator on the site
I want to use this formula to sum only numbers in all columns like =SumNumbers(A1:G1) but it gives error VALUE. how it can be fixed?
This comment was minimized by the moderator on the site
I am using this in excel 2016 but it doesn't seem to be working is there a work through? i keep getting a "
#name?" error
This comment was minimized by the moderator on the site
Hi,
I have a question. How to get the sum or the average of the column that has text inside that column. Please see attachment. Your answer would be greatly appreciated.
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