跳到主要内容

如何仅从Excel中的文本字符串中提取数字?


方法1:仅从具有公式的文本字符串中提取数字

以下长公式可以帮助您仅从文本字符串中提取数字,请按照以下步骤操作:

选择要输出提取的数字的空白单元格,然后键入以下公式: = SUMPRODUCT(MID(0&A5,LARGE(INDEX(ISNUMBER(-MID(A5,ROW(INDIRECT(“ 1:”&LEN(A5)))),1)))* ROW(INDIRECT(“ 1:”&LEN(A5) )),0),ROW(INDIRECT(“ 1:”&LEN(A5)))))+ 1,1)* 10 ^ ROW(INDIRECT(“ 1:”&LEN(A5)))/ 10),然后拖动填充手柄以填充应用此公式所需的范围。 看截图:

doc提取数字仅2

笔记:

  • 1. A5 代表您只想从列表中提取数字的第一个数据。
  • 2.如果字符串中没有数字,结果将显示为0。

仅从文本字符串中提取数字:

Kutools for Excel 提取号码 函数,您可以快速从文本字符串单元格中仅提取数字。 点击下载Kutools for Excel!

doc提取数字仅14


方法2:仅从带有VBA代码的文本字符串中提取数字

这是一个VBA代码,也可以帮您一个忙,请执行以下操作:

1。 按住 Alt + F11键 键打开 Microsoft Visual Basic应用程序 窗口。

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

VBA代码:仅从文本字符串中提取数字:

Sub ExtrNumbersFromRange()
    Dim xRg As Range
    Dim xDRg As Range
    Dim xRRg As Range
    Dim nCellLength As Integer
    Dim xNumber As Integer
    Dim strNumber As String
    Dim xTitleId As String
    Dim xI As Integer
    xTitleId = "KutoolsforExcel"
    Set xDRg = Application.InputBox("Please select text strings:", xTitleId, "", Type:=8)
    If TypeName(xDRg) = "Nothing" Then Exit Sub
    Set xRRg = Application.InputBox("Please select output cell:", xTitleId, "", Type:=8)
    If TypeName(xRRg) = "Nothing" Then Exit Sub
    xI = 0
    strNumber = ""
  For Each xRg In xDRg
    xI = xI + 1
    nCellLength = Len(xRg)
    For xNumber = 1 To nCellLength
      If IsNumeric(Mid(xRg, xNumber, 1)) Then
        strNumber = strNumber & Mid(xRg, xNumber, 1)
      End If
    Next xNumber
    xRRg.Item(xI) = strNumber
    strNumber = ""
  Next xRg
End Sub

3。 然后,按 F5 键以运行此代码,并弹出一个提示框,提醒您选择要使用的文本范围,请参见屏幕截图:

doc提取数字仅3

4。 然后,点击 OK,随后出现另一个提示框,请选择一个单元格以输出结果,请参见屏幕截图:

doc提取数字仅4

5。 最后点击 OK 按钮,并立即提取所选单元格中的所有数字。


方法 3: 使用 Kutools for Excel 仅从文本字符串中提取数字

Kutools for Excel 也有一个强大的功能,称为 提取号码,使用此功能,您可以快速从原始文本字符串中仅提取数字。

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

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

1。 单击文本字符串旁边的单元格,将结果放入其中,请参见屏幕截图:

doc提取数字仅5

2。 然后点击 库工具 > Kutools函数 > 文本 > 提取号码,请参见屏幕截图:

doc提取数字仅6

3。 在 功能参数 对话框中,选择要从中提取数字的单元格 文本 文本框,然后输入 true or falseN 文本框,请参见屏幕截图:

doc提取数字仅7

备注:论点 N 是一个可选项目,如果您输入 true,如果输入,它将以数字形式返回数字 false,它将以文本格式返回数字,默认值为false,因此可以将其保留为空白。

4。 然后点击 OK,已从选定的单元格中提取数字,然后将填充手柄向下拖动到要应用此功能的单元格上,将得到以下结果:

doc提取数字仅8

单击立即下载并免费试用 Kutools for Excel!


方法4:仅从具有公式的文本字符串中提取十进制数字

如果工作表中包含一些十进制数字的文本字符串,如何从文本字符串中仅提取十进制数字?

下面的公式可以帮助您快速轻松地从文本字符串中提取十进制数字。

输入此公式:=LOOKUP(9.9E+307,--LEFT(MID(A5,MIN(FIND({1,2,3,4,5,6,7,8,9,0}, $A5&"1023456789")),999),ROW(INDIRECT("1:999")))),然后将句柄向下填充至要包含此公式的单元格,所有十进制数字均已从文本字符串中提取,请参见屏幕截图:

