VBA Excel 2007 : Boucle IF avec AND et OR

Résolu/Fermé
Jodko - 15 mars 2012 à 15:38
 Mohamed Amine - 29 mai 2014 à 10:35
Bonjour,

Je suis confronté à un léger problème dans une boucle IF :

Le besoin :

SI :

condition 1 remplie
ET
condition 2 remplie
ET
(condition 3 remplie OU condition 4 remplie)
ET
condition 5 remplie

ALORS ...



Voila mon code :






                                If .Range("M" & i).Value = "Ouvert" And _
                                    .Range("H" & i).Value <> "Test" And _
                                    .Range("I" & i).Value = "" Or _
                                    .Range("G" & i).Value = "" And _
                                    .Range("L" & i).Value = "" _
                                Then
                                    .Range("A" & i & ":S" & i).Copy Nv_Classeur_Extract.ActiveSheet.Range("A" & j)
                                    j = j + 1
                                    k = k + 1
                                Else
                                End If


Et mon problème c'est que le résultat constaté est :

SI

condition 1 remplie ET condition 2 remplie ET condition 3 remplie
OU
condition 4 remplie ET condition 5 remplie

ALORS ...

Quelqu'un peut il m'aider SVP ?

Merci !


Jodko.

3 réponses

chossette9 Messages postés 4239 Date d'inscription lundi 20 avril 2009 Statut Contributeur Dernière intervention 12 septembre 2014 1 305
15 mars 2012 à 16:06
Bonjour,

il suffit de faire comme tu as expliqué, mettre des parenthèses autour des conditions 3 et 4. soit :
   If .Range("M" & i).Value = "Ouvert" And _
                                    .Range("H" & i).Value <> "Test" And _
                                    ( .Range("I" & i).Value = "" Or _
                                    .Range("G" & i).Value = ""  ) And _
                                    .Range("L" & i).Value = "" _

Cordialement.
11
Mohamed Amine
29 mai 2014 à 10:35
SI(AND(condition1;condition2);valeur si vrai;valeur si faux)
SI(OU(Condition1;condition2);valeur si vrai;valeur si faux)
4
Merci, j'y croyais tellement pas que j'ai même pas essayé !

Merci !


Jodko.
0