Extract Text from Alphanumeric

Anonymous
2017-07-01T07:31:41+00:00

Split from this thread.

Ash2ra3f4

L1O23V4EU

result is Ashraf,LOVEU

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
{count} votes

10 answers

Sort by: Most helpful
  1. HansV 462.4K Reputation points MVP Volunteer Moderator
    2017-07-01T07:44:53+00:00

    Press Alt+F11 to activate the Visual Basic Editor.

    Select Insert > Module.

    Copy the following code into the code module:

    Function ExtractText(s As String) As String

        Dim i As Long

        For i = 1 To Len(s)

            If Not Mid(s, i, 1) Like "[0-9]" Then

                ExtractText = ExtractText & Mid(s, i, 1)

            End If

        Next i

    End Function

    Press Alt+F4 to close the Visual Basic Editor.

    Usage:

    Let's say Ash2ra3f4 is in cell A1.

    In another cell, enter the formula    =ExtractText(A1)

    Make sure that you save the workbook as a macro-enabled workbook (.xlsm) and that you allow macros when you open it.

    1 person found this answer helpful.
    0 comments No comments
  2. Anonymous
    2017-07-01T12:27:57+00:00

    HansV,thanks

    1 person found this answer helpful.
    0 comments No comments
  3. Anonymous
    2017-07-01T14:15:03+00:00

            If Not Mid(s, i, 1) Like "[0-9]" Then

    Here are two other ways in which you could write the above "If..Then" statement from your posted code...

    1. If Not Mid(s, i, 1) Like "#" Then
    2. If Mid(s, i, 1) Like "[!0-9]" Then

    Of the three total methods, I personally favor the last one.

    0 comments No comments
  4. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  5. Anonymous
    2017-07-01T14:54:53+00:00

    Hi.  If you are going down a list of values, here's another option:

    (Example:  A1:A10)

    Sub RemoveNumbers()

        Dim Cell As Range

       

        With CreateObject("VBScript.RegExp")

        .Pattern = "\d"

        .Global = True

        .IgnoreCase = True

        .MultiLine = True

       

        For Each Cell In [A1:A10].Cells

            Cell = .Replace(Cell.Text, vbNullString)

        Next

        End With

    End Sub

    Why not something simpler, like this...

    Sub RemoveNumbers()

        Dim N As Long

        For N = 0 To 9

            [A1:A10].Replace N, "", xlPart, , , , False, False

        Next

    End Sub

    Although, in case the ranges could be large, I'd turn screen updating off...

    Sub RemoveNumbers()

        Dim N As Long

        Application.ScreenUpdating = False

        For N = 0 To 9

            [A1:A10].Replace N, "", xlPart, , , , False, False

        Next

        Application.ScreenUpdating = True

    End Sub

    1 person found this answer helpful.
    0 comments No comments