excel 正则匹配替换

Private Sub RegExp_Replace()

    Dim RegExp As Object
    Dim SearchRange As Range, Cell As Range
    
    '此处定义正则表达式
    Set RegExp = CreateObject("vbscript.regexp")
    RegExp.Pattern = "^([2]{1})$"
     
    '此处指定查找范围
    Set SearchRange = ActiveSheet.Range("H2:H54083")
    
    '遍历查找范围内的单元格
    For Each Cell In SearchRange
        Set Matches = RegExp.Execute(Cell.Value)
        If Matches.Count >= 1 Then
            Set Match = Matches(0)
            Cell.Value = RegExp.Replace(Cell.Value, "10")
        End If
    Next

End Sub

你可能感兴趣的:(excel 正则匹配替换)