Je reviens vers vous pour savoir si je peux avoir un message d'erreur msg box comme suit :Merci à vous deux pour vos solutions. Cela fonctionne très bien pour mon fichier.
Bonne soirée,
a26
Bonjour youky,Hello
MsgBox"Un doublon !", vbExclamation + vbRetryCancel, "ANNULATION"
ou si on veux choisir le bouton
If MsgBox("Un doublon !", vbExclamation + vbRetryCancel, "ANNULATION") = vbRetry Then Beep
Bruno
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("c6:c18", "g18:h18")) Is Nothing Then
If Target > [I3] Then
MsgBox "Attention valeur trop grande !" & vbCr & _
"Vous ne devez pas d?passer " & [I3], vbExclamation + vbRetryCancel, "ANNULATION"
Target.Value = "" 'on efface
End If
End If
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("c6:c18", "g18:h18")) Is Nothing Then
If Target > [I3] Then
Target.Select
MsgBox "Attention valeur trop grande !" & vbCr & _
"Vous ne devez pas d?passer " & [I3], vbExclamation + vbRetryCancel, "ANNULATION"
Target.Value = "" 'on efface
End If
End If
End Sub
Merci, mais tu vas me trouver pénible car si je clique sur annuler cela ne conserve pas la valeur saisie si malgré tout je désire la conserver .Voici, j'ai ajouté Target.Select avant le MsgBox
VB:Private Sub Worksheet_Change(ByVal Target As Range) If Not Intersect(Target, Range("c6:c18", "g18:h18")) Is Nothing Then If Target > [I3] Then Target.Select MsgBox "Attention valeur trop grande !" & vbCr & _ "Vous ne devez pas d?passer " & [I3], vbExclamation + vbRetryCancel, "ANNULATION" Target.Value = "" 'on efface End If End If End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("c6:c18", "g18:h18")) Is Nothing Then
If Target > [I3] Then
Target.Select
If MsgBox("Attention valeur trop grande !" & vbCr & _
"Vous ne devez pas d?passer " & [I3], vbExclamation + vbRetryCancel, "ANNULATION") = vbRetry Then Target.Value = "" 'on efface
End If
End If
End Sub
Merci, le code fonctionne parfaitement sur la copie de mon fichier original, mais sur l'original au déclenchement d'une macro une erreur 13 se produit et le débobage me souligne la ligne target > I3Voici
Code:Private Sub Worksheet_Change(ByVal Target As Range) If Not Intersect(Target, Range("c6:c18", "g18:h18")) Is Nothing Then If Target > [I3] Then Target.Select If MsgBox("Attention valeur trop grande !" & vbCr & _ "Vous ne devez pas d?passer " & [I3], vbExclamation + vbRetryCancel, "ANNULATION") = vbRetry Then Target.Value = "" 'on efface End If End If End Sub