Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default 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   Report Post  
Posted to microsoft.public.excel.programming
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

  #3   Report Post  
Posted to microsoft.public.excel.programming
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?"




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
If Function returning 0 instead of cell value torana_girl77 Excel Worksheet Functions 4 May 6th 09 05:03 AM
GETPIVOTDATA function returning 0 not #REF Steven Cheng Excel Worksheet Functions 0 October 3rd 08 01:02 AM
MOD function not returning exact zero SB Excel Worksheet Functions 2 October 4th 07 03:29 PM
Calling a function and then returning CLamar Excel Discussion (Misc queries) 4 June 19th 06 06:47 PM
Returning value from function Sally[_3_] Excel Programming 3 September 25th 03 08:20 PM


All times are GMT +1. The time now is 08:55 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"