How to Use VBA Checkboxes to Enter Yes or No in Excel
Question details
The user needs to write a scalable VBA script that outputs 'Y' or 'N' to an Excel worksheet cell based on whether a UserForm checkbox is checked or unchecked.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Capturing user input from an interactive UserForm checkbox and converting the Boolean state into standard text responses.
- Observed behavior
- The VBA macro needs to evaluate the checkbox value (True/False) and correctly insert the desired text output ('Y' or 'N') into a specified dynamic range upon submission.
Ensure that your Excel workbook is saved as a Macro-Enabled Workbook (.xlsm) and that the Developer tab is visible on your ribbon to access the Visual Basic Editor.
Use an If...Then Statement Block
The standard and most readable way to handle True/False checkbox values in VBA is by using a conditional If...Then...Else statement.
This method is highly scalable and easy for beginners to understand. It explicitly checks the Boolean value of the UserForm checkbox and assigns the corresponding string to the target cell.
Press ALT + F11 in Excel to open the VBA Editor, then locate and view your UserForm in the Project Explorer.
Double-click the Submit or Save command button on your UserForm to open its Click event code module.
Enter the code: If DTTCheckBox.Value = True Then .Range("O" & lr).Value = "Y" Else .Range("O" & lr).Value = "N" End If (Ensure you replace 'DTTCheckBox', 'O', and 'lr' with your actual checkbox name, target column, and last row variable).

Use the IIf Function for Concise Code
For a shorter, single-line alternative, use the Immediate If (IIf) function to evaluate the checkbox state.
Create and Manage Macros Seamlessly with WPS Office
WPS Office fully supports VBA macros, providing a robust Developer environment layout similar to Microsoft Excel. You can create UserForms, write VBA code, and automate repetitive tasks without compatibility issues.
- 1. Enable Developer Tools: Open WPS Spreadsheet, go to the Options menu, and ensure the Developer tab is enabled on your ribbon.
- 2. Open the VBA Editor: Click the Developer tab and select 'Visual Basic', or press the ALT + F11 shortcut.
- 3. Create UserForms: Right-click your VBA project, select 'Insert', and choose 'UserForm' to drag and drop your checkboxes.
- 4. Add Checkbox Code: Double-click the UserForm controls to write your If...Then macro logic, then save the file as a macro-enabled workbook.

Frequently Asked Questions
Why is my checkbox VBA code returning an object error?
Errors often occur if the checkbox name referenced in your VBA code doesn't exactly match the 'Name' property of the checkbox control on the UserForm, or if the sheet reference variables (like 'lr' for last row) are not properly defined or set.
Can I use this code for ActiveX checkboxes placed directly on the worksheet?
Yes, but you will need to reference the worksheet object explicitly instead of the UserForm. For example, use Sheet1.CheckBox1.Value instead of a UserForm control name.
How do I clear the checkbox after saving the Yes/No data to the sheet?
After your code transfers the data to the cell, add a line like 'DTTCheckBox.Value = False' at the end of the submit procedure to reset the checkbox state for the next entry.




