|
Private Sub 新建订单_Click()
With ActiveSheet
If Application.CountBlank(.Range("F2:f3")) > 0 Then MsgBox "请录入客户或产品名称": Exit Sub
If Application.CountBlank(.Range("h2:i3")) > 2 Then MsgBox "请录入合同编号或交货日期": Exit Sub
If Trim(.[k2]) = "" Then MsgBox "请录入合同日期": Exit Sub
r = .Cells(Rows.Count, 6).End(xlUp).Row
If r < 5 Then MsgBox "订单为空!": Exit Sub
Set Rng = Sheets("订单汇总表").Columns(3).Find(.[h2], , , 1)
If Not Rng Is Nothing Then MsgBox "已经保存过了!": Exit Sub
ar = .Range("e2:k" & r)
Dim br()
ReDim br(1 To UBound(ar), 1 To 13)
For i = 4 To UBound(ar)
If Trim(ar(i, 2)) <> "" Then
n = n + 1
br(n, 1) = n
br(n, 2) = Date
br(n, 3) = ar(1, 4)
br(n, 4) = ar(1, 7)
br(n, 5) = ar(2, 4)
br(n, 6) = ar(1, 2)
br(n, 7) = ar(2, 2)
br(n, 8) = ar(i, 2)
br(n, 9) = ar(i, 3)
br(n, 10) = ar(i, 5)
br(n, 11) = ar(i, 6)
br(1, 12) = .[h45]
br(n, 13) = ar(i, 7)
End If
Next i
If r - 4 >= 5 Then
h = r + 1
ElseIf r - 4 < 5 Then
h = 10
End If
.Rows(h & ":34").EntireRow.Hidden = True
.PrintOut
.Range("F2,H2:I2,K2,F3,H3:I3,K3,E5:K5,E6:K6").ClearContents
.Rows(h & ":34").EntireRow.Hidden = False
End With
With Sheets("订单汇总表")
rs = .Cells(Rows.Count, 1).End(xlUp).Row + 1
If rs = 4 Then
rs = 5
Else
rs = rs
End If
.Cells(rs, 1).Resize(n, UBound(br, 2)) = br
End With
MsgBox "ok"
End Sub
|
|