|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub qushu()
Application.ScreenUpdating = False
Dim ar As Variant
Dim d As Object
Set d = CreateObject("scripting.dictionary")
With Sheets("组件")
r = .Cells(Rows.Count, 1).End(xlUp).Row
If r < 2 Then MsgBox "组件为空!": End
ar = .Range("a1:c" & r)
End With
For i = 2 To UBound(ar)
If Trim(ar(i, 1)) <> "" Then
If Not d.exists(Trim(ar(i, 1))) Then
d(Trim(ar(i, 1))) = ar(i, 2)
Else
d(Trim(ar(i, 1))) = d(Trim(ar(i, 1))) & "|" & ar(i, 2)
End If
End If
Next i
With Sheets("总表")
rs = .Cells(Rows.Count, 1).End(xlUp).Row
br = .Range("a1:c" & r)
ReDim arr(1 To 100000, 1 To 3)
For i = 2 To UBound(br)
If Trim(br(i, 2)) <> "" Then
If d.exists(Trim(br(i, 2))) Then
rr = Split(d(Trim(br(i, 2))), "|")
n = n + 1
For j = 1 To UBound(br, 2)
arr(n, j) = br(i, j)
Next j
For s = 0 To UBound(rr)
n = n + 1
arr(n, 2) = rr(s)
arr(n, 3) = "取消"
Next s
End If
End If
Next i
.Range("a2:c" & r + 1) = Empty
.[a2].Resize(n, UBound(arr, 2)) = arr
End With
Application.ScreenUpdating = True
MsgBox "ok!"
End Sub
|
|