|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Option Explicit
Sub TEST2()
Dim ar, br, i&, j&, r&, iColSize, vKey, dic As Object
Application.ScreenUpdating = False
Set dic = CreateObject("Scripting.Dictionary")
ar = [A1].CurrentRegion.Value
For i = 2 To UBound(ar)
dic(ar(i, 1)) = dic(ar(i, 1)) & "," & ar(i, 2)
Next i
ReDim ar(1 To dic.Count + 1, 1 To UBound(ar))
ar(1, 1) = "料号": ar(1, 2) = "配置": r = 1
For Each vKey In dic.keys
r = r + 1
ar(r, 1) = vKey
br = Split(dic(vKey), ",")
For j = 1 To UBound(br)
ar(r, j + 1) = br(j)
Next j
If iColSize < UBound(br) + 1 Then iColSize = UBound(br) + 1
Next
[D1].CurrentRegion.Clear
With [D1].Resize(UBound(br), iColSize)
.Cells(1, 2).Resize(, iColSize - 1).Merge
.HorizontalAlignment = xlCenter
.Borders.LineStyle = xlContinuous
.Rows(1).Font.Bold = True
.Value = ar
End With
Application.ScreenUpdating = True
Beep
End Sub
|
|