Afficher un message d'erreur pour une macro

a26

XLDnaute Occasionnel
Bonsoir à tous,
Pouvez-vous m'aider à trouver la solution d'une macro qui m'avertirait d'un dépassement de chiffre (variable)
dans une cellule donnée.
Merci beaucoup,
a26
 

Pièces jointes

  • Valeurs.xlsm
    8.7 KB · Affichages: 31

Hieu

XLDnaute Impliqué
Salut,
Quelque chose comme ca ?

VB:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("c6:c18", "g18:h18")) Is Nothing Then
    If Target > Range("i3") Then MsgBox ("erreur")
End If
End Sub
 

Pièces jointes

  • Valeurs_v0.xlsm
    15 KB · Affichages: 30

youky(BJ)

XLDnaute Barbatruc
Bonsoir tous
Sans vba, données Validation
Bruno
upload_2018-11-6_18-12-33.png
upload_2018-11-6_18-13-23.png
 

a26

XLDnaute Occasionnel
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
Bonjour youky,
J'ai essayé d'appliquer le code que tu m'a transmis mais cela ne fonctionne pas. Peux-être que j'ai oublié quelque chose dans l'appel de la msgbox.
a26
 

Pièces jointes

  • Valeurs_v0.xlsm
    12.6 KB · Affichages: 24

youky(BJ)

XLDnaute Barbatruc
Bonjour
Voici la macro qui fonctionne.
Bruno
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
    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
 

youky(BJ)

XLDnaute Barbatruc
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
 

a26

XLDnaute Occasionnel
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
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 .
 

youky(BJ)

XLDnaute Barbatruc
Voici
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
 

a26

XLDnaute Occasionnel
Voici
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
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 > I3
 

Discussions similaires

Réponses
3
Affichages
229

Statistiques des forums

Discussions
311 730
Messages
2 081 989
Membres
101 856
dernier inscrit
Marina40