跳到主要內容

如何從單元格中提取每個單詞的首字母?

想像一下,您的工作表中有一個國家/地區名稱列表,並且您想要提取這些名稱中每個單字的第一個字母。 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 Excel的Kutools下載並安裝 Kutools for Excel 第一。

安裝Kutools for Excel之後,請點擊 Kutools人工智慧 > 人工智慧助手 打開 Kutools 人工智慧助手 窗格:

  1. 選擇資料列表,然後在聊天框中輸入您的需求,然後按一下 送出 按鈕或按下 Enter 發送問題的按鍵;
  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選項卡為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