Option Button Macro

gerald24

Board Regular
Joined
Apr 28, 2017
Messages
95
Hi Guys,

Anyone who knows how option buttons work in excel macro?

So what I want to happen is I have two option buttons (for example, option A = with tax, option B = without Tax)
Then, I will hit a button (let's say a trigger button) to compute a certain amount that is affected whatever option I selected.

Thanks, Guys.
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
After you record/program your macros. Go into developer mode, right click on an option button. There, you can choose "Assign Macro" and choose the macro you want associated from the list.
 
Upvote 0
After you record/program your macros. Go into developer mode, right click on an option button. There, you can choose "Assign Macro" and choose the macro you want associated from the list.

Hi MrKowz,

what I would like to do is not the option buttons to trigger my macro, I want another macro button to do the job, the option buttons are much more like parameters.
 
Upvote 0
Normally you would not need two Option Buttons.

Create one Option Button. Named OptionButton1

Now if you want to tax the person click the option button if not then do not select the option button.

Put this script in a command button:

This is a example:

If you click the option button and then click the command button the word "Tax" will be put in Range("A1")

Put this script in the command button:

Code:
Private Sub CommandButton1_Click()
If OptionButton1.Value = True Then
Cells(1, 1).Value = "Tax"
OptionButton1.Value = False
End If
End Sub
 
Upvote 0
If you just insist on having two Option Buttons that fine. When user clicks on second Option Button the script will still run when you click Command button but no other action like adding tax will happen
 
Last edited:
Upvote 0
Normally you would not need two Option Buttons.

Create one Option Button. Named OptionButton1

Now if you want to tax the person click the option button if not then do not select the option button.

Put this script in a command button:

This is a example:

If you click the option button and then click the command button the word "Tax" will be put in Range("A1")

Put this script in the command button:

Code:
Private Sub CommandButton1_Click()
If OptionButton1.Value = True Then
Cells(1, 1).Value = "Tax"
OptionButton1.Value = False
End If
End Sub

Here's what I have. But it's not working
Code:
Private Sub OptionButton21_Click()

End Sub
Private Sub CommandButton1_Click()
If OptionButton21.Value = True Then
Cells(1, 3).Value = "Tax"
OptionButton1.Value = False
End If
End Sub

Can you tell me what's wrong?
 
Upvote 0
You put my script in your option Button.
You said you wanted the script to run when you clicked the command button.
Here is your quote:
"Hi MrKowz,

what I would like to do is not the option buttons to trigger my macro, I want another macro button to do the job, the option buttons are much more like parameters."


You need to put my script in a command button






Here's what I have. But it's not working
Code:
Private Sub OptionButton21_Click()

End Sub
Private Sub CommandButton1_Click()
If OptionButton21.Value = True Then
Cells(1, 3).Value = "Tax"
OptionButton1.Value = False
End If
End Sub

Can you tell me what's wrong?
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,287
Members
452,631
Latest member
a_potato

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