|
- Sub test1()
- Dim ar, br, Re As Object, Dict As Object
- Dim i As Long, p As Long, sStr As String
- Set Dict = CreateObject("Scripting.Dictionary")
- Set Re = CreateObject("VBScript.Regexp")
- Re.Global = True
- Re.Pattern = "([\u4e00-\u9fa5]+)([((]+)([A-Za-z]+)([))]+)(\d+)"
- With Range("E1", Cells(Rows.Count, "B").End(xlUp))
- Intersect(.Offset(0, 0), .Offset(1, 2)).ClearContents
- ar = .Value
- End With
- For i = 2 To UBound(ar)
- sStr = Re.Replace(Trim(ar(i, 1)) & Trim(ar(i, 2)), "($3)$1道|$5")
- If Not Dict.Exists(sStr) Then Dict.Add sStr, i
- Next
- Re.Pattern = "([A-Za-z]+)(\d+)"
- br = Range("I1", Cells(Rows.Count, "G").End(xlUp)).Value
- For i = 2 To UBound(br)
- sStr = Trim(Replace(Replace(br(i, 1), "(", "("), ")", ")")) & Re.Replace(br(i, 2), "|$2")
- If Dict.Exists(sStr) Then
- p = Dict(sStr)
- ar(p, 3) = Val(ar(p, 3)) + Val(br(i, 3)) & "m"
- ar(p, 4) = ar(p, 4) + 1
- End If
- Next
- Range("B1").Resize(UBound(ar), UBound(ar, 2)) = ar
- Set Re = Nothing
- Set Dict = Nothing
- Beep
- End Sub
复制代码 |
|