Test for text instead of Date in UDF

Dave Patton

Well-known Member
Joined
Feb 15, 2002
Messages
4,469
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
I have a UDF "AGE" that requires a test to ensure dates are in the SS for d1 and d2.

If a person enters an invalid date such
as Feb 30, it shows as Text on the ss but function defaults to Dec 31 1899.

Probably solution could put text such as
"Input error, Invalid Date" instead of incorrect date for result.

I tried
if application.worksheetfunction.istext(d1)

But I did not get it to work




Function Age(d1 As Date, d2 As Date, Optional Output As Variant = "T")
.... ...
.... output

Select Case UCase(Output)
Case "D": Age = d
Case "H": Age = Array(Y, M, d)
Case "M": Age = M
Case "V": Age = Application.WorksheetFunction.Transpose(Array(Y, M, d))
Case "Y": Age = Y
Case Else: Age = Y & "y " & M & "m " & d & "d"
End Select

End Function

Thanks for your help
 

Some videos you may like

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.

s-o-s

Active Member
Joined
Apr 14, 2002
Messages
384
I hope I'm not teaching you to suck eggs, but have you considered doing another UDF that uses the ISDATE function to test for a date if it is true then the call is made to your Age function. If it returns false then a warning message appears.

ie
Function isd(celref)
isd = IsDate(celref)
End Function

you then put in your function as

=IF(ISD(celref),AGE(celref),"Please Enter A Valid Date in Cell "&CELL("address",celref))

Failing this have you thought of using the SS function =TYPE(celref) this returns the value 2 when celref contains text.


Hope this helps
Sean.

_________________<MARQUEE/><A HREF= "http://website.lineone.net/~s-o-s/Index.html">
</MARQUEE>
This message was edited by s-o-s on 2002-09-15 14:30
 

Watch MrExcel Video

Forum statistics

Threads
1,118,455
Messages
5,572,223
Members
412,448
Latest member
ManuW
Top