Toggle checkbox values in vba

melodramatic

Board Regular
Joined
Apr 28, 2003
Messages
180
Office Version
  1. 365
Platform
  1. Windows
I'm running a macro that pulls up a file template, then asks you a series of questions to get the file set for who and what it needs to get the data.

The problem I'm having is in having it check the appropriate checkboxes. I've never done this before, and somewhere I'm screwing up.

If you answer the questions "No", then no problem - it bypasses and goes to the next question. So obviously my error is in the action line. I have opened the properties box and doublecheck that my checkboxes are named CheckBox1, CheckBox2, CheckBox3, CheckBox4 & CheckBox5. Their default setting in the template is false (unchecked).

Here's what I've got...

Code:
            If MsgBox("Was RAW DATA delivered to the Client?", vbYesNo) = vbYes Then
                CheckBox1.Value = True
            End If
            If MsgBox("Were PHOTOS delivered to the Client?", vbYesNo) = vbYes Then
                CheckBox2.Value = True
            End If
            If MsgBox("Were TEST LOGS delivered to the Client?", vbYesNo) = vbYes Then
                CheckBox3.Value = True
            End If
            If MsgBox("Was an EMAIL SUMMARY delivered to the Client?", vbYesNo) = vbYes Then
                CheckBox4.Value = True
            End If
            If MsgBox("Was any other type documentation delivered to the Client?", vbYesNo) = vbYes Then
                CheckBox5.Value = True
                OtherDesc = InputBox("Please list other documentation provided to Client:", "Other Documentation Provided")
                Range("G22").Select
                ActiveCell.FormulaR1C1 = OtherDesc
            End If

Help?
 
Last edited:

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Try change sheet1 to fit your data
Code:
Sheet1.CheckBoxes("Check Box 1").Value = True
 
Upvote 0
Still getting an error. My sheet name is "Waive" - does that make a difference in the coding?
 
Upvote 0
The msgbox needs a variable to be checked against, the above will always return false.

Try:

Code:
Dim answer As Integer

answer = MsgBox("Question", vbYesNo)


If answer = vbYes Then blahblahblah
 
Upvote 0
In the VBA editor your will see something like

VBAProject (workbookname)
microsoft Excel Objects
Sheet1(Sheet1)
Sheet2(Sheet2)
Sheet3(Waive)
Sheet4(Sheet4)

even though Sheet3 is name Waive I use the below code to change the check box on that sheet.
Code:
Sheet3.CheckBoxes("Check Box 1").Value = True

Use the Sheet# not the name in the parentheses as listed in the VBA Project.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,952
Messages
6,122,457
Members
449,083
Latest member
Ava19

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