|
Sub 拆分bom()
Application.ScreenUpdating = False
Dim ar As Variant
Dim d As Object
Set d = CreateObject("scripting.dictionary")
With Sheets("BOM")
r = .Cells(Rows.Count, 1).End(xlUp).Row
If r < 2 Then MsgBox "BOM为空": End
ar = .Range("a1:c" & r)
End With
With Sheets("计划")
rs = .Cells(Rows.Count, 1).End(xlUp).Row
If rs < 2 Then MsgBox "计划为空": End
br = .Range("a1:c" & rs)
End With
Dim arr()
ReDim arr(1 To UBound(ar) + UBound(ar), 1 To 4)
For I = 2 To UBound(br)
If Trim(br(I, 3)) <> "" Then
fj = br(I, 1)
sl = br(I, 2)
For s = 2 To UBound(ar)
If Trim(ar(s, 1)) = Trim(fj) Then
n = n + 1
arr(n, 1) = ar(s, 2)
arr(n, 2) = fj
arr(n, 3) = sl * ar(s, 3)
arr(n, 4) = br(I, 3)
End If
Next s
End If
Next I
With Sheets("按照父件结果")
ws = .Cells(Rows.Count, 1).End(xlUp).Row
If ws > 1 Then .Range("a2:d" & ws) = Empty
.[a2].Resize(n, UBound(arr, 2)) = arr
End With
Application.ScreenUpdating = True
MsgBox "ok!"
End Sub
|
|