View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 6,953
Default Sub calling and passnig arguments

Sub sub1()
Dim y as double, myX as Double
y = 31
myX = Sub2(y)
msgbox y & " squared is " & myX
end sub

function Sub2(yy as double) as Double
xx = yy^2
Sub2 = xx
End Function

Look up Scope in VBA help.

--
Regards,
Tom Ogilvy

"Jacob" wrote:

I am trying to call a sub within another sub, i'll refer to the main
sub as sub1 and the sub within that as sub2. I want sub2 to perform a
calculation and find result X. How do I then use X in sub1? why is X
not available to sub1?

thanks,
Jacob