- 帖子
- 5923
- 主題
- 13
- 精華
- 1
- 積分
- 5986
- 點名
- 0
- 作業系統
- win10
- 軟體版本
- Office 2010
- 閱讀權限
- 150
- 性別
- 男
- 來自
- 台灣基隆
- 註冊時間
- 2010-5-1
- 最後登錄
- 2022-1-23
        
|
19#
發表於 2013-11-19 19:45
| 只看該作者
回復 18# prince0413 - Const 早 = "10:00~18:00"
- Const 全日 = "10:30~18:30"
- Const 晚 = "11:00~19:00"
- Sub Ex()
- Dim Rng(1 To 2) As Range, i As Integer, 出勤 As String, M As Variant
- Sheets("假日出勤單").PageSetup.PrintArea = "A1:H13" '一頁就夠了
- Set Rng(1) = Sheets("假日出勤單").Range("J2") '設定姓名
- Do While Rng(1) <> "" '執行迴圈的條件:姓名<>""
- With Sheets("11月")
- Set Rng(2) = .Range("B:B").Find(Rng(1), LOOKAT:=xlWhole)
- M = Application.Match(Rng(1), Sheets("中英文姓名對照表").Range("A:A"), 0) 'Match : 工作表函數
- If IsError(M) Then MsgBox "中英文姓名對照表 中沒有 : " & Rng(1): Exit Sub
- If Not Rng(2) Is Nothing Then
- i = 3 '第3欄 :C
- Do While IsNumeric(.Cells(4, i)) '執行迴圈的條件:第4列是數字
- If .Cells(5, i) = "六" Or .Cells(5, i) = "日" Then
- 出勤 = "" '歸零
- If .Cells(Rng(2).Row, i) Like "*早*" Then
- 出勤 = 早
- ElseIf .Cells(Rng(2).Row, i) Like "*晚*" Then
- 出勤 = 晚
- ElseIf .Cells(Rng(2).Row, i) Like "*全日*" Then
- 出勤 = 全日
- End If
- If 出勤 <> "" Then
- Sheets("假日出勤單").Range("B3") = Sheets("中英文姓名對照表").Cells(M, "B") '姓名: 對照出在B欄的 M列
- Sheets("假日出勤單").Range("D3") = Rng(2).Offset(, -1) '社員編號
- Sheets("假日出勤單").Range("A5") = DateSerial(2013, 11, .Cells(4, i)) '日期
- Sheets("假日出勤單").Range("B5") = 出勤 '時間
- Sheets("假日出勤單").Range("D5") = IIf(.Cells(4, i) = "六", "(星期六)", "(星期日)") & "沙龍營業"
- Sheets("假日出勤單").PrintOut '印列出勤單
- End If
- End If
- i = i + 1
- Loop
- End If
- End With
- Set Rng(1) = Rng(1).Offset(1) '下一位姓名
- Loop
- End Sub
複製代碼 |
|