Mostafa Nabil
Mostafa Nabil

Reputation: 29

Vba to mark Check Box if specific cells contains specific imput

i need to create check box to be checked only if another specific cell contains specific input and unchecked if this input is not existing, noting that i tried below code

Private Sub Worksheet_Ca()

Dim DestS As Worksheet
Set DestS = ThisWorkbook.Worksheets("rest")

Dim DestSh As Range
Set DestSh = DestS.Range("B2")

If DestSh.Value = "Device" Then
DestS.CheckBoxes("Reset").Value = xlOn
Else
DestS.CheckBoxes("Reset").Value = xlOff
End If
End Sub

Also the check box i used is part of the forms toolbar not activeX and i changed the name of the check box to 'reset'

The error i got using debug is method of checkbox of object _worksheet failed

Upvotes: 1

Views: 815

Answers (1)

FaneDuru
FaneDuru

Reputation: 42236

Please, copy the next event code in the worksheet "rest" code module:

Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
  If Not Intersect(Target, Range("B2")) Is Nothing Then
    If Target.value = "Device" Then
        CheckBoxes("Reset").value = True
    Else
        CheckBoxes("Reset").value = False
    End If
  End If
End Sub

When you change the "B2" cell value in "Device", the check box will be checked. If you change its value in something else, the check box will be unchecked...

In order to copy the code in that sheet module, please activate sheet "rest" execute right click on the sheet name, choose View Code and copy the above code in the window which opens...

Upvotes: 1

Related Questions