Function
Urlaub(urlaubsRange
As
Range,
ByRef
vergleichsDatumRange
As
Range)
As
String
Dim
urlaubsName
As
String
Dim
startDatum
As
Date
Dim
endDatum
As
Date
For
i = 1
To
urlaubsRange.Rows.Count
If
Not
IsEmpty(urlaubsRange.Cells(i, 2).Value)
Then
urlaubsName = urlaubsRange.Cells(i, 1).Value
startDatum =
CDate
(urlaubsRange.Cells(i, 2).Value)
endDatum =
CDate
(urlaubsRange.Cells(i, 3).Value)
vergleichsDatum =
CDate
(vergleichsDatumRange.Cells(1, 1).Value)
Debug.Print startDatum &
", "
& vergleichsDatum &
", "
& endDatum
isUrlaub = startDatum <= vergleichsDatum
And
vergleichsDatum <= endDatum
If
isUrlaub
Then
vergleichsDatumRange.Cells(1, 1).Value = urlaubsName
Exit
For
End
If
End
If
Next
Urlaub = isUrlaub
End
Function
Private
Sub
test()
Dim
cellRange
As
Range
Set
cellRange = Range(
"A1:C3"
)
Range(cellRange.Cells(1, 1), cellRange.Cells(1, 3)).MergeCells =
True
cellRange.Cells(1, 1).Value =
"Urlaub"
cellRange.Cells(2, 1).Value =
"Urlaub 1"
cellRange.Cells(2, 2).NumberFormat =
"dd.mm.yyyy"
cellRange.Cells(2, 2).Value = Format(
"01.08.2020"
,
"dd.mm.yyyy"
)
cellRange.Cells(2, 3).NumberFormat =
"dd.mm.yyyy"
cellRange.Cells(2, 3).Value = Format(
"07.08.2020"
,
"dd.mm.yyyy"
)
cellRange.Cells(3, 1).Value =
"Urlaub 2"
cellRange.Cells(3, 2).NumberFormat =
"dd.mm.yyyy"
cellRange.Cells(3, 2).Value = Format(
"10.10.2020"
,
"dd.mm.yyyy"
)
cellRange.Cells(3, 3).NumberFormat =
"dd.mm.yyyy"
cellRange.Cells(3, 3).Value = Format(
"17.10.2020"
,
"dd.mm.yyyy"
)
Dim
vergleich
As
Range
Set
vergleich = Range(
"B5"
)
vergleich.Cells(1, 1).NumberFormat =
"dd.mm.yyyy"
vergleich.Cells(1, 1).Value = Format(
"06.08.2020"
,
"dd.mm.yyyy"
)
Debug.Print Urlaub(cellRange, vergleich) &
", "
& vergleich
End
Sub