Try this:-
This is not too complicated if you take it a step at a time.
It is the assumed that the related sheet has 4 OptionButtons in each cell in column "A" . The 4 buttons have Captions:- Green, Orange,Red and Blank.
You can have as many cells in Column "A" with "Optionbuttons" as you like..
Step (1)
Right Click the sheet Tab and from the "Dropdown" select "View Code".
VBWindow appears.
Copy and Paste the code below into the VbWindow at the very top of the Window , insuring you don't end up with two "Option Explicit"s at the top..of the window.
Option Explicit
Dim myCbs() As clsOpButton
Private Sub Worksheet_Activate()
Dim pointer As Long
Dim oneControl As OLEObject
ReDim myCbs(1 To ActiveSheet.OLEObjects.Count)
For Each oneControl In ActiveSheet.OLEObjects
If TypeName(oneControl.Object) = "OptionButton" Then
pointer = pointer + 1
Set myCbs(pointer) = New clsOpButton
Set myCbs(pointer).oPton = oneControl.Object
End If
Next oneControl
ReDim Preserve myCbs(1 To pointer)
End Sub
Step (2)
With the VBwindow still open, look on the left hand side, where there should be the "Project Window" if it is not there click "Ctrl+R"
Right click somwhere in that "Project Window." and from the "DropDown" select "Insert" then "Class Module". New Vb window appears and a new Module title in the "Project Window" showing a "Class1"
Paste the code below into that VBWindow.
Option Explicit
Public WithEvents oPton As MSForms.OptionButton
Private Sub opton_Click()
With oPton.TopLeftCell.Offset(, 1).Interior
Select Case oPton.Caption
Case "Green": .ColorIndex = 4
Case "Orange": .ColorIndex = 45
Case "Red": .ColorIndex = 3
Case "Blank": .ColorIndex = 2
End Select
End With
End Sub
In the "Project Window" Click on the Module "Class1", then click "F4", The "Class1" properties window appears. Change the "Name" in the window from "Class1" to "clsOpButton" (No Commas)
Close the Vb windows.
To collect all the OptionButton Information and run the first bit of code you need to select another sheet, then reselect the "OptionButton" sheet.
You should now be able to Click any of the "Option Buttons" and the Column"B" cell will change colour accordingly.
Good Luck
Regrds Mick
Bookmarks