|
- Sub test()
- Dim r%, i%
- Dim arr, brr
- Dim d As Object
- Set d = CreateObject("scripting.dictionary")
- Set d1 = CreateObject("scripting.dictionary")
- With Worksheets("BOM")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- arr = .Range("a2:i" & r)
- For i = 1 To UBound(arr)
- If Not d1.exists(arr(i, 1)) Then
- Set d1(arr(i, 1)) = CreateObject("scripting.dictionary")
- End If
- d1(arr(i, 1))(arr(i, 3)) = arr(i, 9)
- Next
- End With
- With Worksheets("生产计划")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- c = .Cells(4, .Columns.Count).End(xlToLeft).Column
- arr = .Range("a4").Resize(r - 3, c)
- End With
- ls = UBound(arr, 2) - 10 + 6
- For i = 2 To UBound(arr)
- If d1.exists(arr(i, 1)) Then
- For Each bb In d1(arr(i, 1)).keys
- If Not d.exists(bb) Then
- ReDim brr(1 To ls)
- brr(1) = bb
- Else
- brr = d(bb)
- End If
- For j = 11 To UBound(arr, 2)
- brr(j - 4) = brr(j - 4) + arr(i, j) * d1(arr(i, 1))(bb)
- Next
- d(bb) = brr
- Next
- End If
- Next
- With Worksheets("物料需求")
- .Cells.Clear
- .Range("a3:f3") = Array("物料代号", "规格", "单位", "其他信息", "描述", "备注")
- For j = 11 To UBound(arr, 2)
- .Cells(3, j - 4) = arr(1, j)
- Next
- .Cells(3, 7).Resize(1, UBound(arr, 2) - 10).NumberFormatLocal = "m月d日"
- .Range("a4").Resize(d.Count, ls) = Application.Transpose(Application.Transpose(d.items))
- With .Range("a3").Resize(1 + d.Count, ls)
- .Borders.LineStyle = xlContinuous
- With .Font
- .Name = "微软雅黑"
- .Size = 11
- End With
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- End With
- End With
- End Sub
复制代码 |
|