- Sub test()
- ar = Range("A1").CurrentRegion.Resize(, 2)
- r = UBound(ar)
- ReDim br(1 To r, 1 To 1)
- br(1, 1) = "反馈"
- Set d = CreateObject("scripting.dictionary")
- Set reg = CreateObject("vbscript.regexp")
- reg.Pattern = "^\d+、"
- For i = 2 To r
- If ar(i, 2) = 0 Then
- br(i, 1) = "抵消"
- Else
- f1 = ar(i, 1) & IIf(ar(i, 2) < 0, "正", "负") & Abs(ar(i, 2))
- If d.exists(f1) Then
- br(i, 1) = "抵消"
- x = d(f1)
- br(Val(x), 1) = "抵消"
- x = reg.Replace(x, "")
- If x = "" Then d.Remove f1 Else d(f1) = x
- Else
- f0 = ar(i, 1) & IIf(ar(i, 2) > 0, "正", "负") & Abs(ar(i, 2))
- d(f0) = d(f0) & i & "、"
- End If
- End If
- Next
- Range("C1").Resize(r) = br
- End Sub
复制代码 |