|
- Sub test1()
- Dim sh1, sh2 As Worksheet
- Dim arr, brr As Variant
- Dim dic1 As Object
- Dim i As Integer, j As Integer
- Set sh1 = ThisWorkbook.Sheets("sheet1")
- Set sh2 = ThisWorkbook.Sheets("sheet2")
- arr = sh1.UsedRange
- brr = sh2.UsedRange
- Set dic1 = CreateObject("scripting.dictionary")
- For i = 2 To UBound(arr)
- If arr(i, 2) <> "" And dic1.exists(arr(i, 2)) = True Then
- dic1(arr(i, 2)) = dic1(arr(i, 2)) & "、" & arr(i, 4)
- ElseIf arr(i, 2) <> "" Then
- dic1(arr(i, 2)) = arr(i, 4)
- End If
- Next
- For j = 3 To UBound(brr)
- sh2.Cells(j, 3) = dic1(brr(j, 2))
- Next
- End Sub
复制代码 |
|