There were several mistakes:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Count <> 1 Then Exit Sub ' <- use Count, not CountLarge. If you want to exit, then it should be <> 1, not = 1
Static lngColor As Long, lngLastRow As Long, strAddress As String
On Error Resume Next
lngLastRow = Range("A5").End(xlDown).Row
Application.ScreenUpdating = False
If Not Intersect(Target, Range("A5", Range("G" & lngLastRow))) Is Nothing Then
If strAddress = "" Then
'do not exit sub here. If you exit sub, the address would never get saved, not even for the first time.
Else
Rows("5:" & lngLastRow).RowHeight = 15
Range(strAddress).Interior.Color = IIf(lngColor = 16777215, xlNone, lngColor)
End If
strAddress = Target.Address
lngColor = Target.Interior.Color
Target.Interior.Color = 13421823
Target.RowHeight = 25
Else ' Added this segment. necessary to reset color if clicking out of "designated range"
If strAddress = "" Then
'do not exit sub here.
Else
Rows("5:" & lngLastRow).RowHeight = 15
Range(strAddress).Interior.Color = IIf(lngColor = 16777215, xlNone, lngColor)
End If
End If
Application.ScreenUpdating = True
End Sub
Bookmarks