Gruppe
Ereignis
Bereich
Change
Thema
Prüfung, welche Fahrer in welcher Zeit frei sind
Problem
Wie kann ich durch einfache Eingabe eines Datums, einer Anfangsund Endzeit feststellen, welche Fahrer für diesen Zeitraum eine Tour übernehmen können und welche belegt sind?
Lösung
Geben Sie den Ereigniscode in das Klassenmodul des Arbeitsblattes ein.
ClassModule: Tabelle4
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim iWks As Integer, iRow As Integer
Dim iColA As Integer, iColB As Integer
Dim iTime As Integer
Dim Besetzt As Boolean
If Intersect(Target, Range("B1:B3")) Is Nothing Then Exit Sub
If IsEmpty(Range("B1")) Or IsEmpty(Range("B3")) Or _
IsEmpty(Range("B3")) Then Exit Sub
For iWks = 3 To Worksheets.Count
Besetzt = False
With Worksheets(iWks)
iRow = WorksheetFunction.Match( _
CDbl(Range("B1").Value), .Columns(1))
iColA = .Rows("1").Find(TimeValue(Range("B2").Text), _
LookIn:=xlFormulas, lookat:=xlWhole).Column
iColB = .Rows("1").Find(TimeValue(Range("B3").Text), _
LookIn:=xlFormulas, lookat:=xlWhole).Column
For iTime = iColA To iColB
If Not IsEmpty(.Cells(iRow, iTime)) Then
Cells(iWks - 2, 4) = "Besetzt"
Besetzt = True
Exit For
End If
Next iTime
If Besetzt = False Then Cells(iWks - 2, 4) = "Frei"
End With
Next iWks
End Sub