Excel Checkbox: If Checked then Change Cell Color (2 Methods)

How to Insert Checkboxes in Excel

Method 1 – Insert a Single Checkbox

Steps

How to Insert a Checkbox in Excel

  • Click the Insert option. From Form Controls, click on the Checkbox.

  • You will find a plus sign(+) that indicates the checkbox. Place it in any cell.
  • You will get the following checkbox.


Method 2 – Insert Multiple Checkboxes and Link Them

We’ll fill column B with six checkboxes and link them to the respective cells in column C.

Insert Multiple Checkboxes in Excel

Steps

  • Press Alt + F11 on your keyboard to open the VBA editor.
  • Select Insert and choose Module.

  • Insert the following code:
Sub add_multiple_checkbox()

Dim cell As Range

Dim shape_of_box As CheckBox

  For Each cell In Selection.Cells

    Set shape_of_box = ActiveSheet.CheckBoxes.Add(cell.Left, cell.Top, cell.Width, cell.Height)

    With shape_of_box

      .Text = ""

      .Width = cell.Width

      .LinkedCell = cell.Offset(0, 1).Address

    End With

  Next cell

End

End Sub
  • Save the file.
  • Select the range of cells B5:B10.

Insert Multiple Checkboxes in Excel

  • Press Alt + F8 to open the Macro dialog box.

  • Select add_multiple_checkbox.
  • Click on Run.

Insert Multiple Checkboxes in Excel

  • You’ll get multiple checkboxes in the Checkbox column. You can tick a box and set the adjacent value to TRUE.

Insert Multiple Checkboxes in Excel


Customize the Checkbox in Excel

  • You can drag the box around the checkbox to make it bigger or smaller:

Customize the Checkbox in Excel

  • You can change the “Check Box 1” name to another name. Right-click on the checkbox and choose Edit Text.


Link the Checkbox with a Cell

Steps

  • Right-click on the checkbox.

  • Click on the Format Control option.

Link the Checkbox with a Cell

  • From the Format Control dialog box, go to the Control tab.
  • In the Cell link box, insert or select the cell you want to link with the checkbox.
  • Click on OK.

Link the Checkbox with a Cell

  • If you check the box, the value is set to TRUE. Otherwise, it stays FALSE.

Link the Checkbox with a Cell


How to Change Cell Color in Excel If Checkbox is Checked: 2 Methods


Method 1 – Use Excel Conditional Formatting to Change Color If the Checkbox Is Checked

We’ll use a simple dataset with a single checkbox linked to an adjacent cell.

Excel to Change Cell Color If Checkbox Is Checked 

Steps

  • Click on Cell D4.
  • From the Home tab, click on Conditional Formatting.
  • Click on New Rule, or click on Manage Rules and select New Rule.

Excel to Change Cell Color If Checkbox Is Checked 

  • Select the option Use a formula to determine which cells to format.
  • Insert the following formula in the box:

=$C$4=TRUE

Excel to Change Cell Color If Checkbox Is Checked 

  • Click on Format.
  • Click on Fill. 
  • Choose any color that’s not white and click on OK.

  • Your formula and the background color are set. Click on OK again.

  • If you’ve used Manage Rules, you’ll need to click OK again.

  • Here’s the result.

Excel to Change Cell Color If Checkbox Is Checked 

  • Tick the checkbox and the color changes.

Excel to Change Cell Color If Checkbox Is Checked 


Method 2 – Use Excel VBA to Change Cell Color If the Checkbox Is Checked+

Steps

  • Right-click on the checkbox.
  • Click on Assign Macro.

Excel to Change Cell Color If Checkbox Is Checked 

  • Give the Macro a name.
  • Click on New. It will open the Visual Basic Editor.

  • Insert the following code:
Sub change_cell_color()

Dim rng As Range

Set rng = Range("D4")

If Range("C4").Value = True Then

    rng.Interior.Color = vbRed

Else

    rng.Interior.Color = xlNone

End If

End Sub
  • Save the file.
  • If you check the box, it will change the cell color to Red.

Excel to Change Cell Color If Checkbox Is Checked 


Set a Cell Value in Excel If the Checkbox Is Checked

We’ll use the same dataset.

  • Right-click on the checkbox and click on Assign macro.

Set a Cell Value in Excel If Checkbox Is Checked 

  • Name the macro and click on New in the Macro box.
  • Insert the following code in the editor.
Sub set_cell_value()

Dim rng As Range

Dim c As Range, cell_value As String

Set rng = Range("D4")

If Range("C4").Value = True Then

    rng.Value = "Done!"

Else

    rng.Value = ""

End If

End Sub
  • Save the file. You can see no value yet.

Set a Cell Value in Excel If Checkbox Is Checked 

  • Click on the checkbox and you will see a value in Cell D4:

Set a Cell Value in Excel If Checkbox Is Checked 

You can modify the value by changing the text in the following code line:

rng.Value = "Done!"

Read More: What Can You Do with Cell Value If Checkbox Is Checked in Excel?


Things to Remember

You can also insert a checkbox from ActiveX controls.

You can also change the color of multiple cells if the checkbox is checked. Select the range of cells you want to color and follow a similar process in Conditional Formatting.

You must save the file in the .xlsm format.


Download the Practice Workbook


Related Articles


<< Go Back to Excel CheckBox | Form Control in Excel | Learn Excel

Get FREE Advanced Excel Exercises with Solutions!
A.N.M. Mohaimen Shanto
A.N.M. Mohaimen Shanto

A.N.M. Mohaimen Shanto, a B.Sc. in Computer Science and Engineering from Daffodil International University, boasts two years of experience as a Project Manager at Exceldemy. He authored 90+ articles and led teams as a Team Leader, meticulously reviewing over a thousand articles. Currently, he focuses on enhancing article quality. His passion lies in Excel VBA, Data Science, and SEO, where he enjoys simplifying complex ideas to facilitate learning and growth. His journey mirrors Exceldemy's dedication to excellence and... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo