# Solved: Excel 2003 -checkbox VBA



## sk0101 (Nov 8, 2007)

Hi, 

Please see my attached file. I have created 2 checkboxes and in the vba code I want to check ie. If flag = false then "Checkbox False" should be checked.

I don't know how to access the two checkboxes in the vba code. 

Thank you.


----------



## computerman29642 (Dec 4, 2007)

SK, what are the flags? Can you give more details? Could you attach a file that will resemble the real file?


----------



## Rollin_Again (Sep 4, 2003)

Use an IF statement to check the value of the checkbox by name.


```
'Check to see if Check Box 1 is checked
 If ActiveSheet.CheckBoxes("Check Box 1").Value = 1 Then
 
 MsgBox ("TRUE")
 
 Else
 
 MsgBox ("False")
 
 End If
```
If you are simply trying to set the value via code you can just issue the following commands.


```
'Put a check in the box
ActiveSheet.CheckBoxes("Check Box 2").Value = 1

'Remove check from box
ActiveSheet.CheckBoxes("Check Box 2").Value = 0
```
Regards,
Rollin


----------



## sk0101 (Nov 8, 2007)

Hi 
Please see updated excel file. I have updated the vba code.

What I am trying to do is check in the data tab if the value is true or false then in the display tab checkmark the right checkbox.

I hope it is clear now what I am trying to do.

Thank you.


----------



## sk0101 (Nov 8, 2007)

Got it.

I just tried to add the below code:

wk.Worksheets("Display").CheckBoxes("Check Box 2").Value = 1

and it worked. 

Thank you for your help.


----------



## Rollin_Again (Sep 4, 2003)

```
If (wk.Worksheets("Data").Range("C5").Value = False) Then
        MsgBox ("false")
       Sheets("Display").CheckBoxes("Check Box 1").Value = 0
       Sheets("Display").CheckBoxes("Check Box 2").Value = 1
    Else
        Sheets("Display").CheckBoxes("Check Box 1").Value = 1
        Sheets("Display").CheckBoxes("Check Box 2").Value = 0
         MsgBox ("true")
    End If
```
Regards,
Rollin


----------

