RegEx to extract email

后端 未结 4 1740
花落未央
花落未央 2021-01-15 04:52

I need to extract only the email from a spreadsheet in Excel. I\'ve found some example VBA code here at this StackOverflow link, courtesy of Portland Runner

4条回答
  •  天命终不由人
    2021-01-15 05:15

    The easiest way to do this is by installing the software called KUtool. After installing, highlight the content you want to extract emails==>Click ku tools at the top middle==>click on text==>extract emails. You can also use the following code.(ALT+F1==>INSERT MODULE)

    Function ExtractEmailFun(extractStr As String) As String
    'Update 20130829
    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 Ifenter code here
    Loop
    ExtractEmailFun = OutStr
    End Function
    

    You can also go the code way Open excell, click on ALT +F1, Click on insert Module and paste this code

    Click save and enter the formula(Column=ExtractEmailFun(A1)) in a blank cell. press enter and your emails will be extracted. Hope this will help

提交回复
热议问题