跳到主要内容

如何从单元格中提取每个单词的首字母?

想象一下,您的工作表中有一个国家/地区名称列表,并且您想要提取这些名称中每个单词的第一个字母。 Excel 不提供直接提取单元格中每个单词首字母的功能。不过,我将介绍一些实用的方法来有效地完成这项任务,使过程简单有效。


使用公式从单元格中提取每个单词的第一个字母

要获取单元格中每个单词的第一个字母,以下数组公式可以帮助您。

1. 请将以下公式复制到要计算结果的空白单元格中,然后按 Ctrl + Shift + Enter 键在一起以获得第一个结果。

=CONCAT(LEFT(FILTERXML("<a><b>"&SUBSTITUTE(A2," ","</b><b>")&"</b></a>","//b"),1))

2. 接下来,向下拉公式以填充其他单元格。此操作将自动一次性提取每个单元格中每个单词的第一个字母。看截图:

这个公式的解释:
  • 替换(A2,“”,“ ”):此函数将单元格 A2 中文本中的每个空格替换为 。这可以使用这些 XML 标签有效地分隔文本中的每个单词。例如,如果 A2 包含“Hello World”,则该部分公式会将其转换为“Hello World”。
  • ” “&...&” “:这部分将 SUBSTITUTE 函数的结果包装在开头和结尾。继续该示例,该字符串现在变为Hello World ,形成一个有效的 XML 结构,其中每个单词都包含在标签内。
  • FILTERXML(...,"//b"):FILTERXML 用于解析前面步骤中创建的 XML 字符串。 XPath 查询 //b 选择标签内的所有元素,即原始字符串中的每个单词。使用我们的示例,FILTERXML 将返回一个包含两个元素的数组:“Hello”和“World”。
  • 左(...,1):然后将 LEFT 函数应用于 FILTERXML 返回的数组的每个元素,提取每个单词的第一个字母。在示例中,这将导致“H”和“W”。
  • 连接(...):最后,CONCAT 函数将数组的所有元素连接成一个字符串。对于我们的“Hello World”示例,它将连接“H”和“W”以生成“HW”。

使用 Kutools AI Aide 从单元格中提取每个单词的第一个字母

快速提取单元格中每个单词的第一个字母 Kutools 人工智能助手。无需复杂的公式; AI助手为您自动执行任务,使数据处理变得简单高效。简化您的 Excel 工作流程,让您的工作更轻松。尝试 Kutools 人工智能助手 体验智能Excel操作!

备注: 要使用这个 Kutools 人工智能助手 of Kutools for Excel下载并安装 Kutools for Excel 第一。

安装 Kutools for Excel 后,请单击 Kutools人工智能 > 人工智能助手 打开 Kutools 人工智能助手 窗格:

  1. 选择数据列表,然后在聊天框中输入您的需求,然后单击 提交 按钮或按下 输入 发送问题的键;
  2. 分析完后点击 执行 按钮运行。 Kutools AI Aide 将使用 AI 处理您的请求并直接在 Excel 中返​​回结果。


使用用户定义的功能从单元格中提取每个单词的第一个字母

从单元格中提取每个单词的第一个字母是一项可以通过使用 Excel 中的用户定义函数 (UDF) 大大优化的任务。本节探讨如何创建和使用 UDF 来有效地执行此任务。

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

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

Function GetFirstLetters(rng As Range) As String
'Updateby Extendoffice
    Dim arr
    Dim I As Long
    arr = VBA.Split(rng, " ")
    If IsArray(arr) Then
        For I = LBound(arr) To UBound(arr)
            GetFirstLetters = GetFirstLetters & Left(arr(I), 1)
        Next I
    Else
        GetFirstLetters = Left(arr, 1)
    End If
End Function

3.然后保存并关闭此代码,返回工作表,并输入此公式 = GetFirstLetters(A2) 进入空白单元格。然后,将填充柄拖动到要应用此公式的单元格。并且所有第一个字母都已从该系列单词中提取出来,请参见屏幕截图:


