|
求大家帮帮忙了。
- Sub SC1()
- Dim arr, arr1, d As Object, d1 As Object, d2 As Object, x&
- Set d = CreateObject("scripting.dictionary")
- Set d1 = CreateObject("scripting.dictionary")
- Set d2 = CreateObject("scripting.dictionary")
- With Sheets("sheet1")
- arr = .Range("A2:B" & .[A65536].End(3).Row)
- End With
- With Sheets("bom")
- arr1 = .Range("A2:F" & .[A65536].End(3).Row)
- End With
- For x = 1 To UBound(arr)
- For y = 1 To UBound(arr1)
- If arr1(y, 1) = arr(x, 1) And arr1(y, 6) <> "自制品" Then
- d(arr1(y, 2)) = d(arr1(y, 2)) + arr1(y, 5) * arr(x, 2)
- d1(arr1(y, 2)) = arr1(y, 3)
- d2(arr1(y, 2)) = arr1(y, 4)
- End If
- Next y
- Next x
- Sheets("sheet3").Select
- Range("A:D").Clear
- [a4].Resize(d.Count, 1) = Application.Transpose(d.keys)
- [b4].Resize(d.Count, 1) = Application.Transpose(d1.items)
- [c4].Resize(d.Count, 1) = Application.Transpose(d2.items)
- [d4].Resize(d.Count, 1) = Application.Transpose(d.items)
- [a3] = "物料编号"
- [b3] = "物料名称"
- [c3] = "单位"
- [d3] = "数量"
- [a3].Resize(d.Count + 1, 4).Borders.LineStyle = 1
- End Sub
复制代码
|
|