View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
scott scott is offline
external usenet poster
 
Posts: 577
Default global variable not seen

I have a simple workbook with 1 sheet and a command button to run some code.
Under "Microsoft Excel Objects", Sheet1 I have this code:

Public Y As String
Public Sub CommandButton1_Click()
X = "passed parameter"
Y = "global variable"
testmodule (X)
End Sub

Under "Modules", Module1 I have this code:

Public Sub testmodule(X As String)
MsgBox ("X is " + X)
MsgBox ("Y is " + Y)
End Sub

When I press the command button I see two message boxes. The first says :

"X is passed parameter"

and the second says

"Y is "

Question is how can I get the Y variable seen in Module1 without passing it
as a parameter? In other words have the message box say "Y is global
variable".