Re : valeur automatique d'une cellule et création d'un MDP
Bonsoir,
regarde un peu le fichier joint, et dis-moi si cela te convient
PS: A partir de demain, absent 2 mois pour raison professionnelle, mais je ne doute pas qu'un intervenant puisse répondre à une question éventuelle.
Dans le code évènement de feuille :
Private Sub Worksheet_Change(ByVal Target As Range)
Application.ScreenUpdating = False
Dim Rg As Range
Set Rg = Intersect(Target, Columns("C:C"))
If Not Rg Is Nothing And Target.Count = 1 Then
With ActiveSheet
If Target.Offset(0, -1) = "" Then
.Unprotect "mdp"
.Cells.Locked = False
.Columns("B:B").Locked = True
Target.Offset(0, -1) = Date
Else
Dim mdP As String, t As Byte
mdP = "mdp"
t = 0
Do
t = t + 1
anS = Application.InputBox("Il faut le mot de passe pour modifier", _
"Tentative " & t, , , , , , 1 + 2)
If anS = mdP Then
MsgBox "vous pouvez modifier"
Target.Offset(0, -1).Select
.Unprotect "mdp"
Exit Sub
End If
Loop While t < 3
End If
.Protect Password:="mdp", DrawingObjects:=False, Contents:=True, Scenarios:= _
False, AllowFormattingCells:=True, AllowFormattingColumns:=True, _
AllowFormattingRows:=True, AllowInsertingColumns:=True, AllowInsertingRows _
:=True, AllowInsertingHyperlinks:=True, AllowDeletingColumns:=True, _
AllowDeletingRows:=True, AllowSorting:=True, AllowFiltering:=True, _
AllowUsingPivotTables:=True
End With
End If
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Application.ScreenUpdating = False
Dim Rg As Range
Set Rg = Intersect(Target, Columns("B:B"))
If Not Rg Is Nothing And Target.Count = 1 Then
ActiveSheet.Protect Password:="mdp", DrawingObjects:=False, Contents:=True, Scenarios:= _
False, AllowFormattingCells:=True, AllowFormattingColumns:=True, _
AllowFormattingRows:=True, AllowInsertingColumns:=True, AllowInsertingRows _
:=True, AllowInsertingHyperlinks:=True, AllowDeletingColumns:=True, _
AllowDeletingRows:=True, AllowSorting:=True, AllowFiltering:=True, _
AllowUsingPivotTables:=True
End If
End Sub
fichier joint :