Browse » Home
Wednesday, June 15, 2011
How to Change Text Based on CheckBox Value in Excel
1. Open the Excel 2010 workbook that contains the checkbox that you want to manipulate.
2. Click the 'Developer' tab at the top of the screen. Click the 'Design Mode' button in the middle of the ribbon. This lets you interact with your checkbox.
3. Click on the checkbox to select it. Then, click the 'Properties' button in the 'Controls' area of the ribbon. A small Properties window will open up. Take note of the entry in the 'Name' field at the top of this window, which is usually 'CheckBox1,' or something similar. This is the name of the object, and you will need to know it to write your code. Click the 'X' to close the Properties window.
4. Right-click the checkbox and choose 'View Code' from the pop-up menu. The VBA editor window will appear, with the line 'Private Sub CheckBox1_Click()' already entered into the editor. Place your cursor on the line directly beneath this first one.
5. Enter the following code into the cell:If CheckBox1.Value Then[A1] = 'XXX'Else[A1] = 'YYY'End IfChange 'CheckBox1' to your checkbox's name. Change 'A1' to whatever cell you want the checkbox to manipulate. Change 'XXX' to whatever text you want in the cell when the checkbox has a check in it, and 'YYY' to whatever text you want in the cell when the checkbox is blank. To have one of the options leave a blank cell, just remove the letters but leave the quotes in place.
6. Click the 'X' to close the VBA editor. Click the 'Design Mode' button to turn it off. You can now add or remove a check mark from the checkbox, and your desired cell's text will change.