how to call a sub that has arguments
The title line of the code:
Sub Worksheet_Change(ByVal Target As Range)
identifies it as worksheet event code. In this case, it is code that
executes when there is a change on the worksheet. Correctly written it
would be:
Private Sub Worksheet_Change(ByVal Target As Range).
That said, if you want the code to execute without making a change to the
worksheet, then the easy way is to change the title line to some other name
like:
Sub myChangedSub()
'Code here
End Sub
Then you can put it in the public code module and call it like:
Sub YearChange()
Call myChangedSub
End Sub
Or just run it instead of calling it. But you might have to change some of
the code to make it work in the public module for the specific sheet that
you want the data to apply to.
"Harold Good" wrote in message
...
Hi, I'm trying to call this procedure located in the MyCode module:
Sub Worksheet_Change(ByVal Target As Range)
code here
End Sub
(the above code works properly when it is in the Sheet1 (Budget) module)
From this procedure which is in the Sheet1 (Budget) module. How do I write
the code below? The best I can come up with is:
Sub YearChange()
Call MyCode.Worksheet_Change
End Sub
It does not work, I don't know how to handle the argument within the
parenthesis.
Also, I don't think I need to include the MyCode as part of the path, but
a similar Call procedure I've done without arguments only works if I
include this in the path. What might I have done wrong.
I would appreciate anyone's help with writing the bottom code correctly.
Gratefully,
Harold
|