Bonjour à tous.
J'ai un document dans lequel j'ai ajouté du VBA pour ajouter des formules automatiquement :
Private Sub Worksheet_Change(ByVal Target As Range)
On Error Resume Next
Dim Derlig As Integer
With Sheets(Target.Value)
Derlig = .Range("A65536").End(xlUp).Row + 1
.Range("A" & Derlig) = Cells(Target.Row, 2)
.Range("C" & Derlig) = Cells(3, Target.Column)
.Range("F" & Derlig).Formula = "=E" & Derlig & "-D" & Derlig
If Target = "Hs" Then
.Range("I" & Derlig).Formula = _
"=IF(A" & Derlig & "=HsIndiv!$C$14,"""",IF(OR(C" & Derlig & "<HsIndiv!$F$12,C" & Derlig & ">HsIndiv!$F$13,G" & Derlig & "<>""A payer""),"""",A" & Derlig & "))"
.Range("J" & Derlig).Formula = _
"=IF(OR(A" & Derlig & "<>HsIndiv!$C$14,C" & Derlig & "<HsIndiv!$F$12,C" & Derlig & ">HsIndiv!$F$13,G" & Derlig & "<>""A payer""),"""",MAX(J$1:J" & Derlig - 1 & ")+1)"
.Range("K" & Derlig).Formula = _
"=IF(OR(A" & Derlig & "<>Heures!$B$5,G" & Derlig & "<>""A récupérer""),"""",MAX($K$1:K" & Derlig & ")+1)"
End If
If Target = "Ré" Then
.Range("G" & Derlig).Formula = _
"=IF(A" & Derlig & "<>Heures!$B$5,"""",MAX($G1:G" & Derlig - 1 & ")+1)"
End If
.Select
End With
End Sub
Comme je ne veux pas qu'on puisse saisir dans les cases où il y a les formules, je verrouille et protège le document.
A ce moment là, bah mon code ne fonctionne plus !
Y aurait-il une solution ?