跳到主要內容

如何快速從文本字符串中提取電子郵件地址?

當您從“網站”到Excel工作表中導入一些電子郵件地址時,總是包含不相關的文本,但是現在您只想從文本字符串中提取純電子郵件地址(請參見以下屏幕截圖)。 您怎麼能快速僅從單元格文本中獲取電子郵件地址?

文檔提取電子郵件1 -2 文檔提取電子郵件2

使用公式從文本字符串中提取電子郵件地址

使用用戶定義的功能從文本字符串中提取電子郵件地址

使用VBA代碼從文本字符串中提取電子郵件地址

使用Kutools for Excel從文本字符串中提取電子郵件地址


箭頭藍色右氣泡 使用公式從文本字符串中提取電子郵件地址

在這裡,我向您介紹一個很長的公式,僅從Excel中的文本中提取電子郵件地址。 請執行以下操作:

1。 在相鄰的單元格B1中,輸入此公式 = TRIM(RIGHT(SUBSTITUTE(LEFT(A1,FIND(“”,A1&“”,FIND(“ @”,A1))-1),“”,REPT(“”,LEN(A1)))),LEN( A1))).

文檔提取電子郵件3

2。 然後按 Enter 鍵,然後選擇單元格B1,然後將填充手柄拖到要包含此公式的範圍。 並且已從文本字符串中提取了該範圍內的電子郵件地址。 看截圖:

文檔提取電子郵件4

筆記:

1.電子郵件地址後的標點符號也將被提取。

2.如果單元格中不包含電子郵件地址,則公式將顯示錯誤值。

3.如果一個單元格中有多個電子郵件地址,則該公式將僅提取第一個地址。


從文本字符串中提取多個電子郵件地址

Excel的Kutools 提取電子郵件地址 可以幫助您快速方便地從文本字符串中提取電子郵件地址。 點擊下載Kutools for Excel!

doc提取電子郵件-1

Excel的Kutools:具有300多個方便的Excel加載項,可以在30天內免費試用,沒有任何限制。 立即下載並免費試用!


箭頭藍色右氣泡 使用用戶定義的功能從文本字符串中提取電子郵件地址

除上述公式外,用戶定義函數還可以幫助您從文本字符串中獲取電子郵件地址。

1。 按住 ALT + F11 鍵,然後打開 Microsoft Visual Basic for Applications 窗口。

2。 點擊 插入 > 模塊,然後將以下宏粘貼到“模塊”窗口中。

Function ExtractEmailFun(extractStr As String) As String
'Update by extendoffice
Dim CharList As String
On Error Resume Next
CheckStr = "[A-Za-z0-9._-]"
OutStr = ""
Index = 1
Do While True
    Index1 = VBA.InStr(Index, extractStr, "@")
    getStr = ""
    If Index1 > 0 Then
        For p = Index1 - 1 To 1 Step -1
            If Mid(extractStr, p, 1) Like CheckStr Then
                getStr = Mid(extractStr, p, 1) & getStr
            Else
                Exit For
            End If
        Next
        getStr = getStr & "@"
        For p = Index1 + 1 To Len(extractStr)
            If Mid(extractStr, p, 1) Like CheckStr Then
                getStr = getStr & Mid(extractStr, p, 1)
            Else
                Exit For
            End If
        Next
        Index = Index1 + 1
        If OutStr = "" Then
            OutStr = getStr
        Else
            OutStr = OutStr & Chr(10) & getStr
        End If
    Else
        Exit Do
    End If
Loop
ExtractEmailFun = OutStr
End Function

3。 然後保存代碼並輸入公式 = ExtractEmailFun(A1) 在相鄰的空白單元格中,請參見屏幕截圖:

文檔提取電子郵件5

4。 然後按 Enter 鍵,選擇單元格B1,然後將填充手柄拖到所需公式的範圍內。 並且所有電子郵件地址均已從單元格文本中提取。 看截圖:

文檔提取電子郵件6

筆記:

1.如果單元格沒有電子郵件地址,它將顯示空白單元格。

2.如果一個單元中有多個電子郵件地址,則將提取所有電子郵件。


箭頭藍色右氣泡 使用VBA代碼從文本字符串中提取電子郵件地址

如果您認為上述公式對您來說很麻煩,則以下VBA代碼可以幫助您一次提取電子郵件地址。

1。 按住 ALT + F11 鍵,它會打開一個 Microsoft Visual Basic for Applications 窗口。

2。 點擊 插入 > 模塊,然後將以下宏粘貼到 模塊窗口.

VBA:從文本字符串中提取電子郵件地址

