Archive of Mr Excel Message Board


Back to Excel VBA archive index
Back to archive home



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.


Check out our Excel VBA Resources

Re: Passing Parameters

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




This archive is from the original message board at www.MrExcel.com.
All contents © 1998-2004 MrExcel.com.
Visit our online store to buy searchable CD's with thousands of VBA and Excel answers.
Microsoft Excel is a registered trademark of the Microsoft Corporation.
MrExcel is a registered trademark of Tickling Keys, Inc.