Re : Protection cellules par macro
Bonjour,
Le fichier fonctionne,mais quand j'ajoute une autre feuille à protéger j'ai un message"erreur de compilation"next sans for.
Info:Toutes les cellules ont une mise en forme conditionnelle.
Merci de votre aide.
laplayast.
Je joins le code:
Private Sub Workbook_SheetDeactivate(ByVal Sh As Object)
If ActiveSheet.Index < Sh.Index Then Exit Sub
If Sh.Cells.SpecialCells(xlCellTypeAllFormatConditions).Count = 0 Then Exit Sub
With Application
.EnableEvents = False
If .CountA(Sh.Cells.SpecialCells(xlCellTypeAllFormatConditions)) <> _
Sh.Cells.SpecialCells(xlCellTypeAllFormatConditions).Count Then
Sh.Activate
MsgBox "Faut tout remplir, mon gars!"
End If
.EnableEvents = True
End With
End Sub
Private Sub Workbook_Open()
For Each Sh In Sheets
Sh.Protect userInterfaceOnly:=True
Next Sh
With Sheets("feuille1")
.Unprotect Password:="toto"
.Cells.Locked = True
.Range("B3:B4,B8,B24:B44,B64:B73,C20,C56:C57,C59:C61,D3,D8,D11😀16,D32😀33,D66😀73,E11:E12,E15:E16,E34:E36,E38:E39,E42,E47,E49,E51,E57,E59:E61,F3,F11,F18,F20,F33,F66:F73,G34:G36,G38:G39,G42,H24:H44,H47,H49,H51,H54:H61,H64:H73").Locked = False
.Protect Password:="toto"
Next Sh---ZONE D'ERREUR
With Sheets("feuille2")
.Unprotect Password:="toto"
.Cells.Locked = True
.Range("B4:B5,B8,B25:B46,B56,C31,D4,D8,D11😀16,D20,D22,D29😀30,D34,D41😀43,D49,D51,D53,E11:E12,,F4,F11:F12,F22,F29:F30,F34,F43,F56,G25:G46,G49,G51,G53").Locked = False
.Protect Password:="toto"
End With
End Sub