Hello,

My sheets are password protected, and I've set up the macros to automatically unlock (then lock) the sheets.
However, I still get an protection-error when trying to run the macros (even though it unlocks the sheet first).

I think this may be caused by Worksheet_Change, which also has password unprotect.
So that the Worksheet_Change locks the sheet before the macro has run.

Any suggestions as to how I can fix this? It worked before I made the Worksheet_Change unlock/lock sheets.

Here is my Worksheet_Change code:

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
ActiveSheet.Unprotect Password:="password"
If Not Intersect(Target, Range("A:A")) Is Nothing Then
    Cancel = True
Call DrilldownMotBilde(True)
End If
ActiveSheet.Protect Password:="password"
End Sub


Private Sub Worksheet_Change(ByVal Target As Range)
    ActiveSheet.Unprotect Password:="password"
    Set MyPlage = Range("B4:B200")
    For Each Cell In MyPlage
      
        Select Case Cell.Value
          
         Case Is = "New"
            Cell.EntireRow.Interior.ColorIndex = 3
          
        Case Is = "In Progress"
           Cell.EntireRow.Interior.ColorIndex = 44
                  
        Case Is = "Waiting"
            Cell.EntireRow.Interior.ColorIndex = 34
              
        Case Is = "Solved"
           Cell.EntireRow.Interior.ColorIndex = 50
        
        Case Is = "Aproval"
           Cell.EntireRow.Interior.ColorIndex = 17
              
        Case Else
            Cell.EntireRow.Interior.ColorIndex = xlNone
          
        End Select
    Next
    
     If Target.Column <= Range("G:G").Column Then
    Application.EnableEvents = False
        If Range("A" & Target.Row).Value >= 1000000 And Range("A" & Target.Row).Value <= 39999999 Then
             Range("H" & Target.Row).Value = Application.UserName
             Range("I" & Target.Row).Value = Now
        End If
    Application.EnableEvents = True
End If
ActiveSheet.Protect Password:="password"
End Sub