How do I remove the characters?

前端 未结 4 1639
一向
一向 2021-01-17 18:58

How do I remove special characters and alphabets in a string ?

 qwert1234*90)!  \' this might be my cell value

I have to convert it to

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-17 19:33

    Something like this to

    • split the string using a regexp
    • place the matches into an array
    • dump the array to an automatically sized spreadsheet range

    main sub

    Sub CleanStr()
    Dim strOut As String
    Dim Arr
    strOut = Trim(KillChar("qwe123 4567*. 90 "))
    Arr = Split(strOut, Chr(32))
    [a1].Resize(UBound(Arr) + 1, 1) = Application.Transpose(Arr)
    End Sub
    

    function

    Function KillChar(strIn As String) As String
    Dim objRegex As Object
    Set objRegex = CreateObject("vbscript.regexp")
        With objRegex
            .Global = True
            .Pattern = "[^\d\s]+"
            KillChar = .Replace(strIn, vbNullString)
        End With
    End Function
    

提交回复
热议问题