Results 1 to 2 of 2

change event delayed fire for data validation list

Threaded View

  1. #1
    Registered User
    Join Date
    09-11-2012
    Location
    Rockville, MD
    MS-Off Ver
    Excel 2003
    Posts
    47

    change event delayed fire for data validation list

    I want to run multiple change events in one worksheet; the change to run is range dependent. I have the following code, which sort of works. I don't get any errors and the changes I want eventually happen, but only after I click back and forth between cells. The codes work beautifully separately, but not so well in the combined change event.

    I have multiple columns. Every other column has a drop down list with 2 options, "Data" and "No Data". If the value in column C is "no data", then the adjacent cell in columns D, F, H should equal ".N". If the value of any cell in column E is "No Data", then the value of F should be ".N', likewise for column G triggers H. There will be more change events, all in the same worksheet, with similar logic.

    Thoughts?

    Option Explicit
     
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        Call ChangeEvent1(Target)
        Call ChangeEvent2(Target)
    End Sub
     
    Private Sub ChangeEvent1(ByVal Target As Range)
        Dim Rng As Range
        Dim RngEnd As Range
        
          ' Only one cell should be selected.
            If Target.Cells.Count > 1 Then Exit Sub
        
          ' The cell that changed value must in the range 
            If Intersect(Target, Range("E3:J313")) Is Nothing Then Exit Sub
        
          ' Only odd columns can be changed by the user.
            If Target.Column And 1 = 0 Then Exit Sub
        
            Set Rng = Cells(3, Target.Column)
            Set RngEnd = Cells(Rows.Count, Target.Column).End(xlUp)
            Set Rng = Range(Rng, RngEnd)
                
          ' If cell is not in the question range then exit.
            If Intersect(Target, Rng) Is Nothing Then Exit Sub
                
                ActiveSheet.Unprotect Password:="mypassword"
        
                Application.EnableEvents = False
        
                    If Target.Value = "No Data" Then
                        Target.Offset(0, 1).Locked = True
                        Target.Offset(0, 1).Value = ".N"
                        Target.Offset(0, 1).Interior.ColorIndex = 56
                        Target.Offset(0, 1).Interior.Pattern = xlSolid
                        
                    Else
                        Target.Offset(0, 1).Locked = False
                        Target.Offset(0, 1).Value = ""
                        Target.Offset(0, 1).Interior.ColorIndex = 0
                   End If
            
               ' ActiveSheet.Protect Password:="mypassword"
        
                Application.EnableEvents = True
          
    End Sub
     
    Private Sub ChangeEvent2(ByVal Target As Range)
         
          Dim Rng As Range
        Dim RngEnd As Range
        
          ' Only cell cell should be selected.
            If Target.Cells.Count > 1 Then Exit Sub
        
          ' The cell that changed value must in the range C3:AN323.
            If Intersect(Target, Range("C3:c313")) Is Nothing Then Exit Sub
        
          ' Only odd columns can be changed by the user.
            If Target.Column And 1 = 0 Then Exit Sub
        
            Set Rng = Cells(3, Target.Column)
            Set RngEnd = Cells(Rows.Count, Target.Column).End(xlUp)
            Set Rng = Range(Rng, RngEnd)
                
          ' If cell is not in the question range then exit.
            If Intersect(Target, Rng) Is Nothing Then Exit Sub
                            
                ActiveSheet.Unprotect Password:="mypassword"
    
                   
                Application.EnableEvents = False
        
                    If Target.Value = "No Data" Then
                        Target.Offset(0, 1).Locked = True
                        Target.Offset(0, 1).Value = ".N"
                        Target.Offset(0, 1).Interior.ColorIndex = 56
                        Target.Offset(0, 1).Interior.Pattern = xlSolid
                        Target.Offset(0, 3).Locked = True
                        Target.Offset(0, 3).Value = ".N"
                        Target.Offset(0, 3).Interior.ColorIndex = 56
                        Target.Offset(0, 3).Interior.Pattern = xlSolid
                        Target.Offset(0, 5).Locked = True
                        Target.Offset(0, 5).Value = ".N"
                        Target.Offset(0, 5).Interior.ColorIndex = 56
                        Target.Offset(0, 5).Interior.Pattern = xlSolid
                        Target.Offset(0, 7).Locked = True
                        Target.Offset(0, 7).Value = ".N"
                        Target.Offset(0, 7).Interior.ColorIndex = 56
                        Target.Offset(0, 7).Interior.Pattern = xlSolid
                    Else
                        Target.Offset(0, 1).Locked = False
                        Target.Offset(0, 1).Value = ""
                        Target.Offset(0, 1).Interior.ColorIndex = 0
                        Target.Offset(0, 3).Locked = False
                        Target.Offset(0, 3).Value = ""
                        Target.Offset(0, 3).Interior.ColorIndex = 0
                        Target.Offset(0, 5).Locked = False
                        Target.Offset(0, 5).Value = ""
                        Target.Offset(0, 5).Interior.ColorIndex = 0
                        Target.Offset(0, 7).Locked = False
                        Target.Offset(0, 7).Value = ""
                        Target.Offset(0, 7).Interior.ColorIndex = 0
                    End If
            
               ' ActiveSheet.Protect Password:="mypassword"
        
                Application.EnableEvents = True
          
    End Sub
    Last edited by ShoshanaM; 10-10-2012 at 04:06 PM. Reason: give better title to post

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1