Botão para bloquear e desbloquear bélulas específicas

ortegaf

06-02-2019 11:59:55

Tenho um código que bloqueia determinas células em um planilha:

Código: Selecionar todos

Sub Bloquear_Soja()

    Range("P8,P11,P14,P17,P20,P23,P26,P29,P32,P35,P42,Z8,Z11,Z14,Z17,Z20,Z23,Z26,Z29,Z32,Z35,AJ8,AJ11,AJ14,AJ17,AJ20,AJ23,AJ26,AJ29,AJ32,AJ35").Select
    Selection.Locked = True
    Selection.FormulaHidden = False
    ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
End Sub
Gostaria de criar um botão que ao clicar bloqueia e desbloqueia essas células, alguém pode ajudar?

Wagner Morel

06-02-2019 13:05:43

ortegaf,

Bom dia!

Veja e é assim.

ortegaf

06-02-2019 18:18:52

Isso mesmo!

Porém, preciso fazer isso em mais de uma Planilha... quando copio o código e mudo as células não da certo... Ele só bloqueia as células da ultima planilha(Rateios)

Código: Selecionar todos

Option Explicit
Sub Bloquear_Soja()


OPERATIVO.Select

Range("P8,P11,P14,P17,P20,P23,P26,P29,P32,P35,P42,Z8,Z11,Z14,Z17,Z20,Z23,Z26,Z29,Z32,Z35,AJ8,AJ11,AJ14,AJ17,AJ20,AJ23,AJ26,AJ29,AJ32,AJ35").Select
Selection.Locked = True
Selection.FormulaHidden = False
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True


RATEIOS.Select

Range("F8,F11,F14,P8,P11,P14,Z8,Z11,Z14,AJ8,AJ11,AJ14").Select
Selection.Locked = True
Selection.FormulaHidden = False
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True


End Sub


Sub Desbloquear_Soja()


OPERATIVO.Select
ActiveSheet.Unprotect
Range("P8,P11,P14,P17,P20,P23,P26,P29,P32,P35,P42,Z8,Z11,Z14,Z17,Z20,Z23,Z26,Z29,Z32,Z35,AJ8,AJ11,AJ14,AJ17,AJ20,AJ23,AJ26,AJ29,AJ32,AJ35").Select
Selection.Locked = False
Selection.FormulaHidden = True
  

RATEIOS.Select
ActiveSheet.Unprotect
Range("F8,F11,F14,P8,P11,P14,Z8,Z11,Z14,AJ8,AJ11,AJ14").Select
Selection.Locked = False
Selection.FormulaHidden = True


End Sub

Wagner Morel

07-02-2019 10:33:29

ortegaf,

Bom dia!

Ok. Todavia, em sua demanda você não anexou arquivo e nem disse como deveria ser. Desse modo, fica muito difícil adivinhar.

Veja se é assim.

ortegaf

08-02-2019 14:02:49

Muito Obrigado!