+ Reply to Thread
Results 1 to 6 of 6

how to remove letters from a cell

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    09-19-2007
    Location
    Beirut
    MS-Off Ver
    0365 MSO Version 2109
    Posts
    207

    how to remove letters from a cell

    dear all,

    i have in column A cells with a mix of letters and numbers together in a form like
    letters (seperate) then numbers :

    TG 342841,TG 441472-RX001023
    MS0012146-ML225126
    Civ 126019 Cv 3456006

    I am looking for an easy way to have only numbers extracted into B,C and D example:

    B1 342841
    C1 441472
    D1 001023

    and so on

    I appreciate your usual help

    regards

    R

  2. #2
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: how to remove letters from a cell

    Here is one way. Format columns as text if you want to preserve leading zeros.
    Sub x()
    
    Dim oMatches As Object, i As Long, vOut As Variant, rCell As Range
    
    With CreateObject("VBScript.RegExp")
        .Global = True
        .Pattern = "[0-9]+"
         For Each rCell In Range("A1", Range("A1").End(xlDown))
             Set oMatches = .Execute(rCell)
             ReDim vOut(0 To oMatches.Count - 1)
             For i = 0 To oMatches.Count - 1
                   vOut(i) = oMatches(i).Value
             Next i
            rCell.Offset(, 1).Resize(, i) = vOut
         Next rCell
         
    End With
    
    End Sub

  3. #3
    Forum Contributor
    Join Date
    09-19-2007
    Location
    Beirut
    MS-Off Ver
    0365 MSO Version 2109
    Posts
    207

    Re: how to remove letters from a cell

    Thanks StephenR
    I assume this is a module as to be inserted but what formula goes in B

    thank you

  4. #4
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: how to remove letters from a cell

    That's right. Assumes your data are in A1 and down. No formulae, just run the code.

  5. #5
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: how to remove letters from a cell

    or
    Sub snb()
      with columns(1)
        For j = 1 To 26
          .Replace Chr(64 + j), " "
          .Replace Chr(95 + j), " "
          If j < 5 Then .Replace Choose(j, ",", ".", "-", "_"), " "
        Next
        [A1:A2000] = [index(trim(A1:A2000),)]
       
        .TextToColumns , , , , False, False, False, True, False
      End With
    End Sub



  6. #6
    Forum Contributor
    Join Date
    09-19-2007
    Location
    Beirut
    MS-Off Ver
    0365 MSO Version 2109
    Posts
    207

    Re: how to remove letters from a cell

    thank you...

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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