Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 85
Default call a procedure using current inputs

this is a very simple example of a much bigger pair of subs. i need to use
variables set in main sub w/in the called upon second sub. example:

Sub Macro1()
For i = 1 To 3
tabpick = "page " & i
Call macro2
Next i
End Sub

Sub macro2()
MsgBox "you are on " & tabpick
End Sub

it should result in a series of 3 msgbox's that say: 'you are on page 1',
'you are on page 2', 'you are on page 3'
is it possible for a called upon sub to remember the variable at hand
without re-establishing all my variables? these variables set in 1st sub
take up tons of code to calculate, so it is not feasible to re-calc every
time. also, the code in the 2nd and subsequent subs is quite involved. I
have thought about a function vs. sub, but the inputs are so many. any
other ideas? thanks, mike allen


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,327
Default call a procedure using current inputs

Hi Mike

Just pass whatever you need passed from one to another, like this:

Sub Test1()
Dim S As String
S = InputBox("Now what ?")
Call Test2(S, Now)
End Sub

Sub Test2(What As String, D As Date)
MsgBox "At " & D & " You said " & What & _
". Please wait for the police.", vbInformation
End Sub

HTH. Best wishes Harald

"mike allen" skrev i melding
...
this is a very simple example of a much bigger pair of subs. i need to

use
variables set in main sub w/in the called upon second sub. example:

Sub Macro1()
For i = 1 To 3
tabpick = "page " & i
Call macro2
Next i
End Sub

Sub macro2()
MsgBox "you are on " & tabpick
End Sub

it should result in a series of 3 msgbox's that say: 'you are on page 1',
'you are on page 2', 'you are on page 3'
is it possible for a called upon sub to remember the variable at hand
without re-establishing all my variables? these variables set in 1st sub
take up tons of code to calculate, so it is not feasible to re-calc every
time. also, the code in the 2nd and subsequent subs is quite involved. I
have thought about a function vs. sub, but the inputs are so many. any
other ideas? thanks, mike allen




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 85
Default call a procedure using current inputs

i think i did figure a way to use functions as opposed to subs after all:
Sub Macro1()
For i = 1 To 3
tabpick = "page " & i
macro2(tabpick)
Next i
End Sub

function macro2()
MsgBox "you are on " & tabpick
End Sub

i would still like to be able to call other subs (that have way too many
inputs to create a function with) using current variables. thanks, mike
allen


"mike allen" wrote in message
...
this is a very simple example of a much bigger pair of subs. i need to

use
variables set in main sub w/in the called upon second sub. example:

Sub Macro1()
For i = 1 To 3
tabpick = "page " & i
Call macro2
Next i
End Sub

Sub macro2()
MsgBox "you are on " & tabpick
End Sub

it should result in a series of 3 msgbox's that say: 'you are on page 1',
'you are on page 2', 'you are on page 3'
is it possible for a called upon sub to remember the variable at hand
without re-establishing all my variables? these variables set in 1st sub
take up tons of code to calculate, so it is not feasible to re-calc every
time. also, the code in the 2nd and subsequent subs is quite involved. I
have thought about a function vs. sub, but the inputs are so many. any
other ideas? thanks, mike allen




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
call procedure problem stan Excel Discussion (Misc queries) 2 August 17th 09 06:11 PM
can I call a procedure using a variable Santiago Gomez Excel Programming 8 December 24th 03 09:08 PM
Selective call procedure jamesa Excel Programming 2 October 2nd 03 10:04 AM
call procedure bob Excel Programming 1 August 9th 03 12:40 AM
procedure won't call John Gittins Excel Programming 0 August 5th 03 08:17 PM


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