|
Private Sub CommandButton1_Click()
Dim s As Date
If ComboBox1.Text = "" Then MsgBox "姓名不能为空!": Exit Sub
If TextBox1.Text = "" Then MsgBox "开始日期不能为空!": Exit Sub
If TextBox2.Text = "" Then MsgBox "结束日期不能为空!": Exit Sub
If ComboBox2.Text = "" Or ComboBox4.Text = "" Then MsgBox "开始时间不能为空!": Exit Sub
If ComboBox3.Text = "" Or ComboBox5.Text = "" Then MsgBox "结束时间不能为空!": Exit Sub
With Sheets("请假")
ts = DateDiff("d", TextBox1.Text, TextBox2.Text)
If ts = 0 Then
r = .Cells(Rows.Count, 1).End(xlUp).Row + 1
.Cells(r, 1) = ComboBox1.Text
.Cells(r, 2) = TextBox1.Text
.Cells(r, 3) = CDate(ComboBox2.Text & ":" & ComboBox4.Text)
.Cells(r, 4) = CDate(ComboBox3.Text & ":" & ComboBox5.Text)
.Cells(r, 5) = DateDiff("h", .Cells(r, 3), .Cells(r, 4))
ElseIf ts > 0 Then
ks = TextBox1.Text
js = TextBox2.Text
For s = ks To js
r = .Cells(Rows.Count, 1).End(xlUp).Row + 1
.Cells(r, 1) = ComboBox1.Text
.Cells(r, 2) = s
m = m + 1
If m = 1 Then
.Cells(r, 3) = CDate(ComboBox2.Text & ":" & ComboBox4.Text)
.Cells(r, 4) = CDate("16:30")
.Cells(r, 5) = DateDiff("h", .Cells(r, 3), .Cells(r, 4))
ElseIf m > 1 And m <= ts Then
.Cells(r, 3) = CDate("08:00")
.Cells(r, 4) = CDate("16:30")
.Cells(r, 5) = 8
ElseIf m = ts + 1 Then
.Cells(r, 3) = CDate(ComboBox3.Text & ":" & ComboBox5.Text)
.Cells(r, 4) = CDate("16:30")
.Cells(r, 5) = 8 - DateDiff("h", .Cells(r, 3), .Cells(r, 4))
End If
Next s
End If
End With
MsgBox "ok!"
End Sub |
|