|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Sub test()
- Dim r%, i%
- Dim arr, brr
- Dim d As Object
- Dim rng As Range
- Set d = CreateObject("scripting.dictionary")
- With Worksheets("生产领料明细")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- arr = .Range("a2:j" & r)
- For i = 1 To UBound(arr)
- If Not d.exists(arr(i, 3)) Then
- Set d(arr(i, 3)) = CreateObject("scripting.dictionary")
- End If
- d(arr(i, 3))(i) = Empty
- Next
- End With
- With Worksheets("生产领料单")
- .Cells.Clear
- End With
- r = 1
- With Worksheets("模板")
- For Each aa In d.keys
- r1 = .Cells(.Rows.Count, 2).End(xlUp).Row
- If r1 <> 5 Then
- .Rows("5:" & r1 - 1).Delete
- End If
- ReDim brr(1 To d(aa).Count, 1 To 8)
- m = 0
- i = d(aa).keys()(0)
- For Each bb In d(aa).keys
- m = m + 1
- brr(m, 1) = m
- For j = 2 To 8
- brr(m, j) = arr(bb, j + 2)
- Next
- Next
- .Range("d3") = arr(i, 2)
- .Range("f3") = Application.Sum(Application.Index(brr, 0, 7))
- .Range("h3") = aa
- .Rows(5).Resize(UBound(brr)).Insert
- With .Range("a5").Resize(UBound(brr), UBound(brr, 2))
- .Value = brr
- .Borders.LineStyle = xlContinuous
- End With
- r2 = 4 + UBound(brr) + 1
- .Range("a1:h" & r2).Copy Worksheets("生产领料单").Cells(r, 1)
- r = r + r2 + 1
- Next
- End With
-
- End Sub
复制代码 |
|