Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default remembering the nth item in one sub routine in the next sub routin

I have a macro which has one sub routine running another sub routine, however
I want the n number I defined in the first sub routine to be rembered in the
next sub routine.

ie
Dim Asset(1 To 19) As String 'Camilla EDITED coding
Asset(1) = "Eurostoxx 50"
Asset(2) = "Nasdaq 100"

Dim n As Integer
For n = 1 To 19
Worksheets(Asset(n)).Activate
CloseDay MyDay, MyMonth, MyYear
Next n

then in the next sub routine I am trying to switch between workbooks and
worksheets
ie Workbooks("Trade Files").Worksheets(Asset(n)).Activate

but I need it to remember the the (Asset(n)) from the previous sub routine.

Can anyone help?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default remembering the nth item in one sub routine in the next sub routin

If you want a variable to be available (global) to several Subs, then declare
it above all the subs in the module.
--
Gary's Student


"Cammy" wrote:

I have a macro which has one sub routine running another sub routine, however
I want the n number I defined in the first sub routine to be rembered in the
next sub routine.

ie
Dim Asset(1 To 19) As String 'Camilla EDITED coding
Asset(1) = "Eurostoxx 50"
Asset(2) = "Nasdaq 100"

Dim n As Integer
For n = 1 To 19
Worksheets(Asset(n)).Activate
CloseDay MyDay, MyMonth, MyYear
Next n

then in the next sub routine I am trying to switch between workbooks and
worksheets
ie Workbooks("Trade Files").Worksheets(Asset(n)).Activate

but I need it to remember the the (Asset(n)) from the previous sub routine.

Can anyone help?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default remembering the nth item in one sub routine in the next sub ro

Even when I define

Dim n As Integer
Dim Asset(1 To 19) As String
Asset(1) = "Eurostoxx 50"
Asset(2) = "Nasdaq 100"

At the beginning of the sub routine, the macro still get stuck on the coding:


Workbooks("Trade Files").Worksheets(Asset(n)).Activate

do you know why?

"Gary''s Student" wrote:

If you want a variable to be available (global) to several Subs, then declare
it above all the subs in the module.
--
Gary's Student


"Cammy" wrote:

I have a macro which has one sub routine running another sub routine, however
I want the n number I defined in the first sub routine to be rembered in the
next sub routine.

ie
Dim Asset(1 To 19) As String 'Camilla EDITED coding
Asset(1) = "Eurostoxx 50"
Asset(2) = "Nasdaq 100"

Dim n As Integer
For n = 1 To 19
Worksheets(Asset(n)).Activate
CloseDay MyDay, MyMonth, MyYear
Next n

then in the next sub routine I am trying to switch between workbooks and
worksheets
ie Workbooks("Trade Files").Worksheets(Asset(n)).Activate

but I need it to remember the the (Asset(n)) from the previous sub routine.

Can anyone help?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default remembering the nth item in one sub routine in the next sub ro

sorry I forgot to say I don't want the variables defined for all sub routines
just the two that are relevant.

"Cammy" wrote:

Even when I define

Dim n As Integer
Dim Asset(1 To 19) As String
Asset(1) = "Eurostoxx 50"
Asset(2) = "Nasdaq 100"

At the beginning of the sub routine, the macro still get stuck on the coding:


Workbooks("Trade Files").Worksheets(Asset(n)).Activate

do you know why?

"Gary''s Student" wrote:

If you want a variable to be available (global) to several Subs, then declare
it above all the subs in the module.
--
Gary's Student


"Cammy" wrote:

I have a macro which has one sub routine running another sub routine, however
I want the n number I defined in the first sub routine to be rembered in the
next sub routine.

ie
Dim Asset(1 To 19) As String 'Camilla EDITED coding
Asset(1) = "Eurostoxx 50"
Asset(2) = "Nasdaq 100"

Dim n As Integer
For n = 1 To 19
Worksheets(Asset(n)).Activate
CloseDay MyDay, MyMonth, MyYear
Next n

then in the next sub routine I am trying to switch between workbooks and
worksheets
ie Workbooks("Trade Files").Worksheets(Asset(n)).Activate

but I need it to remember the the (Asset(n)) from the previous sub routine.

Can anyone help?

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default remembering the nth item in one sub routine in the next sub ro

Also if I do define Asset(1) , Asset(2) at the top of the all subs in the
procedure it says it is an invalid procedure.

"Cammy" wrote:

Even when I define

Dim n As Integer
Dim Asset(1 To 19) As String
Asset(1) = "Eurostoxx 50"
Asset(2) = "Nasdaq 100"

At the beginning of the sub routine, the macro still get stuck on the coding:


Workbooks("Trade Files").Worksheets(Asset(n)).Activate

do you know why?

"Gary''s Student" wrote:

If you want a variable to be available (global) to several Subs, then declare
it above all the subs in the module.
--
Gary's Student


