返回列表 上一主題 發帖

[發問] 如何利用VBA刪除字串前後的數字或英文字串

回復 1# jsleee


   

Function test(s As String) As String
    Dim reg As Object
    Set reg = CreateObject("vbscript.regexp")
    With reg
        .Global = True
        .Pattern = "[A-Za-z0-9]+"
        test = .Replace(s, "")
    End With
End Function

TOP

回復 3# jsleee

撰寫函式程式
https://learn.microsoft.com/zh-tw/office/vba/language/concepts/getting-started/writing-a-function-procedure
    Function test(s As String) As String
    定義
    Dim reg As Object
正規表示式物件
    Set reg = CreateObject("vbscript.regexp")

    With reg
全局匹配模式
        .Global = True
匹配模式 大小寫a~z,數字 0~9
        .Pattern = "[A-Za-z0-9]+"
把大小寫a~z,數字 0~9,用空白取代
        test = .Replace(s, "")
    End With
End Function

TOP

        靜思自在 : 一個人的快樂.不是因為他擁有得多,而是因為他計較得少。
返回列表 上一主題