- 1). Launch Microsoft Excel.
- 2). Click the "Office" button at the top of the screen, then select the "Excel Options" button at the bottom of the window. Choose the "Show Developer Tab in the Ribbon" option, then click the "OK" button.
- 3). Press "Alt + F11," then double -click the sheet in the left-hand column that will have the mandatory field.
- 4). Type the following VBA code into the window:
Sub Button1_Click()
If Range("A2").Value = "" Then
MsgBox ("Please insert value in cell A2")
Exit Sub
End If
End Sub
You can replace each instance of "A2" to correspond to the cell or range of cells you are making mandatory. Additionally, whatever function this button will perform will be defined between "End If" and "End Sub." - 5). Return to your spreadsheet, then click the "Developer" tab at the top of the screen and click the "Insert" button.
- 6). Select the "Button" option from the "Forms" toolbar, then select a location on your spreadsheet for the button.
- 7). Click the "Button1_Click" option from the list under "Macro Name," then click the "OK" button.
SHARE