I am almost there... I have created the UserForm with two option buttons for
the 2 macros. I seem to be missing the code which connects the selection of
the option button and running of either of the macros. At the moment the
UserForm comes up on screen, I select an option then the macro just stops.
Can you see what I am missing? Also, I'm not sure where I should put the
code. Do I have it within the UserForm as below, or should it be seperate?
Private Sub UserForm_Click()
UserForm1.Show
If OptionButton1.Value = True Then
Call Macro1
ElseIf OptionButton2.Value = True Then
Call Macro2
Else
Exit Sub
End If
End Sub
> In that case you should consider to build your own userform.
> (which sounds harder than it is.)
[quoted text clipped - 36 lines]
> >
> > - Show quoted text -
I don't recommend to put the code in Userform_Click,
it triggers also, if the user clicks somewhere else on
the form.
Make a Button, that's easier to understand. And put
the Code directly on the button.
To connect the two optionbuttons you have to put
them into a frame control. that way only one of the
optionbuttons can be true.
Your sub looks actually fine, so I don't know why
it doesn't work.
I changed minor details:
'-------------------------------------------------------------------------
Private Sub CommandButton1_Click()
If OptionButton1.Value = True Then
Call Macro1
Else
Call Macro2
End If
Unload Me
End Sub
'-------------------------------------------------------------------------
(you don't need the UserForm.show, because the
form is already visible)
Make the option1 default true, that way you prevent
the user from clicking the button without selecting
anything.
Give me some feedback if it works or not.
hth
Carlo
> I am almost there... I have created the UserForm with two option buttons for
> the 2 macros. I seem to be missing the code which connects the selection of
[quoted text clipped - 56 lines]
>
> - Show quoted text -
carlo - 28 Nov 2007 02:50 GMT
I forgot something:
'-------------------------------------------------------------------------
Private Sub CommandButton1_Click()
If Me.OptionButton1.Value = True Then
Call Macro1
Else
Call Macro2
End If
Unload Me
End Sub
'-------------------------------------------------------------------------
the Me is usually needed, to tell Excel where the Button is located
cheers Carlo
> I don't recommend to put the code in Userform_Click,
> it triggers also, if the user clicks somewhere else on
[quoted text clipped - 94 lines]
>
> - Show quoted text -
Ant - 28 Nov 2007 03:32 GMT
Hi Carlo. I have it working now (although it didn't like the Me bits for some
reason). I added a commandbutton called "GO" on the userform and once the
selection was made and the GO button pushed it ran the relative Macro. The
initial Macro button had the UserForm.Show. I tried removing this as you
mentioned but it seemed to require it. The call code sits under the
commandbutton and the main code in seperate modules.
One question though...How do you make the userform close once the Macro has
started?
Thanks for your help. Ant.
> I forgot something:
>
[quoted text clipped - 111 lines]
> >
> > - Show quoted text -
Ant - 28 Nov 2007 03:40 GMT
I have answered my own question...
userform1.hide - of course!
> Hi Carlo. I have it working now (although it didn't like the Me bits for some
> reason). I added a commandbutton called "GO" on the userform and once the
[quoted text clipped - 123 lines]
> > >
> > > - Show quoted text -
carlo - 28 Nov 2007 04:08 GMT
you can do
userform1.hide
unload userform1
or if you are on the form
me.hide
unload me
the difference between unload and hide:
unload takes the form out of the memory,
so it will be initialised again when you open
it the next time. hide just makes it invisble,
all selection and entries will be stored.
hth
Carlo
> I have answered my own question...
>
[quoted text clipped - 129 lines]
>
> - Show quoted text -