Radial Button to load Macro when selected

johnpants

New Member
Joined
Oct 31, 2005
Messages
44
Hi, I have a Userform with 5 radial buttons on. When I select the top one and click the commandbutton I would like it to run Macro1 for example, then when radial button 2 is selected I would like it to run marco2 etc.

I am guessing this is pretty simple, am I correct?

Thanks.
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Use the Click Event for that control. You just list the name of the macro you want to run in the Event Or add the code portion of the macro to the event.
 
Upvote 0
Ok, I see what you mean, below are the details:

\code
Sub Rep1()
Range("A3").Select
ActiveSheet.PivotTables("PivotTable1").PivotCache.Refresh
End Sub
\endcode

that is the Macro that I would like to run, I have placed it into module3.

What I am having the problem with is what event control do I put into:

'OptionButton1_click'

and what into

'CommandButton1_Click'

so that it only runs the macro for the selected optionbutton...

Apologies if that makes no sense.. :)
 
Upvote 0
Thanks, that works perfect, it runs and completes, one minor adjustment I would like if it isn't too complex though.

At the minute the macro runs as soon as I click the radial button, what would I need to ammend if I wanted it to only run once it is selected, and the user clicks the CommandButton1 at the bottom of the form?

Thanks for your time Joe, much appreciated.
 
Upvote 0
Private Sub CommandButton1_Click()

If UserForm1.OptionButton1=True Then Rep1
If UserForm1.OptionButton2=True Then Rep2
If UserForm1.OptionButton3=True Then Rep3
If UserForm1.OptionButton4=True Then Rep4
End Sub
 
Upvote 0
Hi, guys,
as an alternative, easy to edit when buttons are added or deleted, you can use this
Code:
Private Sub CommandButton1_Click()
Dim i As Integer
For i = 1 To 4
If Me.Controls("optionbutton" & i) Then Run ("Rep" & i)
Next i
End Sub
kind regardfs,
Erik
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,717
Members
448,985
Latest member
chocbudda

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top