XL 2016 Msgbox

pascalpetanque

XLDnaute Nouveau
Bonsoir et Bonne Année :)

Lorsque le chiffre en a2 est impair le message s'affiche c'est normal, mais quand je clic sur une autre cellule le message réapparait comment éviter cela ?
Merci

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Range("A2") Mod 2 <> 0 Then
MsgBox " blablabla", vbOKOnly

End If
End Sub
 

JM27

XLDnaute Barbatruc
bonsoir
VB:
Private Sub Worksheet_Change(ByVal Target As Range)
     If Not Intersect([A2], Target) Is Nothing And Target.Count = 1 Then
        If Target Mod 2 <> 0 Then
            MsgBox " ok"
        End If
    End If
End Sub

ou
évènement différent en fonction de ce que tu souhaites faire

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Not Intersect([A2], Target) Is Nothing And Target.Count = 1 Then
        If Target Mod 2 <> 0 Then
            MsgBox " ok"
        End If
    End If
End Sub
 
Dernière édition:

Staple1600

XLDnaute Barbatruc
Bonsoir le fil

Une variante
(ca pourrait servir, donc je publie)
VB:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$A$2" Then
MsgBox IIf([A2] Mod 2, "Impair", "Pair"), IIf([A2] Mod 2, 48, 16), "Parité"
End If
End Sub
 

Discussions similaires

Statistiques des forums

Discussions
312 305
Messages
2 087 088
Membres
103 461
dernier inscrit
dams94