|
- Sub test()
- Dim r%, i%
- Dim arr, brr
- Dim d As Object
- Set d = CreateObject("scripting.dictionary")
- With Worksheets("送货单")
- r = .Cells(.Rows.Count, 2).End(xlUp).Row
- arr = .Range("a5:k" & r)
- End With
- 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
- With Worksheets("送货单列表")
- .Cells.Clear
- r = 3
- For Each aa In d.keys
- ReDim crr(1 To d(aa).Count, 1 To 4)
- m = d(aa).keys()(0)
- brr = Application.Transpose(Application.Transpose(Array(Array("日期:", arr(m, 2), "客户:", arr(m, 8)), Array("单号:", arr(m, 3), "联系:", arr(m, 9)), Array("备注:", arr(m, 11), "地址:", arr(m, 10)))))
- m = 0
- For Each bb In d(aa).keys
- m = m + 1
- crr(m, 1) = arr(bb, 4)
- crr(m, 2) = arr(bb, 5)
- crr(m, 3) = arr(bb, 6)
- crr(m, 4) = arr(bb, 7)
- Next
- With .Cells(r, 2)
- .Value = "送货单"
- .Resize(1, 4).Merge
- End With
- .Cells(r + 1, 2).Resize(UBound(brr), UBound(brr, 2)) = brr
- .Cells(r + 5, 2).Resize(1, 4) = Array("产品", "单价", "数量", "金额")
- .Cells(r + 6, 2).Resize(UBound(crr), UBound(crr, 2)) = crr
- .Cells(r + 6 + UBound(crr), 4) = "合计:"
- With .Cells(r + 6 + UBound(crr), 5)
- .Value = Application.Sum(Application.Index(crr, 0, 4))
- .NumberFormatLocal = "¥#,##0.00_);[红色](¥#,##0.00)"
- .Font.ColorIndex = 3
- End With
- With .Cells(r + 1, 2).Resize(3, 4)
- With .Borders(xlEdgeTop)
- .LineStyle = xlContinuous
- End With
- With .Borders(xlEdgeBottom)
- .LineStyle = xlContinuous
- End With
- End With
- With .Cells(r + 6, 2).Resize(UBound(crr), 4)
- With .Borders(xlEdgeBottom)
- .LineStyle = xlDot
- End With
- With .Borders(xlInsideHorizontal)
- .LineStyle = xlDot
- End With
- End With
- With .Cells(r + 6, 3).Resize(UBound(crr), 1)
- .NumberFormatLocal = "¥#,##0.00_);[红色](¥#,##0.00)"
- End With
- With .Cells(r + 6, 5).Resize(UBound(crr), 1)
- .NumberFormatLocal = "¥#,##0.00_);[红色](¥#,##0.00)"
- End With
- r = r + 6 + UBound(crr) + 2
- Next
- With .UsedRange
- With .Font
- .Name = "等线"
- .Size = 18
- End With
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- End With
-
- End With
- End Sub
复制代码 |
|