Search code examples
excelvba

Mark checkbox based on value in a cell


I currently have a vba-written Macro that populates a form I have in worksheet "Design" based on values in a row in worksheet "info". Once all fields are populated in the form, it is then printed to PDF, then does the same for every row with data. On the form I have check boxes that are manually marked after the PDF creation; HOWEVER, i was wondering if we can include VBA in the same Macro that would mark the a checkbox based on the specific value in a cell within the row of the "info" worksheet. to make this easier, the cell has a data validation that would only allow the selection of specific values.

For example, if c3 = rain, then mark box in d4, if c3 = sunshine, then mark box in d5, and so on.


Solution

    • Assuming ActiveX checkbox control is used on worksheet.
    Option Explicit
    
    Private Sub Worksheet_Change(ByVal Target As Range)
        Call UpdateChkBox
    End Sub
    
    Sub UpdateChkBox()
        Sheets("Sheet1").CheckBox1.Value = (Range("c3") = "rain")
        Sheets("Sheet1").CheckBox2.Value = (Range("c3") = "sunshine")
    End Sub
    
    

    enter image description here