zoom38
01-27-2024, 10:12 AM
Hello, I have the below code in a worksheet selection_change event that is activating when I select cells for printing. The selection for printing is larger than the target ranges in the code. Is there a way to prevent this code from activating when selecting cells that include the target range as well as cells that are outside of that target range? Another way of asking, can the code be modified so that it activates when only one cell is selected within the target range?
Option Explicit
Private Sub Worksheet_SelectionChange(ByVal target As Range)
Dim myRng As Range
Dim myAddress As Range
Application.EnableEvents = False
Application.ScreenUpdating = False
ActiveSheet.Unprotect
If Not Intersect(target, Range("$B$5:$H$20,$J$5:$P$20")) Is Nothing Then
Call HighlightRowsMeterCharts(target)
End If
ActiveSheet.Protect
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub
Thanks
Gary
Option Explicit
Private Sub Worksheet_SelectionChange(ByVal target As Range)
Dim myRng As Range
Dim myAddress As Range
Application.EnableEvents = False
Application.ScreenUpdating = False
ActiveSheet.Unprotect
If Not Intersect(target, Range("$B$5:$H$20,$J$5:$P$20")) Is Nothing Then
Call HighlightRowsMeterCharts(target)
End If
ActiveSheet.Protect
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub
Thanks
Gary