ActiveX controls – Option Button in Excel VBA

Building an application for entering data – Inserting an Option Button Option (ActiveX Control)

We would like the data on gender to be entered in the “I” column of our data table, which is the value of Woman or Man. In this case, we should construct our application in such a way as to make it impossible to mark both options at the same time. The best way to do this is to use it OptionButton. How do I insert an OptionButton? From the ActiveX controls in the Developer tab, select two Options button controls. Put them above the column “I”. When entering the properties of controls, let’s correct for them the values ​​in the Caption fields for “Woman” for OptionButton1 and “Male” for OptionButton2. It is worth noting that another common name of the radio button is RadioButton

 

Building an application for entering data – Programming the Option Button Option (ActiveX Control)

OptionButton buttons are already embedded in our application. How can we program OptionButton option buttons? In the code block responsible for entering the data, we should enter the conditional statement If Then Else . Below the code snippet:

As you can see, we have introduced the ElseIf element to our instruction . The code has been saved in this way, because we can meet with the situation when no option is selected. The selected radio button accepts True in VBA . Decorated False value . The code of our program in the Arkusz1 object now looks like:

Leave a comment

Your email address will not be published. Required fields are marked *

%d bloggers like this: