提示:其它语言是由 Google 机器翻译的。 你可以访问 English 版本。
登录
x
or
x
x
马上登记
x

or

如何从Excel中的文本字符串中提取第一/最后/第n个单词?

你是否曾经遇到过需要从工作表中的文本字符串中提取某个单词的问题? 例如,您需要从中获取第一个/最后一个或第n个单词所需的以下文本字符串范围,在这里我可以谈谈您解决问题的一些有效方法。

用公式从文本字符串中提取第一个单词或姓氏

用用户定义的函数从文本字符串中提取第n个单词

从文本字符串中提取每个单词并水平或垂直列出它们

轻松批量提取Excel中全名的名字和姓氏

Kutools为Excel的 拆分名称 实用程序可以帮助您在Excel中快速将全名分割为名字,中间名和姓氏。 全功能免费试用60天!
广告拆分名称2

Office选项卡在Office中启用选项卡式编辑和浏览,使您的工作更轻松......
Kutools for Excel - 最佳办公生产力工具将解决您的大部分Excel问题
  • 重用任何东西: 将最常用或最复杂的公式,图表和其他任何内容添加到您的收藏夹中,并在将来快速重复使用它们。
  • 超过20文本功能: 从文本字符串中提取数字; 提取或删除部分文本; 将数字和货币转换为英语单词...
  • 合并工具:多个工作簿和表格合二为一; 合并多个单元格/行/列而不丢失数据; 合并重复行和总和...
  • 拆分工具:根据价值将数据拆分为多个表格; 一个工作簿到多个Excel,PDF或CSV文件; 一列到多列......
  • 粘贴跳过 隐藏/过滤行; 数和总和 按背景颜色; 创建邮件列表和 通过Cell的价值发送电子邮件...
  • 超级过滤器: 创建高级过滤方案并应用于任何工作表; 排序 按周,日,频率等; 筛选 通过大胆,公式,评论......
  • 超过300强大的功能; 适用于Office 2007-2019和365; 支持所有语言; 在公司轻松部署; 全功能60天免费试用。

箭头蓝色右泡 用公式从文本字符串中提取第一个单词或姓氏

希望从文本字符串列表中提取第一个单词,以下公式可以帮助您。

要提取第一个单词,请输入此公式 = IF(ISERR(FIND(“”,A2)),“”,LEFT(A2,FIND(“”,A2)-1)) 放入空白单元格中,然后根据需要将该单元格的自动填充句柄拖动到该范围。

现在你会看到第一个字是从每个单元格中提取的。 看下面的截图:

备注:

(1)在上式中, A2 表示您想要应用此公式的单元格。

(2)为了从每个单元格中提取最后的单词,请应用以下公式: = IF(ISERR(FIND(“”,A2)),“”,RIGHT(A2,LEN(A2)-FIND(“*”,SUBSTITUTE(A2,“”,“*”,LEN(A2) SUBSTITUTE(A2,“”,“”)))))).

注意丝带 公式太难记了? 将公式保存为自动文本条目,以便将来只需点击一下即可重复使用!
阅读全文... 免费试用

箭头蓝色右泡 用用户定义的函数从文本字符串中提取第n个单词

如果要从文本字符串中提取第二个,第三个或第n个单词,可以创建一个用户定义的函数来处理它。

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

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

Function FindWord(Source As String, Position As Integer)
'Update 20131202
Dim arr() As String
arr = VBA.Split(Source, " ")
xCount = UBound(arr)
If xCount < 1 Or (Position - 1) > xCount Or Position < 0 Then
    FindWord = ""
Else
    FindWord = arr(Position - 1)
End If
End Function

3。 然后保存代码,在这个例子中,我会从字符串中得到第三个单词,所以输入这个公式 = findword(A2,3) 放入一个空白单元格B2中,然后根据需要将该单元格的自动填充句柄拖到该范围。 看截图:

请注意: 在上面的公式中, A2 是你想从中提取单词的单元格,数字 3 表示将要提取的字符串中的第三个单词,并且可以根据需要更改它们。


箭头蓝色右泡 从文本字符串中提取每个单词并水平或垂直列出它们

这种方法将为Excel引入Kutools 拆分单元格 实用程序从文本字符串单元格中提取每个单词,然后根据您的需要水平或垂直列出提取的单词。

