Add checkbox to cell where cell equals yes

TaskMaster

Board Regular
Joined
Oct 15, 2020
Messages
75
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hi all,

I currently have to highlight all of my cells which contain the word Yes and use the following to add in a checkbox. Is there a way to automate this so rather than selecting the range it just does it where the cell is Yes?

VBA Code:
Sub InsertCheckboxes()

    Dim c As Range

    For Each c In Selection
        Dim CB As CheckBox
        Set CB = ActiveSheet.CheckBoxes.Add(c.Left, _
                                    c.Top, _
                                    c.Width, _
                                    c.Height)
        With CB
            .Caption = ""
           ' .Value = xlOff
           ' .LinkedCell = c.Address
            .Display3DShading = False
        End With
    Next
End Sub
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
You are going to have to tell Excel where to look on your sheet to find the "Yes". Whether you do it in the code or manually. It is not practical to have Excel search the entire sheet.
Something like this (using your code) will look at Range("E1:E20") for the word "Yes", delete that text ("Yes") and replace it with a checkbox that is checked or true.

VBA Code:
Sub InsertCheckboxes()

    Dim c As Range
    Dim CB As CheckBox
    
    For Each c In Range("E1:E20")
        If c.Value = "Yes" Then
            c.Value = ""
            Set CB = ActiveSheet.CheckBoxes.Add(c.Left, _
                c.Top, _
                c.Width, _
                c.Height)
            With CB
                .Caption = ""
                .Value = True
                '.LinkedCell = c.Address
                .Display3DShading = False
            End With
        End If
    Next
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,816
Messages
6,181,138
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top