doc提取数字仅13


使用 Kutools for Excel 仅从字符串中提取数字

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

相关文章:

最佳办公生产力工具

🤖 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 (61)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
how to get a extract extact numbers from text
This comment was minimized by the moderator on the site
Hi, I'm looking to list all numbers in a string before a certain character. The string has letters and numbers, so I want to remove the letters and only list the numbers that appear before the second minus sign "-". Example:MUMUT-S941-22460991e002
I want that to isolate the numbers 941 in the above example.
This comment was minimized by the moderator on the site
How to use Index instead of Indirect to extract number from string. Indirect is volatile and Index can replace it as per http://www.excelhero.com/blog/2011/03/the-imposing-index.html. Thanks Ahead!
This comment was minimized by the moderator on the site
Hello! I found the following formula to extract only the numbers from text strings in Excel very useful

SUMPRODUCT(MID(0&A5, LARGE(INDEX(ISNUMBER(--MID(A5, ROW(INDIRECT("1:"&LEN(A5))), 1)) * ROW(INDIRECT("1:"&LEN(A5))), 0), ROW(INDIRECT("1:"&LEN(A5))))+1, 1) * 10^ROW(INDIRECT("1:"&LEN(A5)))/10)

Could you explain more on this formula as it seems quite complicated? Many thanks.
This comment was minimized by the moderator on the site
Reading ID: 3151346 BeatO User ID: 239930 Name: Mahesh Phone: 9823010759 Email: City: nashik State: Maharashtra Reading: 55 Meal Time: Random Meal Type: RANDOM Reading Time: 2020-03-01 00:15:57 View user readings in Portal



I want to extract numeric no. post Reading text
This comment was minimized by the moderator on the site
Hello, how can i extract the cheque no.only from the below text

OUTWARD CLEARING CLRG CHQ DEPOSIT CHQ. NO: 000123~700320456 ABCD ARAB PLAZ BRANC Value DATE, 01/02/2020 - S79519642

i tried below formula and its working but i need to change the 1:57 by calculating how many character before the first digit plus how many digits i want to extract.
=MIN(FIND({0,1,2,3,4,5,6,7,8,9},A3&"0123456789"))+5 im using this formula to know how many characters before the first number..

=TEXTJOIN("",TRUE,IFERROR(MID(A3,ROW(INDIRECT("1:57")),1)+0,""))
This comment was minimized by the moderator on the site
=Mid(A2,find("CHQ. NO", A2)+9,6)
This comment was minimized by the moderator on the site
Hi. I wonder to know is it possible to extract from the next string '102-105+106-10605-10605 -10631-10632-10633-10634-10635+107' all values of only three digits that have sign '-' (i.e. minus) before them (or plus - doesn't matter). Then extract extract all 5-digits values with the same rule? If this is possible to do I will save many many hours of manual work that I can devote to lot's of uselful tasks.

P.S.
I know that regular expressions are able to do that, BUT... I hate their syntax, so I'm searching any other method to complete this task.

Thanks in advance.
This comment was minimized by the moderator on the site
Hi, is it possible to extract the numbers before "g", for example : 25,20,15,25,300,40

Ali Baba Dark Chocolate 25g box 12 pcs
Ali Baba Dark Chocolate 20g*24 box
Cadbury 5 Star White Chocolate 15g
Kinder 2 White Chocolate 25g*24
ALpella Biscuits W/Marshmallow300g
Alpella Chocolate 40g
This comment was minimized by the moderator on the site
did anyone answer or did you figure this out? this is exactly my problem right - even down to the letter 'g'. the problem with the formula I am using now is that it returns the first number, if there are more than one, from the string and not the number I am wishing to return.
This comment was minimized by the moderator on the site
Hi, is it possible to extract the numbers before "g", for example : 25,20,15,25,300,40


Ali Baba Dark Chocolate 25g box 12 pcs
Ali Baba Dark Chocolate 20g*24 box
Cadbury 5 Star White Chocolate 15g
Kinder 2 White Chocolate 25g*24
ALpella Biscuits W/Marshmallow300g
Alpella Chocolate 40g
This comment was minimized by the moderator on the site
can any one answer this question, how to extract the no's
This comment was minimized by the moderator on the site
You may try select the number before g in the first cell, copy and paste it in new cell. Then press CTRL + E. All the number before g will be auto generated. 

This comment was minimized by the moderator on the site
Tkssssss you saved my day :) God bless you
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