Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
The following UDF works perfectly - except for the first line, i.e.
when CheckDate is a Sunday or Holiday. The result is #VALUE! but I want just a blank or empty cell. How can I suppress or fix this? Public Function RecissionDate(CheckDate, DaysAfter As Integer, Holidays As Range) As Date Dim BDADate As Date Dim i As Integer If isSunday(CheckDate) Or isHoliday(CheckDate, Holidays) Then BDADate = "" Else BDADate = CheckDate For i = 1 To DaysAfter BDADate = BDADate + 1 If isSunday(BDADate) Or isHoliday(BDADate, Holidays) Then BDADate = BDADate + 1 Else: BDADate = BDADate End If If isSunday(BDADate) Or isHoliday(BDADate, Holidays) Then BDADate = BDADate + 1 Else: BDADate = BDADate End If Next i End If SunTrustRecissionDate = BDADate End Function |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
On 27 Dec, 17:03, John Pierce wrote:
The following UDF works perfectly - except for the first line, i.e. when CheckDate is a Sunday or Holiday. The result is #VALUE! but I want just a blank or empty cell. How can I suppress or fix this? The problem is that you have defined the function to return a Date, and "" isn't a valid date. (The date datatype is a specialised numeric type) If you change the "...) As Date" to "...) As Variant" it should work. Also note that an "If" doesn't need an "Else", and your "Else"s seem to do nothing. |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
On Dec 27, 12:29*pm, atpgroups wrote:
On 27 Dec, 17:03, John Pierce wrote: The following UDF works perfectly - except for the first line, i.e. when CheckDate is a Sunday or Holiday. The result is #VALUE! but I want just a blank or empty cell. How can I suppress or fix this? The problem is that you have defined the function to return a Date, and "" isn't a valid date. (The date datatype is a specialised numeric type) If you change the "...) *As Date" to "...) As Variant" it should work. Also note that an "If" doesn't need an "Else", and your "Else"s seem to do nothing. Thanks, changing 'as Date' to 'as Variant' in both places fixed it. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Error when cell A1 is not active and xlInsideVertical border formatthrowing error 1004 | Excel Programming | |||
Error handling error # 1004 Run-time error | Excel Programming | |||
Error Handling - On Error GoTo doesn't trap error successfully | Excel Programming | |||
run-time error '1004': Application-defined or object-deifined error | Excel Programming | |||
Automation Error, Unknown Error. Error value - 440 | Excel Programming |