|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Sub test()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
arr = Sheets(1).UsedRange
With Sheets(3)
For i = 2 To UBound(arr)
a = Split(arr(i, 4))
rq = Day(a(0))
If rq > rq1 Then rq1 = rq1 + 1
If rq1 > 16 Then
If C = 0 Then
r1 = n
n = 0
End If
C = 3
End If
If arr(i, 2) <> s Then
If s <> "" Then
r2 = IIf(r1 > n, r1, n)
.Cells(r, 1).Resize(r2 + 1, 9).Borders.LineStyle = xlContinuous
.Cells(r + r2 + 1, 1).Resize(12, 1) = Application.Transpose(Array("全月应出勤天数:天", "实际出勤天数:天", "正常月休天数:天", "休存假天数:天", "休年假天数:天", "事假天数:天", "病假天数:天", "夜班天数:个", "全月加班小时:小时", "剩余年假天数:天", "剩余存假:天", "确认无误后请签名:"))
End If
s = arr(i, 2)
C = 0
n = 0
r = .[A65536].End(3).Row + 4
.Cells(r, 1).Resize(1, 9) = [{"部门","姓名","考勤号码","日期","时间","备注","日期","时间","备注"}]
rq1 = 1
End If
For j = rq1 To rq
If j > 16 Then
If C = 0 Then
r1 = n
n = 0
End If
C = 3
End If
n = n + 1
.Cells(r + n, 1) = arr(i, 1)
.Cells(r + n, 2) = arr(i, 2)
.Cells(r + n, 3) = arr(i, 3)
.Cells(r + n, 4 + C) = DateValue(Format(a(0), "YYYY/M/") & j)
Next
.Cells(r + n, 5 + C) = a(1)
rq1 = rq
Next
r2 = IIf(r1 > n, r1, n)
.Cells(r, 1).Resize(r2 + 1, 9).Borders.LineStyle = xlContinuous
.Cells(r + r2 + 1, 1).Resize(12, 1) = Application.Transpose(Array("全月应出勤天数:天", "实际出勤天数:天", _
"正常月休天数:天", "休存假天数:天", "休年假天数:天", "事假天数:天", "病假天数:天", "夜班天数:个", _
"全月加班小时:小时", "剩余年假天数:天", "剩余存假:天", "确认无误后请签名:"))
For j = r2 + r + 1 To 4 Step -1
If .Cells(j, 4) <> "" And .Cells(j, 4) = .Cells(j - 1, 4) Then .Cells(j - 1, 4).Resize(2).Merge
If .Cells(j, 7) <> "" And .Cells(j, 7) = .Cells(j - 1, 7) Then .Cells(j - 1, 7).Resize(2).Merge
Next
End With
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub
这是“半百”帮我写的代码,能够完美的运行。有些地方我有些疑惑, If rq > rq1 Then rq1 = rq1 + 1 这行代码中rq在If语句之前已经赋值,rq1没有赋值,而是在后面的代码中才出现赋值。我不明白为什么 If rq > rq1 Then rq1 = rq1 + 1这句代码还能运行。后面的s,c也存在相同的疑惑
|
|