Private Sub CommandButton1_Click() 'dans cet exemple, l'utilisateur va vérrouiller la cellule A1 puis protéger la feuille, en choisissant sont mot de passe Dim mptdepasse As String motdepasse = InputBox("entrer votre mot de passe") With ActiveSheet With .Cells .Locked = False .FormulaHidden = False End With With .Range("A1") .Locked = True .FormulaHidden = False End With .Protect DrawingObjects:=True, Contents:=True, Scenarios:=True, Password:=motdepasse End With End Sub Private Sub CommandButton2_Click() 'dans cet exemple, l'utilisateur va déprotéger la feuille, en choisissant sont mot de passe 'puis déverrouiller la cellule A1 Dim mptdepasse As String motdepasse = InputBox("entrer votre mot de passe") With ActiveSheet .Unprotect Password:=motdepasse With .Range("A1") .Locked = False .FormulaHidden = False End With ' et si tu veux reprotéger la feuille (si par exemple d'autres cellules que A1 doivent rester verrouillées With .Cells .Locked = False .FormulaHidden = False End With End With End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range) Dim Immuable As Variant Dim Rep Dim PasTouche As Range If Target.Address = "$A$1" Then Rep = InputBox("Entrez le mot de passe", "Mot de passe", "monmotdepasse") If Rep = "zaza" Then 'c'est bon Else Set PasTouche = Cells(1, 1) Immuable = PasTouche.Value If Not Application.Intersect(Target, PasTouche) Is Nothing Then: PasTouche.Value = Immuable: Cells(1, 2).Select Set PasTouche = Nothing End If End If End Sub
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionCells.Select Selection.Locked = False Selection.FormulaHidden = False Range("C9").Select Selection.Locked = True Selection.FormulaHidden = False ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True, Password:="toto"
With ActiveSheet With .Cells .Locked = False .FormulaHidden = False End With With .Range("C9") .Locked = True .FormulaHidden = False End With .Protect DrawingObjects:=True, Contents:=True, Scenarios:=True, Password:="toto" End With
mais ce ne marche pas