LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Function and Sub

How about just manipulating the values, er, variables passed to the subroutine:

Option Explicit
Sub testme01()
Dim myLong As Long
Dim myDbl As Double
myLong = 5
Call testme02(myLong, myDbl)
MsgBox myLong & "--" & myDbl
End Sub
Sub testme02(ByVal a As Long, ByRef b As Double)
b = a / 2
a = a + a
End Sub

Since a is passed by value, mylong won't change.

Since b is passed by reference, then any change made to b is a change to mydbl.








Jeff wrote:

Hi,

I guess your point is that the sub and function have the same computing
power. The limitations of a function, are that you cant manipulate cell
data. It is strange
that there is no way to return a value or multiple values in a sub procedure
though.

"Harald Staff" wrote:

A sub is a function that returns nothing (Void). Or a function is a sub with
a return value. No differences in power. Practical diffenrences in Excel is
that a Sub is in the macro-run menu and can be assigned to clickable
objects, whereas functions can be used as cell formulas.

When used from a cell, then the function is pretty crippled, it is limited
to what formulas can do; return a single value. Which I guess is the
limitation in mention. Call the function from a sub, like

Sub Test()
MsgBox MaxValue(2, 1)
End Sub

and it can do just anything; kill files, partition disks, email your inlaws,
....

HTH. Best wishes Harald


"Jeff" wrote in message
...
Hi,

I have a function that returns a value. I just set the value = to the
name
of the function. Is there a way to do this with a "Sub" procedure - I
mean
return a value without creating a global variable. I wanted to use a Sub
in
the future because you can do more manipulation.

Function MaxValue(a, b)

If a < b Then
MaxValue = b
Else
MaxValue = a
End If

End Function




--

Dave Peterson


 
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
copy of excel file not showing formulal/function in the function b oaallam Excel Discussion (Misc queries) 4 September 6th 07 01:20 PM
LINKEDRANGE function - a complement to the PULL function (for getting values from a closed workbook) [email protected] Excel Worksheet Functions 0 September 5th 06 03:44 PM
Offset function with nested match function not finding host ss. MKunert Excel Worksheet Functions 1 March 21st 06 10:46 PM
Emulate Index/Match combo function w/ VBA custom function Spencer Hutton Excel Worksheet Functions 2 May 2nd 05 05:26 PM
Nested IF Function, Date Comparing, and NetworkDays Function carl Excel Worksheet Functions 2 December 29th 04 09:57 PM


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

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

About Us

"It's about Microsoft Excel"