Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Returning by Function
Hello Experts,
I have Excel 97 Pro on Win98SE. For a certain complex calculation, I have written a specific function in VBA. This function returns a date. For a certain situation, I want this function to return a string. Can a function return two different data types for two different conditions? Thank you, -- Syed Zeeshan Haider. http://szh.20m.com/ ----------------------------------- Allah says to Mankind: "Then which of the favours of your Lord will ye deny?" |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
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?" |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
If Function returning 0 instead of cell value | Excel Worksheet Functions | |||
GETPIVOTDATA function returning 0 not #REF | Excel Worksheet Functions | |||
MOD function not returning exact zero | Excel Worksheet Functions | |||
Calling a function and then returning | Excel Discussion (Misc queries) | |||
Returning value from function | Excel Programming |