|
楼主 |
发表于 2018-1-10 08:02
|
显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Function RegXToCalculate(RegX As RegExp, Rng As Range)
- Dim oRng As Range
- Dim PattStr
- Dim ii As Integer, Str, Str1, RepStr As String
- Str1 = Replace(Rng.Formula, "=", "")
-
- Dim MatColl As MatchCollection, MatColl1 As MatchCollection
- With RegX
- .Pattern = Rng(, 2)
- Set MatColl = .Execute(Str1) '
- If Rng <> "" Then
- Set oRng = Rng(, "D")
- oRng.Interior.ColorIndex = 4
- ''
- With MatColl
- Set oRng = Rng(, "E")
- oRng.Interior.ColorIndex = 40
- oRng(, 1) = .Count
- ''
- For jj = 0 To .Count - 2
- PattStr = .Item(jj) & "(.*?)" & .Item(jj + 1)
- RegX.Pattern = (PattStr)
- Set MatColl1 = RegX.Execute(Str1)
- Str = .Item(jj) & " & """ & MatColl1(0).submatches(0) & """ & " & .Item(jj + 1)
- Rng(, "C") = Str
- Rng(, "D") = "=" & Str
- Next jj
- oRng(, 0) = Str
- End With
- 'Stop
- End If
- End With
- End Function
复制代码
|
|