View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Harald Staff Harald Staff is offline
external usenet poster
 
Posts: 1,327
Default can variables pass values

Hi

See if this is of help:

Sub test()
Call Macro1(1)
End Sub

Sub Macro1(ByVal X As Long)
MsgBox "Macro1 says " & X
X = X + 1
Call Macro2(X)
End Sub

Sub Macro2(ByVal X As Long)
MsgBox "Macro2 says " & X
X = X + 1
If X < 10 Then
Call Macro1(X)
Else
Call Macro3(X)
End If
End Sub

Sub Macro3(ByVal X As Long)
MsgBox "Final result " & X, , "Macro 3 finishes up"
End Sub

--
HTH. Best wishes Harald
Followup to newsgroup only please

"Don" skrev i melding
...
I've written a program that starts a sub procedure each
minute (which is started with the application.ontime
event) that takes a value from a cell and puts it into
the next cell down a column. The problem is that it works
well as long as I use active cells, which I can't use.

THE QUESTION IS: can I pass the value of a global
variable from one procedure to the next or does the
variable return to zero or garbage when it goes out of
scope from one procedure to another? I really need to
pass an index value from one procedure to the next.
Any ideas at all? Declaring static seems to not work as
in VB.