Welcome to Excel Avon
Introduction of option Button
In today’s post we will explain you Introduction of Option Button in Excel VBA, In the previous post, we taught you that Data Entry with List box by User form in Excel VBA, let’s first understand the basic functionalities of OptionButton and how they work. Option Buttons are very useful controls available in VBA when a user wants to select one option from a small number of choices.
Option Buttons are always used in a group of two or more items. When we select an Option Button from a group, the other Option Buttons in that group get deselected, and this is the actual behavior of the Option Button.
Introduction Option Button in Excel VBA
If a UserForm or Data Entry form contains more than one set of Option Buttons, the Option Buttons in each set must have a unique GroupName property value in VBA. If we don’t assign the unique Group Name property to Option Buttons, then all Option Buttons become part of the same set.
To create a group, we can also use the Frame Control and enclose the Option Buttons in that. The Frame will automatically group the Option Buttons contained in it. Ok, you should know how to Insert UserForm, let’s understand. For how to use Option Buttons, we have to go to the Developer Tab like last time and then click on the option of Visual Basic as shown in the picture below.
On opening in VBE, you have to go to Insert and then UserForm has to be inserted, as can be seen in the image.
As you can see now, we have inserted UserForm
.
We will now drag the OptionButton, Then we will rename the button as ‘male’.
We will copy the option button, then we will also paste it and rename the button.
Now we will run the UserForm
As soon as the UserForm is run, we will open where we can see our inserted option button. But we can select only one option.
After this we will close the UserForm and explain in VBE. Now we will add third button in UserForm.
Now we will run the UserForm
As soon as the UserForm runs, the worksheet will open where we can see the three-option button we inserted. But still, we can choose only one option.
We will close the UserForm with the close button, and then we will delete all the buttons from the UserForm and then insert the frame in the UserForm along with we will rename its frame.
Now we will add optionbutton in frame 1. In frame one we have added only three option buttons which we can see after pressing run button but here also only one option will be able to be selected so now, we will create second frame.
In the same UserForm, we will add another frame to select multiple options, we will change the name of the frame by going to the properties of the frame.
In frame 2, we will add the Optionbutton, as we want to do it, we will change the name according to our properties.
When we run the UserForm, we can see some such UserForms where there are two different types of frames in which the options are also different, and we can select multiple.
If all these options are in the same frame, then you will select only one option.
Therefore, I hope that you have understood this article of ours very well, maybe if you do not understand some options, then you can comment us, which we will answer soon and for more information, you can follow us on Twitter, Instagram, LinkedIn and you can also follow on YouTube.
You can also see well-explained video here about Introduction of OptionButton in Excel VBA