Option Explicit
Dim bSwitch As Boolean
Dim bRw As Boolean
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Cancel = True
If bSwitch Then Exit Sub
With Application
.EnableEvents = False
With Cells
.Interior.ColorIndex = 0
.Font.Bold = False
End With
.EnableEvents = True
End With
End Sub
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
Cancel = True
If bSwitch Then
If MsgBox("Shut off the highlighter?", 36) = 7 Then Exit Sub
Else
If MsgBox("Turn on the highlighter?", 36) = 7 Then Exit Sub
End If
If Selection.Rows.Count > 1 Then
bRw = False
Else
bRw = True
End If
bSwitch = Not bSwitch
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not bSwitch Then Exit Sub
Const szRCName As String = "rgnRC"
Dim rRng As Excel.Range
Dim szOldTarget As String
Dim vArrCellTypes As Variant
Dim vCell As Variant
vArrCellTypes = Array(xlCellTypeConstants, xlCellTypeFormulas)
On Error Resume Next
szOldTarget = Replace$(Names(szRCName).RefersTo, "=", "")
szOldTarget = Replace$(szOldTarget, """", "")
Application.EnableEvents = False
Application.ScreenUpdating = False
With Range(szOldTarget)
.Interior.ColorIndex = 0
.Font.Bold = False
End With
If bRw Then
Set rRng = Range(Target.EntireRow.Address)
Else
Set rRng = Range(Target.EntireColumn.Address)
End If
For Each vCell In vArrCellTypes
With rRng.SpecialCells(CLng(vCell))
.Interior.ColorIndex = 15
.Font.Bold = True
End With
Next vCell
If bRw Then
Names.Add szRCName, Target.EntireRow.Address, False
Else
Names.Add szRCName, Target.EntireColumn.Address, False
End If
Application.EnableEvents = True
Application.ScreenUpdating = True
Set rRng = Nothing
End Sub
|