|
本帖最后由 獨一無2 于 2018-7-15 20:58 编辑
可以使用Worksheet_Change事件,判断如果是A1值有变化,则执行宏内的代码。Worksheet_Change为工作表事件
Private Sub Worksheet_Change(ByVal Target As Range)
If Target =Sheet1.Range("A1") Then
Dim result, regx, iLoop, re
Sheet1.Cells(1, "C").value = ""
Set regx = CreateObject("vbscript.regexp")
With regx
.Global = True
.Pattern = "([一-龢]+\d+\D?\d?)"
Set result = .Execute(Sheet1.Cells(1, "A").value)
For iLoop = 0 To result.Count - 1
If "." = Right(result(iLoop).submatches(0), 1) Then
Sheet1.Cells(1, "C").value = Sheet1.Cells(1, "C").value + result(iLoop).submatches(0) + "0"
Else
Sheet1.Cells(1, "C").value = Sheet1.Cells(1, "C").value + result(iLoop).submatches(0)
End If
Next iLoop
End With
End If
End Sub
|
|