Notifications
Clear all

Desproteger planilha

3 Posts
2 Usuários
0 Reactions
1,008 Visualizações
(@silviag123)
Posts: 0
New Member
Topic starter
 

Preciso desproteger uma planilha sempre que alguma célula da coluna N for selecionada.

Estou usando a macro abaixo, porém, não está funcionando. Alguém poderia me ajudar?

Private Sub Worksheet_Change(ByVal Target As Range)

    If Target.Address = "N:N" Then ActiveSheet.Unprotect Password:="1234"
    
    If Intersect(Target, Range("N:N")) Is Nothing Or Target.Cells.Count > 1 Then Exit Sub

    Application.EnableEvents = False
ActiveSheet.AutoFilter.ApplyFilter
    With ActiveWorkbook.Worksheets("Priorização").AutoFilter.Sort
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
    Application.EnableEvents = True
  
    
    Protect Password:="1234", UserInterfaceOnly:=True
End Sub
 
Postado : 04/11/2019 9:22 am
(@coutinho)
Posts: 0
New Member
 

Silviag123, veja se é isso o que quer :

Private Sub Worksheet_Change(ByVal Target As Range)

    Application.EnableEvents = False

    If Intersect(Target, Range("N:N")) Is Nothing Or Target.Cells.Count > 1 Then
        Exit Sub
    
    Else
        ActiveSheet.Unprotect Password:="1234"
    
        ActiveSheet.AutoFilter.ApplyFilter
        
        With ActiveWorkbook.Worksheets("Priorização").AutoFilter.Sort
            .Header = xlYes
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
    
        Application.EnableEvents = True
        
        Protect Password:="1234", UserInterfaceOnly:=True
    
    End If

End Sub

[]s
Mauro Coutinho

 
Postado : 04/11/2019 9:53 am
(@silviag123)
Posts: 0
New Member
Topic starter
 

Muito obrigada! Deu certo!!!

 
Postado : 04/11/2019 2:06 pm