How to set checked property in vba (format or control toolbar)

I am trying to change the value of my checkbox to true based on a different cell value

if range("A1").value = "green" then
Checkbox1.value= true

end if 

How to change the value of a property to true for several checkboxes simultaneously

For some reason, the code I tried does nothing. PS I use format flags

+3
source share
2 answers

This will change all the checkboxes.

Sub Changeboxes()

    Dim cb As CheckBox

    If Sheet1.Range("a1").Value = "green" Then
        For Each cb In Sheet1.CheckBoxes
            cb.Value = True
        Next cb
    End If

End Sub

If you need to specify specific flags, then

Sub ChangeSomeCbs()

    If Sheet1.Range("a1").Value = "green" Then
        Sheet1.CheckBoxes("Check Box 1").Value = True
        Sheet1.CheckBoxes("Check Box 2").Value = False
        Sheet1.CheckBoxes("Check Box 3").Value = True
    End If

End Sub

Checkbox and checkboxes are hidden properties. You will not get intellisense, but they work.

+5
source

This works fine for me:

If range("O26").Value = "green" Then
    CheckBox1.Value = True
    CheckBox2.Value = True
End If

If you are in development mode, this will not work.

0
source

Source: https://habr.com/ru/post/1749656/


All Articles