Sub ExtractEmail()
'Update 20130829
Dim WorkRng As Range
Dim arr As Variant
Dim CharList As String
On Error Resume Next
xTitleId = "KutoolsforExcel"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
arr = WorkRng.Value
CheckStr = "[A-Za-z0-9._-]"
For i = 1 To UBound(arr, 1)
    For j = 1 To UBound(arr, 2)
        extractStr = arr(i, j)
        outStr = ""
        Index = 1
        Do While True
            Index1 = VBA.InStr(Index, extractStr, "@")
            getStr = ""
            If Index1 > 0 Then
                For p = Index1 - 1 To 1 Step -1
                    If Mid(extractStr, p, 1) Like CheckStr Then
                        getStr = Mid(extractStr, p, 1) & getStr
                    Else
                        Exit For
                    End If
                Next
                getStr = getStr & "@"
                For p = Index1 + 1 To Len(extractStr)
                    If Mid(extractStr, p, 1) Like CheckStr Then
                        getStr = getStr & Mid(extractStr, p, 1)
                    Else
                        Exit For
                    End If
                Next
                Index = Index1 + 1
                If outStr = "" Then
                    outStr = getStr
                Else
                    outStr = outStr & Chr(10) & getStr
                End If
            Else
                Exit Do
            End If
        Loop
        arr(i, j) = outStr
    Next
Next
WorkRng.Value = arr
End Sub

3。 然後按 F5 鍵來運行此代碼,您應該在彈出的對話框中選擇要使用VBA的範圍,請參見屏幕截圖:

文檔提取電子郵件7

4。 然後點擊 OK,並且已從所選文本字符串中提取電子郵件地址。 查看屏幕截圖:

文檔提取電子郵件8 -2 文檔提取電子郵件9

筆記:

1.如果單元格沒有電子郵件地址,它將顯示空白單元格。

2.如果一個單元中有多個電子郵件地址,則將提取所有電子郵件。

3.提取的電子郵件將覆蓋原始數據,因此,如果需要,最好先備份數據。


箭頭藍色右氣泡 一鍵使用Kutools for Excel從文本字符串中提取電子郵件地址

對於我們的Excel初學者來說,以上方法看起來有些複雜,在這裡,我可以向您推荐一種快速簡便的工具- Excel的Kutools,其 提取電子郵件地址 實用程序,您可以輕鬆地從文本字符串中提取電子郵件地址。

Excel的Kutools : 帶有300多個便捷的Excel加載項,可以在30天內免費試用.

如果你已經安裝 Excel的Kutools,請執行以下操作:

1。 選擇包含文本字符串的單元格。

2。 點擊 庫工具 > 文本 > 提取電子郵件地址,請參見屏幕截圖:

3。 和 提取電子郵件地址 對話框將彈出,選擇要放置結果的單元格,請參見屏幕截圖:

文檔提取電子郵件9

4。 然後點擊 OK 按鈕,已從文本字符串中提取所有電子郵件地址,請參見屏幕截圖:

文檔提取電子郵件9

點擊下載並立即免費試用Excel的Kutools!


箭頭藍色右氣泡 演示:使用Kutools for Excel從文本字符串中提取電子郵件地址

Excel的Kutools:具有300多個方便的Excel加載項,可以在30天內免費試用,沒有任何限制。 立即下載並免費試用!

相關文章:

如何從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 (40)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
You're a genius!!!
This comment was minimized by the moderator on the site
Really helpful to extract emails in a neat way, thank you!
This comment was minimized by the moderator on the site
Malheureusement la première formule donnée se met en erreur....
This comment was minimized by the moderator on the site
Thank you very much, spend only half hour looking for this and save me ten hours of work!
This comment was minimized by the moderator on the site
This is the most useful page I have ever found on Excel - thank you.
This comment was minimized by the moderator on the site
How do you extract multiple email addresses for one cell?
This comment was minimized by the moderator on the site
Hi, Donna,
The second and the third methods in this article can help you to extract multiple Email addresses from one cell, please try, thank you!
This comment was minimized by the moderator on the site
Quando extraído mais que um email usando a macro, como separa-los depois usando uma outra célula ? Ou é possível extrair já separando ?
This comment was minimized by the moderator on the site
Saved me hours of manual parsing. Thank you!
This comment was minimized by the moderator on the site
Thank you!
This comment was minimized by the moderator on the site
Hi. This is a great job! I am sure that hundreds of people learned new stuff because of it. But if you just want to extract email addresses, you can use extractemailaddress.com . It seemed simple and quick, and I hav pasted the result in my excel spreadsheet. great!
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