This goes in a regular module, it will determine what range the checkbox is that you just clicked.
You will have to play around with the colors...
Sub RangeOfButtonOrShape()
Dim r As Range, x
Set r = ActiveSheet.Shapes(Application.Caller).TopLeftCell 'find the range of the button clicked.
x = IIf(Range("Z" & r.Row) = False, xlNone, 16000 + r.Row * 100)
Range("A" & r.Row & ":B" & r.Row).Interior.Color = x
End Sub
This will go into the worksheet module,
It will add a checkbox into column B and create a linked cell to column Z, and assign the macro to the checkbox.
Private Sub CommandButton1_Click()
Dim ws As Worksheet, LastRow As Long, Rng As Range, c As Range, CkBx As CheckBox
Set ws = Worksheets("Sheet10")
With ws
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
Set Rng = .Range("B2:B" & LastRow)
For Each c In Rng.Cells
With c
Set CkBx = ws.CheckBoxes.Add _
(Top:=.Top, Width:=.Width, _
Height:=.Height, Left:=.Left)
End With
With CkBx
.Name = "cbx_" & c.Address(0, 0)
.Caption = c.Offset(, -1)
.LinkedCell = "Z" & c.Row
.OnAction = ThisWorkbook.Name & "!RangeOfButtonOrShape"
End With
Next c
End With
End Sub
Bookmarks