View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Bill Manville Bill Manville is offline
external usenet poster
 
Posts: 473
Default Returning by Function

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.


Bill Manville
MVP - Microsoft Excel, Oxford, England
No email replies please - reply in newsgroup