Calling a procedure with a Userform
I hope I explain this well.
I have 2 workbooks. One is a compilation ofdata from 4 different worksites. The other holds the monthly totals from the first book on a sheet that shows Jan thru Dec in each year, with the last several years for comparison.
2000 2001 2002 2003 2004
Jan
Feb
March (just to give you an idea)
i have the macro worked out to open the second book, and copy/paste the info to the proper site, month year (a macro for each month). What I don't have is a way to Call the proper month. I created a user form with OptionButtons, one for each month. Now it was easy enough to plug in
OptionButton1_Click()
Sub
Call January
End Sub
But it executes immediately, as soon as I click the Month (optionButton). I wanted a way to protect myself from clicking too quickly and making a mistake, so I wanted to be able to click the month, and then press ENTER to execute the Call. This way I could look things over before I make a mistake.
Should I use check boxes instead? Any suggestions would be appreciated.
If I have been unclear, please let me know and I will try to clarify.
Thanks again for your help.
Don
Edit: I use Office XP 2002. Also, I tried declaring a variable (eg myMonth),
and then
Call myMonth
but it simply will not do it. ( i obviously could have written it wrong) I keep getting the error "Expexted Sub, Function, or procedure"
Thanks
Re: Calling a procedure with a Userform
You should use a checkbox to replace the option button and a command button
to execute after you are sure that it is the option you really want.
HTH
Re: Calling a procedure with a Userform
Thanks, RobDog;
If possible, could you give a short example of the code. I'm confused as to how to implement this. Thanks,
Don
Re: Calling a procedure with a Userform
Place the code in the option button in a command button. Then add a checkbox. When you click
the command button you check the value of the checkbox and act accordingly.
VB Code:
Private Sub CommandButton1_Click()
If CheckBox1.Value = True Then
'do code that was in your optionbutton
End If
End Sub
Re: Calling a procedure with a Userform(Resolved)
Thank you so much for your help. It may seem silly but I had such a hard time working that out.
Thanks again.
Don
Re: Calling a procedure with a Userform
Dont worry about it. We all have those kind of days ;)