View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Rick Rothstein \(MVP - VB\)[_933_] Rick Rothstein \(MVP - VB\)[_933_] is offline
external usenet poster
 
Posts: 1
Default Custom functions

If you declare your variables in the (General)(Declarations) section of the
code module where your function are (that is, declare them outside of any
procedures), then they will be "global" to the code module and **any**
procedure within that code module will be able to read AND CHANGE them. That
"and change them" is very important, especially if you do not declare all
your variables since then you could accidentally use the same variable name
in an unrelated procedure, change the value there without realizing the
effect doing so will have elsewhere and thus screw up some other procedure
that is dependent on those variables. If you give your global variables some
distinctive feature (say, start each name with "global"), then the odds of
accidentally tripping over them is greatly reduced. Now, with all that said,
here is an example...

Dim A As Long
Dim B As Long

Function One(X, Y, Z)
A = X + Y
B = X + Z
One = A * B
End Function

Function Two()
Two = A / B
End Function

Rick


"Palpha32" wrote in message
...
One of my custom functions calculates certain values("a" and "b") and
then
calculates a result relying on "a" and "b". Am I able to use "a" and "b"
in
another function by getting their value from the first function?

function one(x,y,z)
a = x + y
b = x + z
c = a * b
end function

function two(x,y,z)
a = x + y
b = x + z
d = a / b
end function

Thanks
Peter