

If CheckBox2.Value = True Then 'If checked. If CheckBox1.Value = True Then 'If checked. When a checkbox is checked/unchecked, the value of the corresponding cell can be modified by using the Click event: Private Sub CheckBox1_Click() 'Number 1
#Control ie with vba how to#
Here is an example of how to use the CheckBox: Here is the downloadable Excel file: userform1.xls So as not to leave the right-hand side of the UserForm blank when there isn't any error, we can reduce its size by modifying the UserForm's Width property: Private Sub Textbox_number_Change() Range("A1") = Textbox_number.Value 'Copy to A1 We still need to prevent the validation of the form if the value is not numerical: Private Sub CommandButton_validate_Click() The value will be tested each time a character is entered. Label_error.Visible = False 'Label hidden If IsNumeric(Textbox_number.Value) Then 'IF numerical value.

Now let's add an event that will be fired when the value of the text box is changed, which will display an error message if the value is not numerical. The value will now be saved in cell A1 before the closing of the UserForm.Īdd a second Label and edit the following properties: Caption, Forecolor (color: red) and Visible (False, to hide the control by default):
#Control ie with vba code#
'We are using Me in place of the name of the UserForm (because this code is within the UserForm that we want to close) 'Value is the property that contains the value of the text box 'Textbox_number is the name of the text box Select a button and an event Click: Private Sub CommandButton_validate_Click() The drop-down list contains different controls and the UserForm. You can access the options that you see immediately below this text by double clicking on a control: To make something happen, we'll start by adding an event that puts the value of the text box into cell A1 and closes the UserForm.

We want the following result:įor now, when we enter a number and press OK, nothing happens. Now let's edit the names and properties of the controls (using the Caption property, which contains the text). Let's start by adding the following 3 controls: a Label, a TextBox and a CommandButton: Controls have all sorts of properties, and the events associated with them vary, but for now we will only look at a few of the many possible uses of controls in VBA coding.
