Last Updated on January 11, 2023 by token
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:
If OptionButton1 = True Then Cells(sngWiersz, 9) = "Woman" ElseIf OptionButton2 = True Then Cells(sngWiersz, 9) = "Men" Else: Cells(sngWiersz, 9) = "" End If
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 .