相关文章:

  • 从文本字符串中提取前两个或后两个或 n 个单词
  • 如果现在有一个由空格分隔的文本字符串列表,现在,您要从单元格值中提取前三个或n个单词,以获取以下屏幕截图结果。 本文,我将介绍一些公式来从Excel的文本字符串中提取前两个或n个单词。
  • 仅提取空格或逗号之前/之后的文本
  • 当您要从列表中提取空格之前或之后的文本时,如下所示,您是否有一种很好的方法来完成它? 让我告诉您一些技巧,仅在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 (18)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Hello, If the the nth Word is enclosed in a (), it is returning the ( since it comes before the First Letter.

Example:
Word Word (Word)

How to return WWW instead of WW( ?
This comment was minimized by the moderator on the site
Hello, Sharmane
Maybe the following code can help you:
Function GetFirstLetters(rng As Range) As String
    Dim arr() As String
    Dim i As Long
    
    arr = VBA.Split(rng.Value, " ")
    
    For i = LBound(arr) To UBound(arr)
        If Left(arr(i), 1) <> "(" And Right(arr(i), 1) <> ")" Then
            GetFirstLetters = GetFirstLetters & Left(arr(i), 1)
        ElseIf Left(arr(i), 1) = "(" And Right(arr(i), 1) = ")" Then
            GetFirstLetters = GetFirstLetters & Mid(arr(i), 2, 1)
        End If
    Next i
End Function


Please have a try, thank you!
This comment was minimized by the moderator on the site
Another suggestion if using Microsoft 365: =TEXTJOIN("",,LEFT(TEXTSPLIT(D9," "),1)) where the source string is in B9.
Wrap in UPPER function to enforce uppercase: =UPPER(TEXTJOIN("",,LEFT(TEXTSPLIT(D9," "),1)))
@Pradeep Gyawali -> add space: =UPPER(TEXTJOIN(" ",,LEFT(TEXTSPLIT(D9," "),1)))
This comment was minimized by the moderator on the site
Wondering how to add this into the existing formula I have that works to bring the value over from a cell in another sheet? I only want to bring over the first character in each cell. Here's the formula

=IF(LOOKUP(2,1/(OriginalSubmission!D:D<>""),ROW(OriginalSubmission!D:D))=ROW(OriginalSubmission!D4),"",INDIRECT("OriginalSubmission!D5:"&"D"&(LOOKUP(2,1/(OriginalSubmission!D:D<>""),ROW(OriginalSubmission!D:D)))))
This comment was minimized by the moderator on the site
Hello, SARAH
Do you mean extracting each first character in cells from another worksheet? If so, you just need to copy and paste the code in this article, and then apply this formula into another sheet.
=GetFirstLetters(OriginalSubmission!D4)


Note: OriginalSubmission is the sheet name that you want to extract charatcers from.
Please try, hope it can help you!
This comment was minimized by the moderator on the site
How to create space between the letters?

South Korea= S K
This comment was minimized by the moderator on the site
Hi, Gyawali
If you want to add space for each character, please apply the following VBA code:
Function GetFirstLetters(Rng As Range) As String
'Updateby Extendoffice
    Dim xStr
    Dim arr
    Dim I As Long
    xStr = " "
    arr = VBA.Split(Rng, " ")
    If IsArray(arr) Then
        For I = LBound(arr) To UBound(arr)
            GetFirstLetters = GetFirstLetters & Left(arr(I), 1) & xStr
        Next I
    Else
        GetFirstLetters = Left(arr, 1) & xStr
    End If
End Function


After insert the code, and then apply this formula: =GetFirstLetters(A2) to get the result you need.
Please try, hope it can help you!
This comment was minimized by the moderator on the site
Why is this giving me the first 2 letters in each word?
This comment was minimized by the moderator on the site
This is awesome. Such a time saver
This comment was minimized by the moderator on the site
This code is good for upto five words, where D20 is the cell with data.



=IF(ISERR(LEFT($D$20,1)&MID($D$20,SEARCH(" ",$D$20)+1,1)
&MID($D$20,SEARCH(" ",$D$20,SEARCH(" ",$D$20)+1)+1,1)
&MID($D$20,SEARCH(" ",$D$20,SEARCH(" ",$D$20,SEARCH(" ",$D$20)+1)+1)+1,1)
&MID($D$20,SEARCH(" ",$D$20,SEARCH(" ",$D$20,SEARCH(" ",$D$20,SEARCH(" ",
$D$20)+1)+1)+1)+1,1)),IF(ISERR(LEFT($D$20,1)&MID($D$20,SEARCH(" ",$D$20)+1,1)
&MID($D$20,SEARCH(" ",$D$20,SEARCH(" ",$D$20)+1)+1,1)
&MID($D$20,SEARCH(" ",$D$20,SEARCH(" ",$D$20,SEARCH(" ",$D$20)+1)+1)+1,1)),
IF(ISERR(LEFT($D$20,1)&MID($D$20,SEARCH(" ",$D$20)+1,1)
&MID($D$20,SEARCH(" ",$D$20,SEARCH(" ",$D$20)+1)+1,1)),
IF(ISERR(LEFT($D$20,1)&MID($D$20,SEARCH(" ",$D$20)+1,1)),
IF(ISERR(LEFT($D$20,1)),"",LEFT($D$20,1)),LEFT($D$20,1)
&MID($D$20,SEARCH(" ",$D$20)+1,1)),LEFT($D$20,1)&MID($D$20,SEARCH(" ",$D$20)+1,1)
&MID($D$20,SEARCH(" ",$D$20,SEARCH(" ",$D$20)+1)+1,1)),
LEFT($D$20,1)&MID($D$20,SEARCH(" ",$D$20)+1,1)
&MID($D$20,SEARCH(" ",$D$20,SEARCH(" ",$D$20)+1)+1,1)
&MID($D$20,SEARCH(" ",$D$20,SEARCH(" ",$D$20,SEARCH(" ",$D$20)+1)+1)+1,1)),LEFT($D$20,1)
&MID($D$20,SEARCH(" ",$D$20)+1,1)&MID($D$20,SEARCH(" ",$D$20,SEARCH(" ",$D$20)+1)+1,1)
&MID($D$20,SEARCH(" ",$D$20,SEARCH(" ",$D$20,SEARCH(" ",$D$20)+1)+1)+1,1)
&MID($D$20,SEARCH(" ",$D$20,SEARCH(" ",$D$20,SEARCH(" ",$D$20,SEARCH(" ",$D$20)+1)
+1)+1)+1,1))
This comment was minimized by the moderator on the site
Подскажите пожалуйста, можно ли модифицировать код чтобы забиралась не первые а Заглавные буквы?
This comment was minimized by the moderator on the site
i think it has one bug, it's automatically removed from module when sheet is closed, need to again every time when open sheet same process to be required, please advice how to save this formula in excel permanently.
This comment was minimized by the moderator on the site
Pls save excel as Excel Macro-Enablel work book.
This comment was minimized by the moderator on the site
Please include this part: If you create a function called DISCOUNT in a workbook called Personal.xlsb and you call that function from another workbook, you must type =personal.xlsb!discount(), not simply =discount(). https://support.office.com/en-us/article/Create-Custom-Functions-in-Excel-2007-2f06c10b-3622-40d6-a1b2-b6748ae8231f
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