这将遍历前 200 行,这是非常原始的代码,没有错误捕获。它假设 RE 中总是有 8 个数字。如果任何公式中存在语法错误,则在尝试将错误公式分配给单元格时会引发错误。
Sub splitSpecial()
Dim aParts As Variant
Dim i As Long
Dim RE As Object
Dim ret As Object
Dim sNewFormula As String
Set RE = CreateObject("vbscript.regexp")
For i = 1 To 200 'change 200 to be the last row
aParts = Split(Range("A" & i).Formula, ",")
RE.Pattern = "\[\d{8}\]"
RE.Global = True
Set ret = RE.Execute(Range("A" & i).Formula)
If ret.Count <> 0 Then
sNewFormula = aParts(0) & "," & Replace(Replace(ret.Item(0), "[", ""), "]", "") & _
"," & Replace(Replace(ret.Item(0), "[", ""), "]", "") & ")"
Range("B" & i).Formula = sNewFormula
sNewFormula = aParts(0) & "," & Replace(aParts(1), ret.Item(0), "") & _
"," & Replace(aParts(2), ret.Item(1), "")
Range("C" & i).Formula = sNewFormula
End If
Next i
End Sub