PDA

View Full Version : [SOLVED:] Prevent Macro From Activating Upon Selecting Cells For Printing



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

zoom38
01-27-2024, 10:22 AM
Found an answer that seems to work.



If Not Intersect(Target, Range("$B$5:$H$20,$J$5:$P$20")) Is Nothing Then
If Selection.Count = 1 Then
Call HighlightRowsMeterCharts(Target)
End If
End If

Aussiebear
01-27-2024, 11:56 AM
Glad you were able to find an answer