How do I remove the characters?

前端 未结 4 1647
一向
一向 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:24

    Non-re alternative;

    Public Function fmt(sValue As String) As String
        Dim i As Long
        For i = 1 To Len(sValue) '//loop each char
            Select Case Mid$(sValue, i, 1) '//examine current char
                Case "0" To "9", " " '//permitted chars
                   '//ok
                Case Else
                   Mid$(sValue, i, 1) = "!" '//overwrite char in-place with "!"
            End Select
        Next
        fmt = Replace$(sValue, "!", "") '//strip invalids & return
    End Function
    

    For:

    ?fmt("qwe123 4567*. 90") 
    123 4567 90
    

提交回复
热议问题