+ Reply to Thread
Results 1 to 4 of 4

Removing alpha characters from a string with multiple telephone numbers

Hybrid View

  1. #1
    Registered User
    Join Date
    07-30-2018
    Location
    Renton, Washington
    MS-Off Ver
    Office 2007
    Posts
    2

    Removing alpha characters from a string with multiple telephone numbers

    I have a spreadsheet that was created from a database export. One of the fields/cells contains multiple telephone numbers and alpha descriptors. The formatting is not consistent and there can be 1 phone number or 15 listed. Most multiple numbers are separated by a carriage return, rather than a space. The good thing is that all the phone numbers have the same formatting (xxx-xxx-xxxx) which I'm hoping will make it easier.

    I would like to learn how to delete the alpha characters and be left with phone numbers separated with ANY character.
    Once that is completed, I will attempt to use one of the other formulas I found on this site (awesome) to split the phone numbers into separate rows.

    I've attached a sample spreadsheet (At least I hope it is - new to the forum!). The Column I'm looking at is the CKT NO

    Thank you so much!

    Janet
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,615

    Re: Removing alpha characters from a string with multiple telephone numbers

    Try
    Sub test()
        Dim a, i As Long, m As Object, txt1 As String, txt2 As String
        With Range("d1", Range("d" & Rows.Count).End(xlUp)).Resize(, 2)
            a = .Value
            With CreateObject("VBScript.RegExp")
                .Global = True: .MultiLine = True
                .Pattern = "^((\d{3}-){2}\d{4})\b *(.*)$"
                For i = 2 To UBound(a, 1)
                    For Each m In .Execute(a(i, 1))
                        txt1 = txt1 & IIf(txt1 <> "", vbLf, "") & m.submatches(0)
                        txt2 = txt2 & IIf(txt2 <> "", vbLf, "") & m.submatches(2)
                    Next
                    a(i, 1) = txt1: txt1 = ""
                    a(i, 2) = txt2: txt2 = ""
                Next
            End With
            .Value = a
        End With
    End Sub
    Last edited by jindon; 07-31-2018 at 02:52 AM.

  3. #3
    Registered User
    Join Date
    07-30-2018
    Location
    Renton, Washington
    MS-Off Ver
    Office 2007
    Posts
    2

    Re: Removing alpha characters from a string with multiple telephone numbers

    This worked perfect! I don't think I could have ever figured this one out. I have some programming background, but not at this level. I'm planning on studying this one to really understand how it works!
    Thanks so much!

  4. #4
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,615

    Re: Removing alpha characters from a string with multiple telephone numbers

    You are welcome and thanks for the rep.
    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

    If you want to understand the code you will need to google with the key words like

    VBA Regular Expression

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 5
    Last Post: 02-02-2017, 09:11 PM
  2. Removing certain characters (text and numbers) from multiple rows at once
    By rottweiler_lvr in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 02-22-2013, 12:47 PM
  3. Replies: 6
    Last Post: 05-21-2012, 04:07 PM
  4. removing first and last characters of a string
    By jeskit in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-11-2011, 09:45 AM
  5. Replies: 9
    Last Post: 02-04-2011, 06:14 AM
  6. Removing Alpha characters formula
    By will.00 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 04-24-2007, 04:13 AM
  7. Removing Characters From a String of Numbers.
    By Chunkmonki in forum Excel General
    Replies: 1
    Last Post: 09-27-2006, 04:41 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1