I'm using this code provided by Marcelo Branco to visually highlight a cell when it becomes the active cell by changing its font color to orange, then changing the font color back to black when the user clicks elsewhere and the cell becomes non-active.
The SelectionChange event works great for this, but sometimes it becomes a nuisance when doing other things within the sheet. I would like to be able to disable this macro through a button as needed, then turn it back on (with the same button if possible) when it's needed again.
Can this be done?
The SelectionChange event works great for this, but sometimes it becomes a nuisance when doing other things within the sheet. I would like to be able to disable this macro through a button as needed, then turn it back on (with the same button if possible) when it's needed again.
Can this be done?
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range) Static PreviousCell As Range
If Not Intersect(Target, Range("H:H")) Is Nothing Then
If IsEmpty(Target) Then Exit Sub
If PreviousCell Is Nothing Then
Set PreviousCell = Target
Target.EntireColumn.Font.ColorIndex = xlAutomatic
Else
PreviousCell.Font.ColorIndex = xlAutomatic
End If
Target.Font.ColorIndex = 46
Set PreviousCell = Target
Else
Columns("H:H").Font.ColorIndex = xlAutomatic
End If
End Sub