Consulting

Results 1 to 3 of 3

Thread: Prevent Macro From Activating Upon Selecting Cells For Printing

  1. #1
    VBAX Mentor
    Joined
    Jan 2006
    Posts
    323
    Location

    Prevent Macro From Activating Upon Selecting Cells For Printing

    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

  2. #2
    VBAX Mentor
    Joined
    Jan 2006
    Posts
    323
    Location
    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

  3. #3
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,059
    Location
    Glad you were able to find an answer
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •