標題:
100年值日表
[打印本頁]
作者:
h60327
時間:
2011-10-28 10:14
標題:
100年值日表
本帖最後由 h60327 於 2011-10-28 12:11 編輯
[attach]8360[/attach]這是100年的值日表,之前已煩請板大修正,但現在發現一個問題,本來值日表中平常日需扣除週休及例假日(M欄),但因有補上班問題(O欄),[例如:1/27放假而於2/4補上班],請問各位板大這要這要如何解決呢?謝謝大家了
作者:
Hsieh
時間:
2011-10-28 11:13
回復
1#
h60327
Private Sub CommandButton1_Click()
[A2:H65536].ClearContents
Dim ds As Object, ds1 As Object, Arr(1 To 65536, 0 To 4), Men, i#, test$, k%, temp$, s&
Men = Range([J2], [J65536].End(xlUp)).Value
Set ds = CreateObject("Scripting.Dictionary") '國定假日
Set ds1 = CreateObject("Scripting.Dictionary") '補上班
For i = 2 To [M65536].End(xlUp).Row '國定假日
temp = Month(Cells(i, 13)) & "," & Day(Cells(i, 13))
ds.Add temp, i
Next
For i = 2 To [O65536].End(xlUp).Row '補上班
temp = Month(Cells(i, 15)) & "," & Day(Cells(i, 15))
ds1.Add temp, i
Next
For i = [k1] To DateAdd("yyyy", 1, [k1]) - 1
test = Month(i) & "," & Day(i)
If (Weekday(i, vbMonday) < 6 And ds.Exists(test) = False) Or ds1.Exists(test) = True Then '週一至週五並扣除M欄國定假日加入補上班日
s = s + 1
Arr(s, 1) = i
Arr(s, 2) = Month(i)
Arr(s, 3) = Day(i)
Arr(s, 4) = Weekday(i, 2)
k = IIf(s Mod UBound(Men) = 0, UBound(Men), s Mod UBound(Men))
Arr(s, 0) = Men(k, 1)
End If
Next
[A2].Resize(s, 5) = Arr
Range([E2], [E65536].End(xlUp)).FormulaR1C1 = _
"=IF(WEEKDAY(RC[-3])=2,""一"",(IF(WEEKDAY(RC[-3])=3,""二"",(IF(WEEKDAY(RC[-3])=4,""三"",(IF(WEEKDAY(RC[-3])=5,""四"",(IF(WEEKDAY(RC[-3])=6,""五"",(IF(WEEKDAY(RC[-3])=7,""六"",(IF(WEEKDAY(RC[-3])=1,""日"","""")))))))))))))"
Range([E2], [E65536].End(xlUp)).Formula = Range([E2], [E65536].End(xlUp)).Value
End Sub
複製代碼
作者:
h60327
時間:
2011-10-28 12:10
標題:
RE: 100年值日表
原來自己的思路並沒有錯
但因未加上這一段 Set ds1 = CreateObject("Scripting.Dictionary")
造成無法執行
該學習的還是很多,真是感謝版主不吝指導
作者:
man65boy
時間:
2011-10-28 22:51
回復
2#
Hsieh
很不錯的值日表,請問超級板主、如果以相同格式,用隔週休排班,該如何更改!
謝謝!!!
作者:
Hsieh
時間:
2011-10-28 23:58
Private Sub CommandButton1_Click()
[A2:H65536].ClearContents
Dim ds As Object, ds1 As Object, d As Object, Arr(1 To 65536, 0 To 4), Men, i#, test$, k%, temp$, s&
Men = Range([J2], [J65536].End(xlUp)).Value
Set ds = CreateObject("Scripting.Dictionary") '國定假日
Set ds1 = CreateObject("Scripting.Dictionary") '補上班
Set d = CreateObject("Scripting.Dictionary") '補上班
r = [M65535].End(xlUp).Row
For i = 2 To r '國定假日
temp = Month(Cells(i, 13)) & "," & Day(Cells(i, 13))
ds.Add temp, i
Next
r = [O65536].End(xlUp).Row
For i = 2 To r '補上班
temp = Month(Cells(i, 15)) & "," & Day(Cells(i, 15))
ds1.Add temp, i
Next
r = DateAdd("yyyy", 1, Range("K1")) - 1
For i = Range("K1") To r
test = Month(i) & "," & Day(i)
If Weekday(i, vbMonday) = 6 Then d(Month(i)) = d(Month(i)) + 1
If (Weekday(i, vbMonday) <= 6 And ds.Exists(test) = False) Or ds1.Exists(test) = True Then '週一至週五並扣除M欄國定假日加入補上班日
If d(Month(i)) Mod 2 = 0 And Weekday(i, vbMonday) = 6 Then GoTo 10 '偶數週六跳過
s = s + 1
Arr(s, 1) = i
Arr(s, 2) = Month(i)
Arr(s, 3) = Day(i)
Arr(s, 4) = Weekday(i, 2)
k = IIf(s Mod UBound(Men) = 0, UBound(Men), s Mod UBound(Men))
Arr(s, 0) = Men(k, 1)
End If
10
Next
[A2].Resize(s, 5) = Arr
Range([E2], [E65536].End(xlUp)).FormulaR1C1 = _
"=IF(WEEKDAY(RC[-3])=2,""一"",(IF(WEEKDAY(RC[-3])=3,""二"",(IF(WEEKDAY(RC[-3])=4,""三"",(IF(WEEKDAY(RC[-3])=5,""四"",(IF(WEEKDAY(RC[-3])=6,""五"",(IF(WEEKDAY(RC[-3])=7,""六"",(IF(WEEKDAY(RC[-3])=1,""日"","""")))))))))))))"
Range([E2], [E65536].End(xlUp)).Formula = Range([E2], [E65536].End(xlUp)).Value
End Sub
複製代碼
回復
4#
man65boy
作者:
man65boy
時間:
2011-10-29 23:35
回復
5#
Hsieh
太強了,感謝超級版大,給於此題不一樣的條件更改參考,謝謝~~
歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)