- Code: Select all
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, _
Cancel As Boolean)
' check VBA help under "PatternColorIndex Property"
' for a list of ColorIndex numbers you can use
' instead of this one:
Const MarkColor As Integer = 36
With Target.Cells.Interior
If .ColorIndex = MarkColor Then
.ColorIndex = xlNone
Else
.ColorIndex = MarkColor
.Pattern = xlSolid
End If
End With
Cancel = True ' this line may be removed
' Excel's normal double-click action is to
' open the target cell for editing.
' This line cancels that action.
End Sub
Install this code on any worksheet's code sheet. The functionality will be available within that sheet only, never the entire workbook.
For modification, observe the remarks at the top and bottom of the code.