Looking for simple VBA code to work with Value's and Radio Button Selection

Excel_User_10k

Board Regular
Joined
Jun 25, 2022
Messages
100
Office Version
  1. 2021
Platform
  1. Windows
Hi All, I have several Radio button selections as part of an Order form.

Radio Button A Options - Yes (1), No (2)
Radio Button B Options - Yes (1), No (2), N/A (3)
Radio Button C Options - Yes (1), No (2), N/A (3)

If Radio A is selected as No, then B and C are not applicable. Rather than having to Manually Select N/A on both Radio buttons B and C, I want them to Automatically go to N/A when Radio A > No is selected. I know this cannot be done with Formula's, as they would just be cleared when another option is selected. So I am trying to figure it out with VBA. So far I have:

VBA Code:
Sub Radio_Button()
If .Cells(13, 11) = 2 Then
.Cells(13, 3) = 3
.Cells(13, 7) = 3
End
End Sub

I feel like I am close. But at the moment, nothing is happening. Please can you tell me what I am missing and fill in the missing code?

Thank You
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
I try.
First, you should confirm your buttons are "Form Controls" or "ActiveX Controls".
I suppose yours are ActiveX.

Second, I suppose you have two buttons of option A, and one is named "OptionButtonA_YES", the other is named "OptionButtonA_NO".
The name should be changed like the red rectangle of the picture below.
And the two button should have the same "Group Name" like the blue rectangle. They are in Group Name "A".
IF you want to link some cell, ex "A1", you sholud fill "A1" into the "LinkedCell" of the picture.
1670220571377.jpg


Third, suppose you have another two button of option B, and one is named "OptionButtonB_YES", the other is named "OptionButtonB_NO".
The two are in the same Group Name, ex: "B". (It can't be the same with option A.)

Forth, you should put the code below in the sheet of VBA,ex: sheet1 , not in the module.
VBA Code:
Private Sub OptionButtonA_NO_Click()
    If OptionButtonA_NO = True Then
        OptionButtonB_YES = Null
        OptionButtonB_YES.Enabled = False
        OptionButtonB_NO = Null
        OptionButtonB_NO.Enabled = False
    End If
End Sub

Private Sub OptionButtonA_YES_Click()
    If OptionButtonA_YES = True Then
        OptionButtonB_YES.Enabled = True
        OptionButtonB_NO.Enabled = True
        OptionButtonB_YES = True
    End If
End Sub

Then, you can try to click the OptionButtonA_YES and OptionButtonA_NO, and you should see OptionButtonB_YES and OptionButtonB_YES are disable.

Hope this help.
 
Upvote 0
I try.
First, you should confirm your buttons are "Form Controls" or "ActiveX Controls".
I suppose yours are ActiveX.

Second, I suppose you have two buttons of option A, and one is named "OptionButtonA_YES", the other is named "OptionButtonA_NO".
The name should be changed like the red rectangle of the picture below.
And the two button should have the same "Group Name" like the blue rectangle. They are in Group Name "A".
IF you want to link some cell, ex "A1", you sholud fill "A1" into the "LinkedCell" of the picture.
View attachment 80173

Third, suppose you have another two button of option B, and one is named "OptionButtonB_YES", the other is named "OptionButtonB_NO".
The two are in the same Group Name, ex: "B". (It can't be the same with option A.)

Forth, you should put the code below in the sheet of VBA,ex: sheet1 , not in the module.
VBA Code:
Private Sub OptionButtonA_NO_Click()
    If OptionButtonA_NO = True Then
        OptionButtonB_YES = Null
        OptionButtonB_YES.Enabled = False
        OptionButtonB_NO = Null
        OptionButtonB_NO.Enabled = False
    End If
End Sub

Private Sub OptionButtonA_YES_Click()
    If OptionButtonA_YES = True Then
        OptionButtonB_YES.Enabled = True
        OptionButtonB_NO.Enabled = True
        OptionButtonB_YES = True
    End If
End Sub

Then, you can try to click the OptionButtonA_YES and OptionButtonA_NO, and you should see OptionButtonB_YES and OptionButtonB_YES are disable.

Hope this help.
Hi, thank you for replying.

Apologies, I guess I didn't write it as clear as I thought.

They are Radio Button GROUPS A B C, and are Form Control which is why they each have multiple options and why I put the numbers in brackets to show the number references that populate in the Cell ref when the relevant option is selected. It is also why my attempt at Coding has cell references with numbers as Values as well.

I DID put the coding on the Sheet and not as a Module.

I just thought there would be a simple code to change the value of the Cell references of B and C to "3" (i.e N/A - Not Applicable) when Group A is "2" (i.e Yes)

Hopefully this is clearer.
 
Upvote 0

Forum statistics

Threads
1,223,162
Messages
6,170,432
Members
452,326
Latest member
johnshaji

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