ActiveX controls – CommandButton in Excel VBA

Building an application for entering data – Inserting a Command Button – CommandButton (ActiveX Control) 

The command button is already known to us. In the simplest form, it will be used to run written scripts. The command button can be embedded in both the Excel spreadsheet and the UserForm form. How do I insert a CommandButton command button? Go to the Developer tab in succession , then insert the ActiveX controls and select the command button. The same applies to the UserForm form. From the ToolBox window, select the controlCommandButton. At this point, our application contains one CommandButton button named Enter. We want to create another button used to clear data in the form. Let’s put the second ActiveX button – CommandButton in our form. In the properties, change the value in the Caption field to “Clear”.


Building an application for entering data – Programming the CommandButton command button (ActiveX Control) 

The button is programmed by double-clicking it in the design mode. The code is edited in the code of the sheet object. In our case it will be Sheet1. For our button, we create a code that erases all data present in the TextBox, ComboBox, OptionButton and CheckBox fields. The code looks like:

In this way you have programmed the button that cleans the data in our form. The program code in the Sheet1 object looks like:

Leave a comment

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

%d bloggers like this: