Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default can variables pass values

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.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default can variables pass values

A global variable is visible by all routines in a project - so it isn't
passed.

At the top of a general module, outside any procedure declare the variable
as

Public MyCell as Range

or whatever is appropriate for your variable

for your question, if a variable goes out of scope, it doesn't exist. If
you refer to it in a procedure where it is out of scope, you create a new
variable with the same name which will have a value of empty since it will
be an uninitialized variant. (unless you have option explicit at the top,
then it will raise an error).
--
Regards,
Tom Ogilvy

Don wrote in message
...
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.



  #3   Report Post  
Posted to microsoft.public.excel.programming
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.



  #4   Report Post  
Posted to microsoft.public.excel.programming
jaf jaf is offline
external usenet poster
 
Posts: 300
Default can variables pass values

Hi Don,
When it's out of scope it's gone.
Static works the same. If you exit and restart your VB app. aren't statics
reset?

A solution would be to find the cell each time.
Is the next cell down blank?

Sub Tester2()
Sheets("xlconstants").Range("d1").Activate 'start at the top of column d
Selection.End(xlDown).Select 'move to the last cell containing data
ActiveCell.Offset(1, 0).Activate 'move down one more
MsgBox ActiveCell.Row 'we are here
End Sub


--

John

johnf202 at hotmail dot com


"Don" wrote in message
...
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.



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
How to pass variables as arguments of a function Excel-craze Excel Worksheet Functions 1 August 12th 09 11:48 AM
VBA variables retaining their values GeorgeJ Excel Discussion (Misc queries) 2 August 17th 07 02:19 AM
how to look up values with two independent variables charlesfung Excel Worksheet Functions 4 June 17th 06 03:32 PM
How to pass values of a cell? Me Excel Discussion (Misc queries) 4 March 4th 05 05:35 PM
Pass Variables into Form's code Stuart[_5_] Excel Programming 3 August 23rd 03 04:55 AM


All times are GMT +1. The time now is 03:02 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"