|
Sub 出库单()
Application.ScreenUpdating = False
Dim ar As Variant, cr As Variant
Dim i As Long, r As Long, rs As Long
Dim br(), brr()
Dim d As Object
Set d = CreateObject("scripting.dictionary")
Set dc = CreateObject("scripting.dictionary")
With Sheets("签字")
rs = .Cells(Rows.Count, 1).End(xlUp).Row
If rs < 2 Then MsgBox "签字工作表为空!": End
cr = .Range(.Cells(1, 1), .Cells(rs, 2))
End With
For i = 2 To UBound(cr)
If cr(i, 1) <> "" Then
dc(cr(i, 1)) = i
End If
Next i
With Sheets("明细")
r = .Cells(Rows.Count, 1).End(xlUp).Row
If r < 2 Then MsgBox "明细工作表为空!": End
ar = .Range(.Cells(1, 1), .Cells(r, 9))
End With
For i = 2 To UBound(ar)
If ar(i, 1) <> "" And ar(i, 3) <> "" Then
zd = Format(ar(i, 1), "yyyymmdd") & "|" & ar(i, 3)
If d(zd) = "" Then
d(zd) = i
Else
d(zd) = d(zd) & "|" & i
End If
End If
Next i
Application.DisplayAlerts = False
For Each sh In Sheets
If sh.Index > 3 Then
sh.Delete
End If
Next sh
Application.DisplayAlerts = True
For Each k In d.keys
n = 0
ReDim br(1 To UBound(ar), 1 To 7)
rr = Split(d(k), "|")
For i = 0 To UBound(rr)
xh = rr(i)
n = n + 1
For j = 4 To UBound(ar, 2)
br(n, j - 3) = ar(xh, j)
Next j
Next i
Sheets("出库单").Copy after:=Sheets(Sheets.Count)
Set sht = ActiveSheet
With sht
.Name = k
.[a6].Resize(n, UBound(br, 2)) = br
.Rows(n + 7 & ":78").Delete
gys = Split(k, "|")(1)
hh = dc(gys)
Sheets("签字").Select
For Each shp In Sheets("签字").Shapes
If shp.Type = 13 Then
w = shp.TopLeftCell.Row
If w = hh Then
shp.Copy
.Select
.Cells(n + 7, 2).Select
ActiveSheet.Paste
Exit For
End If
End If
Next shp
End With
Next k
Application.ScreenUpdating = True
MsgBox "ok!"
End Sub
|
|