|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub 小票()
Application.ScreenUpdating = False
Dim ar As Variant
Dim d As Object, dc As Object
Set d = CreateObject("scripting.dictionary")
With Sheets("订单列表")
r = .Cells(Rows.Count, 1).End(xlUp).Row
ar = .Range("a1:q" & r)
End With
For i = 2 To UBound(ar)
If Trim(ar(i, 12)) = "送货上门" Then
If Trim(ar(i, 1)) <> "" Then
d(Trim(ar(i, 1))) = ""
End If
End If
Next i
With Sheets("送货上门")
.UsedRange.Clear
For Each k In d.keys
n = 0
ReDim br(1 To UBound(ar), 1 To UBound(ar, 2))
For i = 2 To UBound(ar)
If Trim(ar(i, 12)) = "送货上门" Then
If Trim(ar(i, 1)) = k Then
n = n + 1
For j = 1 To UBound(ar, 2)
br(n, j) = ar(i, j)
Next j
End If
End If
Next i
rs = .Cells(Rows.Count, 2).End(xlUp).Row + 2
If rs = 3 Then
rs = 1
Else
rs = rs
End If
Sheets("生成小票").Rows("1:6").Copy .Cells(rs, 1)
.Cells(rs + 1, 3) = br(1, 3)
.Cells(rs + 2, 3) = br(1, 1)
.Cells(rs + 3, 3) = br(1, 2)
.Cells(rs + 4, 3) = br(1, 13)
.Cells(rs + 4, 4) = br(1, 14)
.Cells(rs + 5, 3) = br(1, 16)
xh = rs + 6
For i = 1 To n
Sheets("生成小票").Rows("7:10").Copy .Cells(xh, 1)
.Cells(xh, 3) = br(i, 6)
.Cells(xh + 1, 3) = br(i, 7)
.Cells(xh + 1, 5) = br(i, 8)
.Cells(xh + 2, 3) = br(i, 9)
.Cells(xh + 2, 5) = br(i, 10)
.Cells(xh + 3, 3) = br(i, 11)
.Cells(xh + 3, 5) = br(i, 17)
xh = xh + 4
Next i
Next k
End With
Application.ScreenUpdating = True
MsgBox "ok!"
End Sub
|
|