1。 选择您将提取其文字的文本字符串单元格,然后单击 Kutools > 文本 > 拆分单元格.

2。 在打开的“分割单元”对话框中,指定分割类型 类型 部分,检查 太空 在选项 指定一个分隔符 部分,然后单击 Ok 按钮。 看截图:
请注意: 要将每个文本字符串单元格的所有提取的单词水平列出,请检查 拆分为列 选项; 要垂直列出每个文本字符串单元格的所有提取的单词,请检查 拆分为行 选项。 在我们的例子中,我们检查了 拆分为行 选项。

3。 在打开新的对话框中,选择一个单元格范围,您将输出提取的单词,然后单击 OK 按钮。 见上面的截图:

然后您会看到所有单词都从每个文本字符串单元格中提取并垂直列出,如下面的屏幕截图所示:

检查 拆分为列 选项将水平列出每个文本字符串中所有提取的单词,如下所示:

Kutools for Excel - 包括多个用于Excel的300便捷工具。 全功能免费试用60天,无需信用卡! 现在加入


在这个视频中, Kutools Kutools Plus 选项卡添加 Kutools for Excel。 如果需要,请点击 60天免费试用,不受限制!

箭头蓝色右泡相关文章:


Kutools for Excel - 最佳办公生产力工具提高80%的生产力

  • 重用: 快速插入 复杂的公式,图表 以及你以前用过的任何东西; 加密单元格 密码; 创建邮件列表 并发送电子邮件...
  • 超级方程式酒吧 (轻松编辑多行文字和公式); 阅读布局 (轻松读取和编辑大量单元格); 粘贴到过滤范围...
  • 合并单元格/行/列 不丢失数据; 分裂细胞含量; 组合重复的行/列...防止重复的细胞; 比较范围...
  • 选择复制或唯一 行; 选择空行 (所有细胞都是空的); 超级查找和模糊查找 在许多工作簿中; 随机选择......
  • 精确复制 多个单元格而不更改公式参考; 自动创建参考 多张表; 插入项目符号,复选框等等......
  • 提取文本,添加文本,按位置删除, 删除空间; 创建和打印分页小计; 在单元格内容和注释之间转换...
  • 超级过滤器 (将过滤方案保存并应用到其他工作表); 高级排序 按月/周/日,频率等; 特殊过滤器 用粗体,斜体......
  • 结合工作簿和工作表; 根据键列合并表; 将数据拆分为多个表格; 批量转换xls,xlsx和PDF...
  • 超过300强大的功能。 支持Office / Excel 2007-2019和365。 支持所有语言。 在您的企业或组织中轻松部署。 全功能60天免费试用。
kte tab 201905

Office选项卡为Office提供选项卡式界面,使您的工作更轻松

  • 在Word,Excel,PowerPoint中启用选项卡式编辑和阅读,Publisher,Access,Visio和Project。
  • 在同一窗口的新选项卡中打开并创建多个文档,而不是在新窗口中。
  • 通过50%提高您的工作效率,每天为您减少数百次鼠标点击!
