Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 222
  • Last Modified:

Run a Sub on Check and Uncheck

Excel 2010

When checkbox is checked I want the first part to run. when unchecked I want the second part to run....is this possible using one checkbox control? Please help.

Private Sub CommandButton1_Click()
 If Value = True Then
    Range("C3").Select
    ActiveCell.ClearFormats
    ActiveCell.NumberFormat = "M/D/YYYY"

  Else
    Range("C3").Select
    Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlBetween, _
        Formula1:="=TODAY()", Formula2:="=TODAY()+15"
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    With Selection.FormatConditions(1).Font
        .Color = -16777024
        .TintAndShade = 0
    End With
    With Selection.FormatConditions(1).Interior
        .PatternColorIndex = xlAutomatic
        .ThemeColor = xlThemeColorAccent2
        .TintAndShade = 0.799981688894314
    End With
    Selection.FormatConditions(1).StopIfTrue = False

 End if
End Sub

Open in new window

0
BigBadWolf_000
Asked:
BigBadWolf_000
  • 2
  • 2
1 Solution
 
calacucciaCommented:
Change your test to the code beneath and it should work (you'll have to change CheckBox1 to whatever name the control has.

If CheckBox1.Value = True Then



0
 
cyberkiwiCommented:
Is the Checkbox the CommandButton1 itself? Or another control?
0
 
BigBadWolf_000Author Commented:
Yes the CheckBox1_Click() itsself. (CommandButton1 was a typo)
CheckBox1.Value did the trick thank you  calacuccia:
0
 
cyberkiwiCommented:
If Sheets("Sheet1").Shapes("Check Box 1").DrawingObject.Value = 1 Then
  ' it is checked
Else
  ' it is not checked
End if
0
 
BigBadWolf_000Author Commented:
Thanks for that code snippet too cyberkiwi:
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now