Problème avec Condition if

Bonjour

voici mon code :

For i = Cells(Rows.Count, "B").End(xlUp).Row To 6 Step -1
    val = Cells(i, 2).Value
        If val = (43 Or 44 Or 58 Or 59 Or 62 Or 89 Or 91 Or 101) Then
            Cells(i, 5).Value = val
        Else
            Cells(i, 4).Value = val
        End If
Next i

pourquoi toutes mes valeurs "val" même celles citées entre les parenthèses, sont placé dans la colonne 4 ?

Bonjour,

2 solutions !?

Dim x
    For i = Cells(Rows.Count, "B").End(xlUp).Row To 6 Step -1
        x = Cells(i, 2).Value
        If x = 43 Or x = 44 Or x = 58 Or x = 59 Or x = 62 Or x = 89 Or x = 91 Or x = 101 Then
            Cells(i, 5).Value = x
        Else
            Cells(i, 4).Value = x
        End If
    Next i
Dim x
    For i = Cells(Rows.Count, "B").End(xlUp).Row To 6 Step -1
        x = Cells(i, 2).Value
        Select Case x
            Case 43 To 44, 58 To 59, 62, 89, 91, 101:
                Cells(i, 5).Value = x
            Case Else
                Cells(i, 4).Value = x
        End Select
    Next i

Remplace Val par un autre nom (Val est une fonction VBA - risque de cafouillage !)

ok merci.

Rechercher des sujets similaires à "probleme condition"