Sub 保存()
Dim rn As Range
Dim ar As Variant
With Sheets("销售结算单")
ar = .Range("c3:m16")
sl = Application.CountA(.Range("d6:d13"))
dh = .[l3]
End With
If sl = 0 Then MsgBox "销售结算单为空!": End
Dim br()
ReDim br(1 To UBound(ar), 1 To 15)
For i = 4 To 10
If ar(i, 8) <> "" Then
n = n + 1
br(n, 1) = ar(1, 10)
br(n, 2) = ar(2, 10)
br(n, 3) = ar(2, 3)
For j = 2 To UBound(ar, 2)
br(n, j + 2) = ar(i, j)
Next j
br(n, 14) = ar(14, 2)
br(n, 15) = ar(14, 11)
End If
Next i
With Sheets("基础数据")
r = .Cells(Rows.Count, 1).End(xlUp).Row
Set rn = .Range("a1:a" & r).Find(dh, , , , , , 1)
If Not rn Is Nothing Then MsgBox dh & "数据已经保存!": End
.Cells(r + 1, 1).Resize(n, UBound(br, 2)) = br
End With
MsgBox "数据保存成功!"
End Sub
|