|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Sub test()
- Dim r%, i%
- Dim arr, brr
- Dim d As Object
- Set d = CreateObject("scripting.dictionary")
- With Worksheets("物料排期")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- arr = .Range("a2:d" & r)
- rq1 = CDate(Application.Min(.Range("c2:c" & r)))
- ReDim bt(1 To 121)
- bt(1) = "物料"
- bt(2) = rq1
- For j = 3 To UBound(bt)
- bt(j) = bt(j - 1) + 1
- Next
- For i = 1 To UBound(arr)
- sl = arr(i, 4)
- If Not d.exists(arr(i, 1)) Then
- ReDim brr(1 To UBound(bt))
- brr(1) = arr(i, 1)
- Else
- brr = d(arr(i, 1))
- End If
- For j = 2 To UBound(bt)
- If bt(j) = arr(i, 3) Then
- Exit For
- End If
- Next
- If j <= UBound(bt) Then
- For k = j To UBound(brr)
- If arr(i, 2) < sl Then
- brr(k) = arr(i, 2)
- sl = sl - brr(k)
- Else
- brr(k) = sl
- sl = 0
- Exit For
- End If
- Next
- End If
- d(arr(i, 1)) = brr
- Next
- End With
- jsrq = 0
- With Worksheets("结果")
- .Cells.Clear
- .Range("a1").Resize(1, UBound(bt)) = bt
- m = 1
- For Each aa In d.keys
- m = m + 1
- brr = d(aa)
- For j = UBound(brr) To 1 Step -1
- If Len(brr(j)) <> 0 Then
- Exit For
- End If
- Next
- If jsrq < j Then
- jsrq = j
- End If
- .Cells(m, 1).Resize(1, UBound(brr)) = brr
- Next
- .Columns(jsrq + 1).Resize(, .Columns.Count - jsrq).Clear
- End With
- End Sub
复制代码 |
|