|
楼主 |
发表于 2024-1-25 15:41
|
显示全部楼层
您好,当对应关系中存在小括号的时候,替换就失效了,例如 "实收资本(或股本)" 对应 "Z1"
以下是GPT的回答,我想知道还有其他方法吗,谢谢!
- Sub myDemo()
- Dim dic As Object, reg As Object
- Set dic = CreateObject("Scripting.Dictionary")
- Set reg = CreateObject("VBScript.RegExp")
-
- Dim i As Long
- For i = 2 To 5
- dic(Cells(i, "A").Value) = Cells(i, "B")
- Next i
-
- Dim S As String
- S = Range("D2") & "+"
- For i = 0 To dic.Count - 1
- reg.Pattern = Replace(dic.Keys()(i), "(", "\(")
- reg.Pattern = Replace(reg.Pattern, ")", "\)")
- reg.Pattern = reg.Pattern & "([+\-*\/])"
- S = reg.Replace(S, dic.Items()(i) & "$1")
- Next i
-
- Range("F2").Value = Left(S, Len(S) - 1)
- End Sub
复制代码 |
|