View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Syed Zeeshan Haider[_4_] Syed Zeeshan Haider[_4_] is offline
external usenet poster
 
Posts: 8
Default Returning by Function

"Bill Manville" wrote in message ...
Syed Zeeshan Haider wrote:
Can a function return two different data types
for two different conditions?


Yes.
Declare it As Variant

Function GiveMeA(What As String) As Variant
Select Case What
Case "Date": GiveMeA = Date()
Case "String": GiveMeA = "Hello"
End Select
End Function

=GIVEMEA("Date") ' with cell formatted as date
=GIVEMEA("String") ' cell format can still be date.


Thank you! It works perfectly.

Due to some unknown (in fact, unremembered) reasons my tests gave me
negative results bundled with some quite annoying error messages.

New tests have proved it to be working perfectly.

Thanks again,
--
Syed Zeeshan Haider.
http://szh.20m.com/


-----------------------------------
Allah says to Mankind:
"Then which of the favours of your Lord will ye deny?"