Simplifier une macro

Bonjour,

Quelqu'un pourrait-il m'indiquer si cette macro peut être simplifiée ?

Sub DeprotegeToutesFeuillesCategories()

Application.ScreenUpdating = False

Sheets("BF").Select

ActiveSheet.Unprotect

Sheets("BG").Select

ActiveSheet.Unprotect

Sheets("MF").Select

ActiveSheet.Unprotect

Sheets("MG").Select

ActiveSheet.Unprotect

Sheets("CF").Select

ActiveSheet.Unprotect

Sheets("CG").Select

ActiveSheet.Unprotect

Sheets("JF").Select

ActiveSheet.Unprotect

Sheets("JG").Select

ActiveSheet.Unprotect

Sheets("SF").Select

ActiveSheet.Unprotect

Sheets("SG").Select

ActiveSheet.Unprotect

Sheets("V1F").Select

ActiveSheet.Unprotect

Sheets("V2F").Select

ActiveSheet.Unprotect

Sheets("V1G").Select

ActiveSheet.Unprotect

Sheets("V2G").Select

ActiveSheet.Unprotect

Sheets("Pupitre").Select

Application.ScreenUpdating = True

End Sub

Merci de votre aide

Bonjour,

Sub DeprotegeToutesFeuillesCategories()
Application.ScreenUpdating = False
      For i = 1 To Sheets.Count
         Sheets(i).UnProtect
      Next i
Application.ScreenUpdating = True
End Sub

Bonjour Mjc, bonjour le forum,

La règle d'or en VBA c'est d'éviter les Select inutiles qui ne font que ralentir le code et sont source de plantage.

le code simplifié donne :

Sub DeprotegeToutesFeuillesCategories()
Application.ScreenUpdating = False
Sheets("BF").Unprotect
Sheets("BG").Unprotect
Sheets("MF").Unprotect
Sheets("MG").Unprotect
Sheets("CF").Unprotect
Sheets("CG").Unprotect
Sheets("JF").Unprotect
Sheets("JG").Unprotect
Sheets("SF").Unprotect
Sheets("SG").Unprotect
Sheets("V1F").Unprotect
Sheets("V2F").Unprotect
Sheets("V1G").Unprotect
Sheets("V2G").Unprotect
Sheets("Pupitre").Select
Application.ScreenUpdating = True
End Sub

Toutefois on pourrait peut-être utiliser une boucle mais il nous faudrait la liste complète de tous les onglets du classeur ou leur position...

Merci beaucoup THAUTHEME et OXYDUM

Sujet soldé avec beaucoup de professionnalisme !

Vive le site

Rechercher des sujets similaires à "simplifier macro"