variable in excel

A

anang

I have little problem with my macro. How to assign the value of the
variable to other macro which I call in main macro.

Sub Macro1()
sheet_name = "Measurement 1"
Call Looping
Call Positifing
End Sub

I have "sheet_name" variable inside the Looping and Positifing macros
..
 
J

JulieD

Hi

you need to declare the variable at the top of the module sheet
Dim sheet_name as String
if all of the code is in the same module sheet.

If it isn't you need to declare the variable as
Public sheet_name as String
at the top of a module sheet

Hope this helps
Cheers
JulieD
 
C

Colo[MVP Excel]

Hi,

Here is another way. You can pass the variable as an argument as follows.

Sub Macro1()
Dim sheet_name As String
sheet_name = "Measurement 1"
Call Looping(sheet_name)
Call Positifing(sheet_name)
End Sub

Sub Looping(ByVal Sh_Name)
MsgBox Sh_Name
End Sub

Sub Positifing(ByVal Sh_Name)
MsgBox Sh_Name
End Sub


Regards,
Colo
 
I

ijb

declare the variable public outside the main routine

Public sheet_name as String
Sub Macro1()
sheet_name = "Measurement 1"
Call Looping
Call Positifing
End Sub

--
If I've mis-understood the question please tell me.

HTH

ijb

Remove nospam from my e-mail address to talk direct

Not MCSD, MVP, TLA, P&P, PCMCIA, etc just trying to help
 
I

ijb

declare the variable public outside the main routine

Public sheet_name as String
Sub Macro1()
sheet_name = "Measurement 1"
Call Looping
Call Positifing
End Sub

--
If I've mis-understood the question please tell me.

HTH

ijb

Remove nospam from my e-mail address to talk direct

Not MCSD, MVP, TLA, P&P, PCMCIA, etc just trying to help
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top