|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
代码如下
Sub test()
arr = Sheet1.[a1].CurrentRegion
Set d = CreateObject("scripting.dictionary")
n = 1
Dim brr(1 To 10000, 1 To 7)
For i = 2 To UBound(arr)
s = arr(i, 1) & arr(i, 4)
If Not d.exists(s) Then n = n + 1: d(s) = n
m = d(s)
brr(m, 1) = arr(i, 1)
brr(m, 2) = arr(i, 2)
brr(m, 3) = arr(i, 3)
brr(m, 4) = arr(i, 4)
brr(m, 5) = arr(i, 5)
brr(m, 6) = brr(m, 6) + arr(i, 6)
If brr(m, 7) = Empty Then brr(m, 7) = arr(i, 7) Else If _
InStr(brr(m, 7), arr(i, 7)) = 0 Then brr(m, 7) = brr(m, 7) & "," & arr(i, 7)
Next
With Sheet2
.[j1].CurrentRegion.Clear
With .[j1].Resize(n, 7)
.Value = brr
.HorizontalAlignment = xlCenter
.Borders.LineStyle = 1
End With
.[j1].Resize(, 7) = arr
.[j1].Resize(, 7).Font.Bold = True
.[j1].Resize(n, 7).Columns.AutoFit
End With
Set d = Nothing
Beep
End Sub
|
|