Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default How to return a value from a function?

Dear Excel Gurus,

In C, one can do the following;

int func()
{
....
if (x == true)
return y;
....
}

How can I do the same thing in Excel VBA? I wish to return a value and exit
without running the function to the end.

Thanks for your advice in advance.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default How to return a value from a function?

Function GetValue() as Long

Dim i as Long

For i = 1 to 10
If i = 5 Then
GetValue = i
Exit Function
End If
Next i

End Function


So, the answer is Exit Function.


RBS



"Sing" wrote in message
...
Dear Excel Gurus,

In C, one can do the following;

int func()
{
....
if (x == true)
return y;
....
}

How can I do the same thing in Excel VBA? I wish to return a value and
exit
without running the function to the end.

Thanks for your advice in advance.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 947
Default How to return a value from a function?

General ideas...

Function Func()
Dim x As Boolean
Dim y As Double

x = True
y = 3.14

If x Then
Func = y
Exit Function
End If

'Other stuff
Func = 1.23
End Function

--
HTH :)
Dana DeLouis
Windows XP & Excel 2007


"Sing" wrote in message
...
Dear Excel Gurus,

In C, one can do the following;

int func()
{
....
if (x == true)
return y;
....
}

How can I do the same thing in Excel VBA? I wish to return a value and
exit
without running the function to the end.

Thanks for your advice in advance.




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default How to return a value from a function?

Thank you for your replies. You have been most helpful!!

"Sing" wrote in message
...
Dear Excel Gurus,

In C, one can do the following;

int func()
{
....
if (x == true)
return y;
....
}

How can I do the same thing in Excel VBA? I wish to return a value and

exit
without running the function to the end.

Thanks for your advice in advance.




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
Return Function scott Excel Worksheet Functions 2 October 21st 08 10:26 PM
Return value for a function. Jeff Excel Discussion (Misc queries) 1 June 2nd 08 09:08 PM
Why does this function NOT return a value? Nooby Excel Discussion (Misc queries) 3 May 22nd 06 03:07 PM
Only do Sum function if not "0", IF"0" then return "0" Mike Punko Excel Worksheet Functions 1 June 1st 05 12:20 AM
Function to return value from each tab Steven Leuck Excel Worksheet Functions 1 March 3rd 05 04:11 AM


All times are GMT +1. The time now is 07:07 PM.

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"