Sub 保存数据()
Dim ar As Variant
Dim arr()
Dim rng As Range
With Sheets("出库单")
ar = .Range("a1:m10")
dh = .[k3]
End With
ReDim arr(1 To 5, 1 To 18)
For i = 6 To UBound(ar)
If Trim(ar(i, 1)) <> "" Then
n = n + 1
arr(n, 1) = n
arr(n, 2) = ar(4, 11)
arr(n, 3) = ar(3, 11)
arr(n, 4) = ar(3, 2)
arr(n, 5) = ar(4, 2)
For j = 1 To 13
arr(n, j + 5) = ar(i, j)
Next j
End If
Next i
If n = "" Then MsgBox "出库单为空,请先录入数据!": End
With Sheets("出库汇总")
rs = .Cells(Rows.Count, 1).End(xlUp).Row + 1
Set rng = .Range("c1:c" & rs).Find(dh, , , , , , 1)
If Not rng Is Nothing Then MsgBox dh & "数据已经录入,不能重复录入!": End
.Cells(rs, 1).Resize(n, UBound(arr, 2)) = arr
End With
MsgBox "保存完毕!"
End Sub
|