Событие изменения рабочего листа сверхурочных
Код
Модуль 1 (или любой другой, который вы используете)
Option Explicit
Sub GenehmigungMehrarbeit(Worksheet As Worksheet) ' Overtime
' List of Check Range Addresses
Const cRanges As String = "F14:F26,G14:G26,H14:H26,I14:I26,J14:J26"
' German List of Days
Const cDays As String = "Montag,Dienstag,Mittwoch,Donnerstag,Freitag"
' Message 1
Const strMsg1 = "Wurde der Mehraufwand der Arbeitszeit für den "
' Message 2
Const strMsg2 = " mit dem Teamlead abgesprochen?"
Const cHours As Long = 8 ' Hours
Dim vntR As Variant ' Check Range Array
Dim vntD As Variant ' Days Array
Dim i As Long ' Ranges/Days Array Elements Counter
' Split List of Range Addresses to Check Range Array
vntR = Split(cRanges, ",")
' Split German List of Days to Days Array
vntD = Split(cDays, ",")
' In This workbook's Worksheet
With ThisWorkbook.Worksheets(Worksheet.Name)
' Loop through elements of Check Range Array (Days Array).
For i = 0 To UBound(vntR)
' Check if sum of the current Check Range is greater than cHours.
If WorksheetFunction.Sum(.Range(Trim(vntR(i))).Value) _
> cHours Then
' Build the (daily) message.
MsgBox strMsg1 & Trim(vntD(i)) & strMsg2, vbInformation, vntD(i)
Exit For ' Stop checking.
' Note: The message box will pop up only for the first found
' range with the sum greater than Hours (cHours).
' If you want the messages to pop up for every range
' with the sum greater than Hours, you should out
' comment the previous line.
End If
Next
End With
End Sub
Лист1 (или любой другой, который вы используете)
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Application.Intersect(Target, Range("F14:J26")) Is Nothing Then _
GenehmigungMehrarbeit Me
End Sub