|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Sub dddd()
Dim d As Object, arr, brr(), i, n, m, c, r
Set d = CreateObject("scripting.dictionary")
arr = Sheets("sheet1").Range("a1:c" & Sheets("sheet1").Cells(Rows.Count, 1).End(xlUp).Row)
For i = 1 To UBound(arr)
If Not d.exists(arr(i, 1) & arr(i, 2)) Then
n = n + 1
d(arr(i, 1) & arr(i, 2)) = n
ReDim Preserve brr(1 To 3, 1 To n)
brr(1, n) = arr(i, 1)
brr(2, n) = arr(i, 2)
brr(3, n) = arr(i, 3)
Else
m = d(arr(i, 1) & arr(i, 2))
brr(3, m) = CStr(brr(3, m) & ";" & arr(i, 3))
End If
Next
With Sheets("sheet2")
.Range("a:c").ClearContents
For c = 1 To UBound(brr, 2)
For r = 1 To 3
.Cells(c, r) = brr(r, c)
Next
Next
End With
End Sub
(不知什么原因不能对数组进行转置,只能采取对brr数组进行循环的方式) |
|