官方底部
Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    murali · 1 years ago
    i want to remove the last word in cell and data is like this "/Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf/Cdtr/CtctDtls/FaxNb" can i have formula
  • To post as a guest, your comment is unpublished.
    John · 2 years ago
    Thanks so much for these! I have a question, though: how do I extract a number or group of numbers from a cell or textbox? For instance, if I have [37.5" x 21'] in cell A1, how could extract 37.5 into A2? There could be any number of characters and numbers in A1, but I'll always want the first number to the left of the "X", and the first number to the right. Not sure if you've covered something like this elsewhere, so I thought I'd ask here.
    (Not sure if this went through the first time, so here it is again.)
  • To post as a guest, your comment is unpublished.
    Antonio · 2 years ago
    Thank you! It works fine called in a Sub.
  • To post as a guest, your comment is unpublished.
    DC2209 · 2 years ago
    the original formula isn't working for me, I keep getting #NAME?, anyone able to help? I am using Excel 2013 and this VBA would save me sooooo much time
  • To post as a guest, your comment is unpublished.
    DC2209 · 2 years ago
    The original VBA code posted here would save me so much time, however whenever I type in the =findword formula, I then get #NAME?, anyone able to help me? I am using Excel 2013
  • To post as a guest, your comment is unpublished.
    Shiva · 3 years ago
    Hi,

    I am having cell with values like SAN_UN_TC1,SAN_UN_TC2,PEP_HR_TC1
    I would like to extract first words liek SAN /PEP into one cell and words liek UN/HR to another cell
    How could i do it, Any help is appreciated.

    Thanks,
    Shiva
    • To post as a guest, your comment is unpublished.
      Allart · 3 years ago
      If number of characters in string (SAN_UN_TC1) is fixed (3_2_3), it's simple:
      column 1: =LEFT(B15,3)
      column 2: =MID(B15,5,2)
      column 3: =RIGHT(B15,3)
  • To post as a guest, your comment is unpublished.
    Dean · 3 years ago
    Many thanks for sharing VBA code....saved me a lot of time
  • To post as a guest, your comment is unpublished.
    Dean · 3 years ago
    VBA is so useful - thanks for sharing!
  • To post as a guest, your comment is unpublished.
    Ron Hollingsworth · 3 years ago
    I would like to extract the first word on A1 and put it in front of a word in B1. what's the formula to do that? Thanks!
  • To post as a guest, your comment is unpublished.
    Lorie · 3 years ago
    I'm looking for a formula that will pull out the First and Last Name in a text string. I've tried the formula here, which is amazing by the way, and it works great until it comes across a surname that is not hyphenated. Here is a sample of the text strings I'm presented with:
    example 1: Mouse, Mickey Justin M Feb 10
    example 2: Hall Mouse, Minnie Jean F Mar 18

    For string example 1, the formula/function here works great. For example 2 I get "Hall, Mouse".

    Here is the Excel formula I'm running:
    =CONCATENATE(LEFT(A2,FIND(", ",A2)+1), 'Personal Macro Workbook'!FindWord(A2,2))

    Is there a way to modify the user defined function so that it looks for the first word to the right of the ","?
    • To post as a guest, your comment is unpublished.
      Allart · 3 years ago
      Remove the last name from the string you feed to the FindWord function:
      - find the comma position
      - subtract this from the total length of the string
      - use the remaining 'RIGHT' side of the original string

      =CONCATENATE(LEFT(A2,FIND(", ",A2)+1),FindWord(RIGHT(A2,LEN(A2)-FIND(", ",A2)-1),1))
  • To post as a guest, your comment is unpublished.
    Dan · 3 years ago
    First word. Copy/paste the column, select the contents of the new column, replace " *" with "".
    Last word. Copy/paste the column, select the contents of the new column, replace "* " with ""
  • To post as a guest, your comment is unpublished.
    Vishal · 3 years ago
    ITS WORKING that's good.
    really helpful for us.
  • To post as a guest, your comment is unpublished.
    Mark Bolton · 4 years ago
    I have 64bit Excel 2013 and am missing the Morefunc addin. Based on the code above, I have come up with this replacement for Morefunc's WMID function. I would be grateful if anyone more expert than me could perform any tidying of it.

    Function WMid1(Source As String, Optional Position As Integer, Optional WordCount As Integer, Optional Separator As String)
    Dim arr() As String
    Dim xCount As Integer
    Dim wCount As Integer
    Dim wFirst As Integer
    Dim wLast As Integer
    If Position = 0 Then Position = 1
    If WordCount = 0 Then WordCount = 1
    If Separator = "" Then Separator = " "
    arr = VBA.Split(Trim(Source), Separator)
    xCount = UBound(arr) + 1
    If Position < 1 Then
    wFirst = Application.Max(xCount + Position - WordCount + 1, 0)
    wLast = xCount + Position
    Else
    wFirst = Position - 1
    wLast = Application.Min(xCount - 1, Position + WordCount - 2)
    End If
    If xCount < 2 Or Abs(Position) > xCount Then
    WMid1 = ""
    Else
    WMid1 = arr(wFirst)
    For wCount = wFirst + 1 To wLast
    WMid1 = WMid1 & Separator & arr(wCount)
    Next
    End If
    WMid1 = Trim(WMid1)
    End Function
  • To post as a guest, your comment is unpublished.
    Thang Nguyen · 4 years ago
    Hi geeks,

    I have a cell like this: 1 ABCD; 2 DEDF; 1 DED#3d; 4 FDWDS; 1 ED

    And I would like to extract character after 1. So desired to have a result as below: ABCD;DED#3d;ED
  • To post as a guest, your comment is unpublished.
    Allart · 4 years ago
    Try this (see my reply above):

    Function FindWord(Source As String, Position As Integer)
    ' gets 1st, 2nd, last(0), second to last(-2) etc, word from a string
    ' Update 20150505
    Dim arr() As String
    arr = VBA.Split(WorksheetFunction.Trim(Source), " ")
    xCount = UBound(arr)
    Select Case Position
    Case -xCount To 0
    FindWord = arr(Position + xCount)
    Case 1 To xCount + 1
    FindWord = arr(Position - 1)
    Case Else
    FindWord = ""
    End Select
  • To post as a guest, your comment is unpublished.
    cheezfri · 4 years ago
    I can't get the code for the first word to work if some of my list has only one word in the cell. e.g.
    first word ---> first
    second ---> [null]
    last word ---> last
  • To post as a guest, your comment is unpublished.
    Angelia · 4 years ago
    Hi..
    Thanks for your code, i have list sentences, and one of them just 1 word, and your code not work if its just only have 1 word..
  • To post as a guest, your comment is unpublished.
    Nico · 4 years ago
    Thank You soooo MUCH!!
  • To post as a guest, your comment is unpublished.
    Badan · 4 years ago
    Thanks, Alan, this is great, thanks! :)
  • To post as a guest, your comment is unpublished.
    Allart · 4 years ago
    Hi, just an addition to the code yesterday. This adds an extra line to adjust for redundant spaces in the source string:

    arr = VBA.Split(WorksheetFunction.Trim(Source), " ")

    regards,
    Allart
  • To post as a guest, your comment is unpublished.
    Allart · 4 years ago
    Hi,

    Thanks for your piece of code. It inspired me to expand a little. With the next lines, you can select: last word (0), one but last (-1), second to last (-2) etc. Regardless of number of words.

    Function FindWord(Source As String, Position As Integer)
    'Update 20150504
    Dim arr() As String
    arr = VBA.Split(Source, " ")
    xCount = UBound(arr)
    Select Case Position
    Case -xCount To 0
    FindWord = arr(xCount + Position)
    Case 1 To (xCount + 1)
    FindWord = arr(Position - 1)
    Case Else
    FindWord = ""
    End Select
    End Function
  • To post as a guest, your comment is unpublished.
    Mohammad · 4 years ago
    Much appreciated. It helped me a lot.
  • To post as a guest, your comment is unpublished.
    yücel · 4 years ago
    how can we change fonts for nth word in a cell
  • To post as a guest, your comment is unpublished.
    MikeSyr · 4 years ago
    This does not work properly on a source string made up of non-words (like vendor names followed by part numbers)
  • To post as a guest, your comment is unpublished.
    Badan12 · 4 years ago
    Hi,

    This really saves a lot of time. Thanks for sharing Can someone also suggest how we can extract the words with vba in a reverse way, e.g last word is 1, the second from right to left is 2 and so on. This will be much appreciated.
  • To post as a guest, your comment is unpublished.
    Balu · 4 years ago
    Good one. This worked very well
  • To post as a guest, your comment is unpublished.
    Balu · 4 years ago
    Hi,

    This is excellent. It worked very well and reduces our strain saves lots of time in this operation.

    Thanks to all who worked on this and shared...
  • To post as a guest, your comment is unpublished.
    baynes@ecg-inc.com · 5 years ago
    Hi, I was just wondering what else I could insert into the Visual Basic formula that could extract and commas or dashs immediatly after the data..

    for e.g. Fortin-
  • To post as a guest, your comment is unpublished.
    Chad · 5 years ago
    This was SUPER helpful, I was wondering if anyone knew of a downloadable, or a copy and pastable list of helpful hand made functions such as the "FindWord" that I would be able to use.
  • To post as a guest, your comment is unpublished.
    Alexandros · 5 years ago
    Thanks a lot! Worked fine! :-)
  • To post as a guest, your comment is unpublished.
    Jarad · 5 years ago
    This user-defined function is awesome! Thanks a ton for sharing it.
  • To post as a guest, your comment is unpublished.
    Edgar · 5 years ago
    That vba code is fantastic, thanks a lot.