Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I'm trying to change the value of my checkbox to true based on a another cell's value

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

end if 

How to I change the value property to true for multiple checkbox at the same time

For some reason the code that i've tried doesn't do anything at all. P.S. I'm using format checkboxes

like image 405
user362729 Avatar asked Jun 11 '10 17:06

user362729


1 Answers

This will change all 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 particular checkboxes, 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 won't get intellisense, but they work.

like image 187
Dick Kusleika Avatar answered Nov 15 '22 09:11

Dick Kusleika