Test for text instead of Date in UDF

Dave Patton

Well-known Member
Joined
Feb 15, 2002
Messages
6,345
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
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
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">
image001.gif
</MARQUEE>
This message was edited by s-o-s on 2002-09-15 14:30
 
Upvote 0

Forum statistics

Threads
1,215,049
Messages
6,122,864
Members
449,097
Latest member
dbomb1414

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top