Sub test()
Sheets("打印发货单").Cells.Clear
Set dNum = CreateObject("scripting.dictionary")
With Sheets("发货单明细")
LastRowA = .Cells(Rows.Count, "a").End(xlUp).Row
For i = 2 To LastRowA
Key = .Cells(i, 8).Value
dNum(Key) = ""
Next
arr = dNum.keys
'.Range("a12").Resize(1, UBound(arr) + 1) = arr
'.Range("a12").Resize(UBound(arr) + 1) = Application.Transpose(arr)
For i = 0 To UBound(arr)
Sheets("模板").[A3] = "客户:"
Sheets("模板").[c3] = ""
Sheets("模板").[f2] = ""
Sheets("模板").Range("A5:F14").ClearContents
k = 0
For j = 2 To LastRowA
If .Cells(j, 8) = arr(i) Then
Sheets("模板").[A3] = "客户:" & .Cells(j, 2)
Sheets("模板").[c3] = .Cells(j, 1)
Sheets("模板").[f2] = arr(i)
Sheets("模板").Cells(5 + k, 1) = .Cells(j, 3)
Sheets("模板").Cells(5 + k, 2) = .Cells(j, 4)
Sheets("模板").Cells(5 + k, 3) = .Cells(j, 5)
Sheets("模板").Cells(5 + k, 4) = .Cells(j, 6)
Sheets("模板").Cells(5 + k, 5) = .Cells(j, 7)
k = k + 1
End If
Next
Sheets("模板").Range("A1:g19").Copy
Sheets("打印发货单").Activate
Sheets("打印发货单").Cells(i * 19 + 1, 1).Select
Selection.PasteSpecial Paste:=xlPasteColumnWidths, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
ActiveSheet.Paste
Next
End With
End Sub
'1 ,18,35
'1 2 3
' 1. 清空sheet页内容
Sheets("打印发货单").Cells.Clear
' 2. 从“发货单明细中拿第八列数据,从第二行开始拿,拿到最后一行”
Set dNum = CreateObject("scripting.dictionary")
With Sheets("发货单明细")
LastRowA = .Cells(Rows.Count, "a").End(xlUp).Row
For i = 2 To LastRowA
Key = .Cells(i, 8).Value
dNum(Key) = ""
Next
' 3. 拿完数据保存在arr中
arr = dNum.keys
'.Range("a12").Resize(1, UBound(arr) + 1) = arr
'.Range("a12").Resize(UBound(arr) + 1) = Application.Transpose(arr)
' 4. 看有多少数据就造多少个客户模板
For i = 0 To UBound(arr)
' 4.1 客户模板信息,A3,C3,F2,以及A5开始到F14的所有位置清空
Sheets("模板").[A3] = "客户:"
Sheets("模板").[c3] = ""
Sheets("模板").[f2] = ""
Sheets("模板").Range("A5:F14").ClearContents
' 4.2 开始构造模板sheet页签。
k = 0
For j = 2 To LastRowA
If .Cells(j, 8) = arr(i) Then
' 从第二行开始,
' 取sheet页签“发货单明细”的第二列给A3,第一列给C3,第八列(已保存在arr里面,这里直接取了)给F2。
Sheets("模板").[A3] = "客户:" & .Cells(j, 2)
Sheets("模板").[c3] = .Cells(j, 1)
Sheets("模板").[f2] = arr(i)
' 再挪数据,取sheet页签“发货单明细”的第三到七列,存到模板页签的对应行1到5列
Sheets("模板").Cells(5 + k, 1) = .Cells(j, 3)
Sheets("模板").Cells(5 + k, 2) = .Cells(j, 4)
Sheets("模板").Cells(5 + k, 3) = .Cells(j, 5)
Sheets("模板").Cells(5 + k, 4) = .Cells(j, 6)
Sheets("模板").Cells(5 + k, 5) = .Cells(j, 7)
k = k + 1
End If
Next
' 拷贝模板页签A1到G19的数据,到打印发货单页签对应区域
Sheets("模板").Range("A1:g19").Copy
Sheets("打印发货单").Activate
Sheets("打印发货单").Cells(i * 19 + 1, 1).Select
这个代码是把“发货单明细”中1到8列信息制作成“打印发货单”的代码。
每一个客户的1到8列信息,生成一个19行的发货单模板,再把这样一个一个客户的发货模板拷贝到“打印发货单”的sheet页签里面。
有没有具体点的😂我看好多都是每行翻译的那种