Search code examples
vbaexceluserform

Display Else value with VBA checkboxes


This code is intended to place the word "New" if the checkbox is checked, and a ✓ checkmark if it's unchecked.

If CheckBox2.Value = False Then
Cells(3, 3) = ChrW(&H2713)  # <-- checkmark ✓
Else: Cells(3, 3) = "New"
End If

However, currently, this only places the word "New" if the checkbox is selected, but it won't place a ✓ checkmark if it's not selected! I can get a checkmark to be displayed when they select the checkbox then unselect the checkbox, but this is cumbersome.

How do I fix this?


Solution

  • This is probably the easiest & dirtiest solution:

    Private Sub CheckBox1_Click()        
        If CheckBox1.Value Then
            Cells(3, 3) = "New"
        Else
            Cells(3, 3) = ChrW(&H2713)
        End If        
    End Sub
    

    Every time you select the checkbox, the C3 cell would be updated with either or New. There is a better way to do this, but it requires Object Oriented Programming - Is VBA an OOP language, and does it support polymorphism?

    References for the "better way":