要报告工作天数的消息

时间:2015-03-19 03:29:37

标签: excel vba excel-vba

如果在工资单中注册的人员工作时间少于30天,我会使用下面的代码通知他们。它工作得很好但我遇到的问题是给出的消息包含员工的姓名,例如。 Nabil Amer worked H days

在这里,我希望消息定义天数而不是字母" H"

Private Sub Workbook_Open()
    On Error Resume Next
    Dim EmpName As String
    Dim RowNrNumeric As Long
    Dim RowNrString As String
    Dim CloumnEmpName As String
    Dim CloumnNameRemStatus As String
    Dim RemStatus As String
    Dim Daysworked As String

    Sheets("Master Payroll").Select
    CloumnEmpName = "C"
    CloumnNameRemStatus = "K"
    Daysworked = "H"
    RowNrNumeric = 2
    RowNrString = RowNrNumeric
    EmpName = Range(CloumnEmpName + RowNrString).Value
    DueDate = Range(CloumnNameDate + RowNrString).Value
    RemStatus = Range(CloumnNameRemStatus + RowNrString).Value

    Do While EmpName <> ""
        If Cells(RowNrNumeric, 8).Value < 30 _
        And Not IsEmpty(Cells(RowNrNumeric, 2)) Then
            MsgBox "WARNING: " + EmpName + " worked for " + Daysworked + " Days "
            Range(Daysworked + RowNrString).Interior.ColorIndex = 3
            Range(Daysworked + RowNrString).Select
        End If

        RowNrNumeric = RowNrNumeric + 1
        RowNrString = RowNrNumeric
        EmpName = Range(CloumnEmpName + RowNrString).Value
        RemStatus = Range(CloumnNameRemStatus + RowNrString).Value
    Loop
End Sub

截图:

Sample Worksheet

1 个答案:

答案 0 :(得分:0)

改变这个:

MsgBox "WARNING: " + EmpName + " worked for " + Daysworked + " Days "

对此:

MsgBox "WARNING: " + EmpName + " worked for " & Range(Daysworked & RowNrNumeric).Value & " Days "