"Cammy" wrote:

I have a macro which has one sub routine running another sub routine, however
I want the n number I defined in the first sub routine to be rembered in the
next sub routine.

ie
Dim Asset(1 To 19) As String 'Camilla EDITED coding
Asset(1) = "Eurostoxx 50"
Asset(2) = "Nasdaq 100"

Dim n As Integer
For n = 1 To 19
Worksheets(Asset(n)).Activate
CloseDay MyDay, MyMonth, MyYear
Next n

then in the next sub routine I am trying to switch between workbooks and
worksheets
ie Workbooks("Trade Files").Worksheets(Asset(n)).Activate

but I need it to remember the the (Asset(n)) from the previous sub routine.

Can anyone help?



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default remembering the nth item in one sub routine in the next sub ro

I have decided that it is best to define it globally but I have defined it
using another letter k so that all other n's in other subroutines are not
affected.
Thanks gary!

"Cammy" wrote:

Also if I do define Asset(1) , Asset(2) at the top of the all subs in the
procedure it says it is an invalid procedure.

"Cammy" wrote:

Even when I define

Dim n As Integer
Dim Asset(1 To 19) As String
Asset(1) = "Eurostoxx 50"
Asset(2) = "Nasdaq 100"

At the beginning of the sub routine, the macro still get stuck on the coding:


Workbooks("Trade Files").Worksheets(Asset(n)).Activate

do you know why?

"Gary''s Student" wrote:

If you want a variable to be available (global) to several Subs, then declare
it above all the subs in the module.
--
Gary's Student


"Cammy" wrote:

I have a macro which has one sub routine running another sub routine, however
I want the n number I defined in the first sub routine to be rembered in the
next sub routine.

ie
Dim Asset(1 To 19) As String 'Camilla EDITED coding
Asset(1) = "Eurostoxx 50"
Asset(2) = "Nasdaq 100"

Dim n As Integer
For n = 1 To 19
Worksheets(Asset(n)).Activate
CloseDay MyDay, MyMonth, MyYear
Next n

then in the next sub routine I am trying to switch between workbooks and
worksheets
ie Workbooks("Trade Files").Worksheets(Asset(n)).Activate

but I need it to remember the the (Asset(n)) from the previous sub routine.

Can anyone help?

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 269
Default remembering the nth item in one sub routine in the next sub ro

Why not just pass the variables to the second routine?
Sub Macro1()
Dim n As Integer
Dim Asset(1 To 19) As String
Asset(1) = "Eurostoxx 50"
Asset(2) = "Nasdaq 100"
'other stuff here
Macro2 Asset(1), Asset(2), n
End Sub
Sub Macro2(myAsset1 as string, myAsset2 as string, myN as integer)
'your stuff
End Sub

James

Sub Macro1
Dim
Cammy wrote:
I have decided that it is best to define it globally but I have defined it
using another letter k so that all other n's in other subroutines are not
affected.
Thanks gary!

"Cammy" wrote:

Also if I do define Asset(1) , Asset(2) at the top of the all subs in the
procedure it says it is an invalid procedure.

"Cammy" wrote:

Even when I define

Dim n As Integer
Dim Asset(1 To 19) As String
Asset(1) = "Eurostoxx 50"
Asset(2) = "Nasdaq 100"

At the beginning of the sub routine, the macro still get stuck on the coding:


Workbooks("Trade Files").Worksheets(Asset(n)).Activate

do you know why?

"Gary''s Student" wrote:

If you want a variable to be available (global) to several Subs, then declare
it above all the subs in the module.
--
Gary's Student


"Cammy" wrote:

I have a macro which has one sub routine running another sub routine, however
I want the n number I defined in the first sub routine to be rembered in the
next sub routine.

ie
Dim Asset(1 To 19) As String 'Camilla EDITED coding
Asset(1) = "Eurostoxx 50"
Asset(2) = "Nasdaq 100"

Dim n As Integer
For n = 1 To 19
Worksheets(Asset(n)).Activate
CloseDay MyDay, MyMonth, MyYear
Next n

then in the next sub routine I am trying to switch between workbooks and
worksheets
ie Workbooks("Trade Files").Worksheets(Asset(n)).Activate

but I need it to remember the the (Asset(n)) from the previous sub routine.

Can anyone help?


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
Remembering lookups Aitchy Excel Worksheet Functions 2 June 13th 08 09:53 AM
Remembering a value moving from one sheet to another Hitesh_sethi Excel Discussion (Misc queries) 3 April 27th 06 01:26 AM
Remembering Data Values. Workle New Users to Excel 1 February 10th 05 06:58 AM
For and If Then loops, and remembering a value Art Excel Programming 3 May 5th 04 03:56 AM
UserForm remembering Settings jason Excel Programming 6 October 30th 03 01:51 AM


All times are GMT +1. The time now is 05:57 PM.

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

About Us

"It's about Microsoft Excel"