Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 93
Default #VALUE! Error from UDF

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default #VALUE! Error from UDF

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 93
Default #VALUE! Error from UDF

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Error when cell A1 is not active and xlInsideVertical border formatthrowing error 1004 [email protected] Excel Programming 7 August 7th 08 08:43 PM
Error handling error # 1004 Run-time error [email protected] Excel Programming 3 May 20th 08 02:23 PM
Error Handling - On Error GoTo doesn't trap error successfully David Excel Programming 9 February 16th 06 05:59 PM
run-time error '1004': Application-defined or object-deifined error [email protected] Excel Programming 5 August 10th 05 09:39 PM
Automation Error, Unknown Error. Error value - 440 Neo[_2_] Excel Programming 0 May 29th 04 05:26 AM


All times are GMT +1. The time now is 08:32 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"