MrExcel Publishing
Your One Stop for Excel Tips & Solutions

Passing Parameters


Posted by Bob on August 28, 2001 2:07 PM

Anyone know if it is possible to pass a parameter to the code in
a sheet? In other words, If a click event happens, then Parameter
= True.

I tried:

Sub Review_Click()
MyParm = True
Call Worksheet_SelectionChange(MyParm)
End sub

Sub Worksheet_SelectionChange(ByVal Target As Excel.Range, ByVal MYPARM as Boolean)
If MyPARM = True then
Do some Code
Else
Don't do my Code
End If
End sub

But it didn't work.

Posted by Russell Hauf on August 28, 2001 3:02 PM

You can just use a global variable. Above your Worksheet_SelectionChange event, just declare MyParm:

Private MyParm as Boolean

Then in your click event, you can set it.

Sub Review_Click()
MyParm=True
End Sub

Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
If MyParm Then
' Do Something
Else
' Do something else
End If

MyParm=False
End Sub

Hope this helps,

Russell