- Sub test()
- Dim r%, i%
- Dim arr, brr
- Dim d As Object
- Set d = CreateObject("scripting.dictionary")
- With Worksheets("sheet1")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- arr = .Range("a2:c" & r)
- For i = 1 To UBound(arr)
- If Len(arr(i, 1)) = 4 Then
- arr(i, 3) = arr(i, 2)
- d(CStr(arr(i, 1))) = arr(i, 2)
- Else
- xm = Left(arr(i, 1), Len(arr(i, 1)) - IIf(Len(arr(i, 1)) = 7, 3, 2))
- If d.exists(xm) Then
- arr(i, 3) = d(xm) & "-" & arr(i, 2)
- d(CStr(arr(i, 1))) = arr(i, 3)
- End If
- End If
- Next
- .Range("a2").Resize(UBound(arr), UBound(arr, 2)) = arr
- End With
- End Sub
复制代码 |