我有一个问题我想解决,但我需要帮助。我有一个excel,其中有很多信息:date, activity, people, hours
。每个人都写他的工作,所以表格就像这样
20/06/2013 football me 8.00
21/06/2013 football me 8.00
22/06/2013 basket me 8.00
21/06/2013 football me 8.00
22/06/2013 basket me 8.00
从星期一到星期五。总小时数必须为40,所有字段必须完成,且不能为空!我需要一个自动启动的宏,例如在12.00,并检查它是否对于工作表内的每个人都是正确的。我该怎么做?有人可以帮帮我吗?
答案 0 :(得分:0)
假设在每个工作表中,第1行有一个行标题,A2:D6中有数据。以下代码应相应地以msgbox
的形式返回错误。
Sub test()
Dim i As Integer
Dim j As Integer
Dim emp As Boolean
Dim sum As Integer
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
emp = False
For i = 2 To 6
For j = 1 To 4
If IsEmpty(ws.Cells(i, j)) Then
emp = True
'Skip the rest of cells
GoTo fHandler
End If
Next j
Next i
fHandler:
If emp Then
MsgBox "Some entries are empty in " & ws.Name
End If
sum = WorksheetFunction.sum(ws.Range("D2:D6"))
If sum <> 40 Then
MsgBox "Total hours not equal to 40 in " & ws.Name
End If
Next
End Sub