I have a question, i've tried to search the internet alot, but havent found a solution to help me.
Heres my problem: I have a dropdown menu in sheet3 (called ws_step3 in vba) at cell J3. The dropdown menu has 9 options, where 2 of those options automatically should enable a checkbox (lets call the checkbox "Coffeecup")
The 9 options are A,B,C etc.
Im looking for a VBA code that automatically checks that checkbox if 2 of the options are checked (lets say its C and F that checks the checkbox)
Im using Active X checkboxes, and using drop down menus
Hope anyone can help me.
TY in advance from a newcomer in VBA :-)
/Klaus
Edit #1 - Tried this first
Private Sub Worksheet_Calculate()
If ws_Step3.Range("J3").Value = "C" Then
ws_Step3.CheckBoxes("Coffeecup").Value = xlOn
Else
ws_Step3.CheckBoxes("Coffeecup").Value = xlOff
End If
End Sub
Edit #2 - Credit to DDuffy for helping on this one - I already have this in my Private Sub Worksheet_Change(ByVal Target As Range) for J3
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$J$3" Then
'Hvis værdien hedder "fremført cykelsti":
If ws_Step3.Cells(3, 10).Value = WS_DDL.Cells(2, 2).Value Then
'Default value sættes til det første i dropdown
ws_Step3.Cells(8, 12).Value = WS_DDL.Cells(3, 2).Value
End If
'Hvis værdien hedder "Afkortet cykelsti":
If ws_Step3.Cells(3, 10).Value = WS_DDL.Cells(13, 2).Value Then
'Default value sættes til det første i dropdown
ws_Step3.Cells(8, 12).Value = WS_DDL.Cells(14, 2).Value
End If
'Hvis værdien hedder "Venstresving fra langsiden af T-kryds":
If ws_Step3.Cells(3, 10).Value = WS_DDL.Cells(17, 2).Value Then
'Default value sættes til det første i dropdown
ws_Step3.Cells(8, 12).Value = WS_DDL.Cells(18, 2).Value
End If
'Hvis værdien hedder "Cykelbane":
If ws_Step3.Cells(3, 10).Value = WS_DDL.Cells(21, 2).Value Then
'Default value sættes til det første i dropdown
ws_Step3.Cells(8, 12).Value = WS_DDL.Cells(22, 2).Value
End If
'Hvis værdien hedder "Ingen cykelfaciliteter":
If ws_Step3.Cells(3, 10).Value = WS_DDL.Cells(27, 2).Value Then
'Default value sættes til det første i dropdown
ws_Step3.Cells(8, 12).Value = WS_DDL.Cells(28, 2).Value
End If
'Hvis værdien hedder "Højresvingsshunt":
If ws_Step3.Cells(3, 10).Value = WS_DDL.Cells(31, 2).Value Then
'Default value sættes til det første i dropdown
ws_Step3.Cells(8, 12).Value = WS_DDL.Cells(32, 2).Value
End If
'Hvis værdien hedder "Hollænderboks":
If ws_Step3.Cells(3, 10).Value = WS_DDL.Cells(42, 2).Value Then
'Default value sættes til det første i dropdown
ws_Step3.Cells(8, 12).Value = WS_DDL.Cells(43, 2).Value
End If
'Hvis værdien hedder "Cykelsti i eget trace":
If ws_Step3.Cells(3, 10).Value = WS_DDL.Cells(46, 2).Value Then
'Default value sættes til det første i dropdown
ws_Step3.Cells(8, 12).Value = WS_DDL.Cells(47, 2).Value
End If
'Hvis værdien hedder "Tilladt højresving for rødt":
If ws_Step3.Cells(3, 10).Value = WS_DDL.Cells(57, 2).Value Then
'Default value sættes til det første i dropdown
ws_Step3.Cells(8, 12).Value = WS_DDL.Cells(58, 2).Value
End If
End If
End Sub
And DDuffys suggestion comes here (changed it to the real problem, no more beating around the bush)
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
Application.EnableEvents = False
On Error GoTo Errortrap
'~~> Change it to the relevant string with which you want to compare
StringToCheck1 = "Hoejresvingsshunt"
StringToCheck2 = "Tilladt Hoejresving for roedt"
If Not Intersect(Target, Range("J3")) Is Nothing Then
'~~> Check for the cell value
If Target.Value = StringToCheck1 Then
'change checkbox value to true if it matches
Worksheets("ws_Step3").HoejreD.Value = True
ElseIf Target.Value = StringToCheck2 Then
'change checkbox value to true if it matches
Worksheets("ws_Step3").HoejreD.Value = True
Else
'change checkbox value to false if it doesn't match
Worksheets("ws_Step3").HoejreD.Value = False
End If
End If
LetsContinue:
Application.EnableEvents = True
Exit Sub
Errortrap:
MsgBox Err.Description
Resume LetsContinue
End Sub
My question is now, how do i merge these to worksheet changes?
I have a image of my worksheet here: https://i.stack.imgur.com/IxdvY.jpg