|
Option Explicit
Sub test() '适合VBA,仅供参考
Dim ar, d As Object, i&, j&, k&, s$, t
Set d = CreateObject("Scripting.Dictionary")
With Range("A1").CurrentRegion
.Offset(1, 2).ClearContents
ar = .Value
End With
For j = 3 To UBound(ar, 2)
If Len(ar(1, j)) Then d(ar(1, j)) = j
Next
For i = 2 To UBound(ar)
s = ar(i, 2)
If InStr(s, ";") Then
t = Split(s, ";")
For j = LBound(t) To UBound(t)
k = InStrRev(t(j), "(")
If d.Exists(Left(t(j), k - 1)) Then ar(i, d(Left(t(j), k - 1))) = Val(Mid(t(j), k + 1))
Next
Else
k = InStrRev(s, "(")
If d.Exists(Left(s, k - 1)) Then ar(i, d(Left(s, k - 1))) = Val(Mid(s, k + 1))
End If
Next
Range("A1").CurrentRegion = ar
Set d = Nothing
End Sub |
|