- Private cpdm$, cpmc$
- Sub test()
- Dim r%, i%
- Dim arr
- Set d = CreateObject("scripting.dictionary")
- With Worksheets("BOM")
- .AutoFilterMode = False
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- sjk = .Range("a2:g" & r)
- For i = 1 To UBound(sjk)
- If Not d.exists(sjk(i, 1)) Then
- Set d(sjk(i, 1)) = CreateObject("scripting.dictionary")
- End If
- d(sjk(i, 1))(sjk(i, 3)) = i
- Next
- End With
- With Worksheets("计划订单")
- .AutoFilterMode = False
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- arr = .Range("a2:f" & r)
- End With
- m = 0
- For i = 1 To UBound(arr)
- cpdm = arr(i, 2)
- cpmc = arr(i, 3)
- If arr(i, 5) <> 0 Then
- Call dg(arr(i, 2), arr(i, 5))
- End If
- Next
- With Worksheets("问题")
- .UsedRange.Offset(2, 0).Clear
- If m > 0 Then
- With .Range("a3").Resize(m, UBound(brr, 2))
- .Value = brr
- .Borders.LineStyle = xlContinuous
- End With
- End If
- End With
- End Sub
- Sub dg(ByVal aa As Variant, ByVal jhl As Double)
- Dim i%
- Dim bb As Variant
- For Each bb In d(aa).keys
- i = d(aa)(bb)
- m = m + 1
- brr(m, 1) = cpdm
- brr(m, 2) = cpmc
- brr(m, 3) = aa
- brr(m, 4) = bb
- brr(m, 5) = sjk(i, 4)
- brr(m, 6) = sjk(i, 5)
- brr(m, 7) = sjk(i, 6)
- brr(m, 8) = sjk(i, 7)
- brr(m, 9) = jhl
- brr(m, 10) = brr(m, 7) * brr(m, 9)
- If d.exists(bb) Then
- Call dg(bb, brr(m, 10))
- End If
- Next
- End Sub
复制代码 |