Private Sub CommandButton1_Click()
Dim i As Long, u As Long, p As Long
Dim j As Integer, t, q, LL As Integer
Dim bh As String
Dim JUDGE As String
Dim STP As Integer
'编号
If Range("m6") = "" Then
bh = Format(Now, "yyyymmdd") & "001"
Range("m6") = bh
End If
'编号
If Format(Now, "yyyymmdd") = Left(Cells(6, 12), 8) Then
bh = Format(Now, "yyyymmdd") & Right("000000" & CStr(CInt(Right(Cells(6, 12), 3)) + 1), 3)
Range("m6") = bh
Else
bh = Format(Now, "yyyymmdd") & "001"
Cells(6, 12) = bh
End If
If Range("S3").Value = 2 Then
If Cells(7, 5).Value = "" Then
MsgBox "领用单位不能为空。", vbOKOnly, "友情提示!!!"
Cells(7, 5).Select
Exit Sub
End If
End If
i = 9
Do Until Len(Range("F" & i).Text) = 0
If Cells(i, 4).Value = "" Then
MsgBox "日期不能为空。", vbOKOnly, "友情提示!!!"
Cells(i, 4).Select
Exit Sub
End If
If Cells(i, 9).Value = "" Then
MsgBox "数量不能为空。", vbOKOnly, "友情提示!!!"
Cells(i, 9).Select
Exit Sub
End If
i = i + 1
Loop
If Cells(9, 4).Value <> "" Then
If Range("s3") = 1 Then
JUDGE = "入库清单"
STP = 16
Else
JUDGE = "出库清单"
STP = 31
End If
Sheets(JUDGE).Select
ActiveSheet.Unprotect
i = Val(Sheets(JUDGE).Range("b65536").End(xlUp).Row)
u = Val(Sheets("单据录入").Range("T3").Value)
p = Val(Sheets("单据录入").Range("U3").Value)
For t = 1 To p
For j = 1 To u + 1
Sheets(JUDGE).Cells(i + t, j).Value = Sheets("单据录入").Cells(8 + t, j + STP - 1).Value
Next j
Next t
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
Sheets("单据录入").Select
'ActiveWorkbook.Save '保存
MsgBox "保存成功", vbOKOnly
ActiveSheet.Unprotect
Range("E7,H7,K7,M6,D9:E15,E15,i9:i15,l9:l15,N9:N15").Select
Selection.ClearContents
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
End If
Range("E7").Select
End Sub
参考资料:百度一下