Sub 出库单()
Application.ScreenUpdating = False
With Sheets("出库单")
lx = Mid(.[i1], 2, Len(.[i1]) - 3)
mc = lx & "出库登记表"
With Sheets(mc)
r = .Cells(Rows.Count, 3).End(xlUp).Row
ar = .Range("a1:am" & r)
End With
rs = .Cells(Rows.Count, 1).End(xlUp).Row
If rs > 16 Then .Rows("17:" & rs).Delete
For j = 5 To 35
n = 0
ReDim br(1 To UBound(ar), 1 To 5)
If Trim(ar(2, j)) <> "" Then
For i = 8 To UBound(ar)
If Trim(ar(i, j)) <> "" Then
n = n + 1
br(n, 1) = Replace(ar(i, 3), "上月结余", "")
br(n, 2) = ar(i, 38)
br(n, 3) = ar(i, j)
br(n, 4) = ar(i, 39)
br(n, 5) = br(n, 3) * br(n, 4)
End If
Next i
If n > 0 Then
m = m + 1
If m = 1 Then
.[c2] = ar(2, j)
.[g2] = ar(6, j)
.[i2] = ar(5, j)
.[l2] = ar(4, j)
If n <= 10 Then
.[b4].Resize(n, 5) = br
Else
k = 3
For i = 1 To 10
k = k + 1
For jj = 1 To 5
.Cells(k, jj + 1) = br(i, jj)
Next jj
Next i
k = 3
For i = 11 To n
k = k + 1
For jj = 1 To 5
.Cells(k, jj + 7) = br(i, jj)
Next jj
Next i
End If
ElseIf m > 1 Then
ws = .Cells(Rows.Count, 1).End(xlUp).Row + 1
.Rows("1:16").Copy .Cells(ws, 1)
.Cells(ws + 1, 3) = ar(2, j)
.Cells(ws + 1, 7) = ar(6, j)
.Cells(ws + 1, 9) = ar(5, j)
.Cells(ws + 1, 12) = ar(4, j)
If n <= 10 Then
.Cells(ws + 3, 2).Resize(n, 5) = br
Else
k = ws + 2
For i = 1 To 10
k = k + 1
For jj = 1 To 5
.Cells(k, jj + 1) = br(i, jj)
Next jj
Next i
k = ws + 2
For i = 11 To n
k = k + 1
For jj = 1 To 5
.Cells(k, jj + 7) = br(i, jj)
Next jj
Next i
End If
End If
End If
End If
Next j
End With
Application.ScreenUpdating = True
MsgBox "ok!"
End Sub
|