|
楼主 |
发表于 2012-5-8 13:08
|
显示全部楼层
附件1 中的代码如下:
Sub 装箱单()
Application.ScreenUpdating = False
Application.EnableEvents = False
Application.Interactive = False
Dim lastrow As Long, finalrow As Long, nextcol As Long
Dim irange As Range, crange As Range, orange As Range
Dim sh1 As Worksheet, sh2 As Worksheet
Dim wbk As Workbook
Dim arr, str As String
On Error GoTo veryend
Set sh1 = ThisWorkbook.Sheets("FANOUT台账")
sh1.Activate
With sh1
finalrow = .Cells(.Rows.Count, 1).End(xlUp).Row
nextcol = .Cells(2, Columns.Count).End(xlToLeft).Column + 2
.Cells(2, "k").Copy .Cells(1, nextcol)
str = InputBox("请输入日期", "生成装箱单")
If str = "" Then
.Cells(1, nextcol).Clear
Exit Sub
Else
.Cells(2, nextcol) = str
End If
Set crange = .Cells(1, nextcol).Resize(2, 1)
.Cells(1, nextcol + 2).Resize(1, 19).Value = _
Array(.Cells(2, "q"), .Cells(2, "l"), .Cells(2, "n"), .Cells(2, "u"), .Cells(2, "y"), .Cells(2, "b"), .Cells(2, "c"), _
.Cells(2, "d"), .Cells(2, "e"), .Cells(2, "f"), .Cells(2, "g"), .Cells(2, "a"), .Cells(2, "a"), .Cells(2, "a"), _
.Cells(2, "a"), .Cells(2, "a"), .Cells(2, "a"), .Cells(2, "x"), .Cells(2, "aa"))
Set orange = .Cells(1, nextcol + 2).Resize(1, 19)
Set irange = .Cells(2, 1).Resize(finalrow - 1, nextcol - 2)
irange.AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=crange, CopyToRange:=orange
lastrow = .Cells(Rows.Count, nextcol + 2).End(xlUp).Row
.Cells(2, "aw").Resize(lastrow - 1, 6).ClearContents
End With
Workbooks.Open "Z:\生产台帐\装箱单相关文件\PACKING LIST模板.xls"
Set wbk = ActiveWorkbook
wbk.Sheets("FANOUT").Activate
With wbk.Sheets("FANOUT")
arr = .Cells(16, "o").Resize(lastrow - 1, 3)
.Cells(16, 1).Resize(.Cells(Rows.Count, 1).End(xlUp).Row, 19).Clear
sh1.Cells(2, nextcol + 2).Resize(lastrow - 1, 19).Copy .Cells(16, 1)
.Cells(16, 1).Resize(lastrow - 1, 19).Sort key1:=Range("a1")
.Cells(16, 1).Resize(lastrow - 1, 19).Font.Size = 18
.Rows("16:80").RowHeight = 40
.Cells(16, "o").Resize(lastrow - 1, 3) = arr
.Cells(10, 13) = sh1.Cells(2, nextcol)
End With
sh1.Columns("AJ:BQ").Delete shift:=xlToLeft
Application.ScreenUpdating = True
Application.EnableEvents = True
Application.Interactive = True
veryend:
End Sub |
|