|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub 排班表样式()
Dim d As Object
Dim arr()
Set d = CreateObject("scripting.dictionary")
T = Timer
With Sheets("全年排班")
ks = .[b1]
js = .[d1]
If ks = "" Then MsgBox "请先输入开始日期!": Exit Sub
If js = "" Then MsgBox "请先输入结束日期!": Exit Sub
If Not IsDate(ks) Then MsgBox "请先输入标准开始日期!": Exit Sub
If Not IsDate(js) Then MsgBox "请先输入标准结束日期!": Exit Sub
ts = DateDiff("d", ks, js)
ReDim arr(1 To ts + 1, 1 To 2)
r = Cells(Rows.Count, 1).End(xlUp).Row
.Range("a3:f" & r + 1).Borders.LineStyle = 0
.Range("a3:f" & r + 1).Interior.ColorIndex = 0
.Range("a3:f" & r + 1) = Empty
rr = Array(1, "一", 2, "二", 3, "三", 4, "四", 5, "五", 6, "六", 7, "日")
For i = 0 To UBound(rr) Step 2
d(rr(i)) = rr(i + 1)
Next i
For i = 0 To ts
n = n + 1
arr(n, 1) = ks + 1
xq = Weekday(ks + i, 2)
arr(n, 2) = "星期" & d(xq)
If xq = 6 Or xq = 7 Then Range("a" & n + 2 & ":f" & n + 2).Interior.ColorIndex = 50
Next i
.[a3].Resize(n, 2) = arr
.Range("a3:f" & ts + 3).Borders.LineStyle = 1
End With
MsgBox "耗时:" & Format(Timer - T, "0.00") & "秒"
Set d = Nothing
End Sub
|
|