JenniferMurphy
Well-known Member
- Joined
- Jul 23, 2011
- Messages
- 2,691
- Office Version
- 365
- Platform
- Windows
I am working on my first UserForm. It's for a sheet to keep track of wins and losses in a game. I have a Score button that brings up a form with Win, Lose, and Quit buttons. It's all working.
The Subs behind the Win and Lose buttons have quite a bit of code in common and they read the same data cells into variables. I hate to duplicate code. It's too easy to have them get out of sync. What's the best way to share this code?
One way I thought of is to put the common code in a separate subroutine (Setup) that each button sub can call. This would require that the variables assigned in Setup be available to the calling routines. Can I declare them as global variables outside all of the routines? If so, what's the correct way to do that?
Thanks
The Subs behind the Win and Lose buttons have quite a bit of code in common and they read the same data cells into variables. I hate to duplicate code. It's too easy to have them get out of sync. What's the best way to share this code?
One way I thought of is to put the common code in a separate subroutine (Setup) that each button sub can call. This would require that the variables assigned in Setup be available to the calling routines. Can I declare them as global variables outside all of the routines? If so, what's the correct way to do that?
Thanks