M
moon
Below function can return non-holiday date, I want to return how many
holiday found.
Variable HolidayResult to be update as long integer. But , I try can not
able to return the non-holiday by coding HolidayResult.Address.Value =
cntHoliday
HolidayResult. Address is "$F$4' in my test case.
Holiday Sheet format
Column A - Date value
Column B - Yes = Holiday, No = Non-Holiday
Function xHoliday(HolidayResult As Range, loDate As Date, ByVal loOffset As
Long) As Date
'~~ if input value no changed, this function will not call.
Dim HolidaySheet As Variant
Dim i As Long
Dim found As Boolean
Dim cntHoliday As Long
cntHoliday = 0
found = False
xHoliday = loDate - loOffset
Set HolidaySheet = Sheets("Holiday")
i = 1001
Do
If HolidaySheet.Range("A" & i) = xHoliday Then
found = True
Else
i = i - 1
End If
Loop Until found = True
'~~ When return date still holiday, skip it , until Holiday = "no"
found = False
Do
If Trim(UCase(HolidaySheet.Range("B" & i))) = "NO" Then
found = True
Else
xHoliday = xHoliday - 1
cntHoliday = cntHoliday + 1
i = i - 1
End If
Loop Until found = True
' MsgBox HolidayResult.Address
HolidayResult.Address.Value = cntHoliday
End Function
holiday found.
Variable HolidayResult to be update as long integer. But , I try can not
able to return the non-holiday by coding HolidayResult.Address.Value =
cntHoliday
HolidayResult. Address is "$F$4' in my test case.
Holiday Sheet format
Column A - Date value
Column B - Yes = Holiday, No = Non-Holiday
Function xHoliday(HolidayResult As Range, loDate As Date, ByVal loOffset As
Long) As Date
'~~ if input value no changed, this function will not call.
Dim HolidaySheet As Variant
Dim i As Long
Dim found As Boolean
Dim cntHoliday As Long
cntHoliday = 0
found = False
xHoliday = loDate - loOffset
Set HolidaySheet = Sheets("Holiday")
i = 1001
Do
If HolidaySheet.Range("A" & i) = xHoliday Then
found = True
Else
i = i - 1
End If
Loop Until found = True
'~~ When return date still holiday, skip it , until Holiday = "no"
found = False
Do
If Trim(UCase(HolidaySheet.Range("B" & i))) = "NO" Then
found = True
Else
xHoliday = xHoliday - 1
cntHoliday = cntHoliday + 1
i = i - 1
End If
Loop Until found = True
' MsgBox HolidayResult.Address
HolidayResult.Address.Value = cntHoliday
End Function