leezac
asked on
Code for button cannot be used for other procedures
I have code attached to a button
Private Sub PerfCompare_Click()
I want to use the same code for another process. When I add PerfCompare to the other code - it says Sub or Function not defined.
I have copied the code into another Function but it is a duplicate of the code and it seems that it would be confusing to someone looking at the code unless they know what I have done.
Is there a way to use the PerfCompare_Click code for another procedure and if so how?
Thanks in advance.
Private Sub PerfCompare_Click()
I want to use the same code for another process. When I add PerfCompare to the other code - it says Sub or Function not defined.
I have copied the code into another Function but it is a duplicate of the code and it seems that it would be confusing to someone looking at the code unless they know what I have done.
Is there a way to use the PerfCompare_Click code for another procedure and if so how?
Thanks in advance.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Faustulus, you make a valid point. I rarely put any Public procedures inside my Sheet modules, mainly because it makes it harder to locate them when visually scanning around for them (like...where did I put that procedure again? Sheet1, Sheet2, Sheet3, thisWorkbook, oh yeah! Module1, where it should be!) In this case, it seemed like a simple solution to the problem. however, if there is more to it than that, it would be prudent to make a separate module and go forward from there.
ASKER
That helped a great deal. I was able to change.
Great!
Thank you.
Thank you.
For example, if the code for the button is in Sheet1 and you're trying to access it from Sheet2, making it public will allow Sheet2 to run that procedure.
Specifically, you should call the sub something like this:
Open in new window