|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
参与一下。。。
- Sub ykcbf() '//2024.9.12
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Set d = CreateObject("Scripting.Dictionary")
- Set d1 = CreateObject("Scripting.Dictionary")
- With Sheets("订单明细")
- r = .Cells(Rows.Count, 1).End(3).Row
- arr = .[a1].Resize(r, 20)
- End With
- For i = 2 To UBound(arr)
- s = CStr(arr(i, 4))
- If Not d1.Exists(s) Then
- d1(s) = Array(arr(i, 1), arr(i, 4), arr(i, 2), arr(i, 3), arr(i, 5), arr(i, 10), arr(i, 20))
- End If
- If Not d.Exists(s) Then Set d(s) = CreateObject("Scripting.Dictionary")
- d(s)(i) = ""
- Next
- With Sheets("发货单")
- .Cells.Clear
- For Each k In d.Keys
- n = n + 1
- m = 0
- ReDim brr(1 To d(k).Count, 1 To 5)
- If n = 1 Then
- r = 1
- Sheets("模板").Cells.Copy .Cells(r, 1)
- Else
- r = .Cells(Rows.Count, 1).End(3).Row + 2
- Sheets("模板").Rows("1:17").Copy .Cells(r, 1)
- End If
- For Each kk In d(k).Keys
- m = m + 1
- brr(m, 1) = arr(kk, 6)
- brr(m, 2) = arr(kk, 7)
- brr(m, 3) = arr(kk, 8)
- brr(m, 4) = arr(kk, 9)
- brr(m, 5) = arr(kk, 11)
- Next
- If m > 7 Then
- For i = 1 To m - 7
- .Cells(r + 6 + i, 1).EntireRow.Insert
- Next i
- End If
- .Cells(r + 6, 1).Resize(m, 5) = brr
- .Cells(r + 1, 2) = d1(k)(0): .Cells(r + 1, "d") = d1(k)(1)
- .Cells(r + 2, 2) = d1(k)(2): .Cells(r + 2, "d") = d1(k)(3)
- .Cells(r + 3, 2) = d1(k)(4): .Cells(r + 3, "d") = d1(k)(5)
- .Cells(r + 4, 2) = d1(k)(6)
- Next
- .DrawingObjects.Delete
- End With
- Set d = Nothing
- Set d1 = Nothing
- Application.ScreenUpdating = True
- MsgBox "OK!"
- End Sub
复制代码
|
|