Hi,
it's all about the naming of the option buttons:
'Naming convention (e.g. "OP_A1Q1R1C1"):Two sets of OptionButtons.xls
'OP : optionbutton
'_ : placeholder
'A1 : attribute 1
'Q1 : question 1
'R1 : response 1
'C1 : code 1
Name your option buttons accordingly and assign all OP's from response 1 to the macro "OP_Click", it will dis-/enable the corresponding option buttons in response 2, change the back color of the cell and set the value to 0:
contains:
Option Explicit
'Naming convention:
'OP : optionbutton
'_ : placeholder
'A1 : attribute 1
'Q1 : question 1
'R1 : response 1
'C1 : code 1
Sub OP_Click()
Dim oOpClicked As Shape
'get clicked option button
Set oOpClicked = ActiveSheet.Shapes(Application.Caller)
'check if response = 1
If Mid(oOpClicked.Name, InStr(oOpClicked.Name, "R") + 1, 1) = "1" Then
Application.ScreenUpdating = False
'dis-/enable corresponding op's in response 2
OP_Enable Left(oOpClicked.Name, 7), (Mid(oOpClicked.Name, InStr(oOpClicked.Name, "C") + 1, 1) <> "0")
Application.ScreenUpdating = True
End If
End Sub
Sub OP_Enable(strOpName As String, blnEnabled As Boolean)
Dim oActive As Worksheet: Set oActive = ActiveSheet
Dim oOptButton As OptionButton
Dim iButtonCount As Integer
For iButtonCount = 1 To oActive.OptionButtons.Count
Set oOptButton = oActive.OptionButtons(iButtonCount)
With oOptButton
'if same attribute and question
If StrComp(Left(.Name, 7), strOpName, vbBinaryCompare) = 0 Then
'if response 2
If StrComp(Mid(.Name, InStr(.Name, "R") + 1, 1), "2", vbBinaryCompare) = 0 Then
'set enabled property
If .Enabled <> blnEnabled Then .Enabled = blnEnabled
If blnEnabled Then
.TopLeftCell.Interior.ColorIndex = 2
Else
.Value = 0
.TopLeftCell.Interior.ColorIndex = 16
End If
End If
End If
End With
Next iButtonCount
End Sub
Bookmarks