Réduire une condition de OR

Bonjour

Comment pourrais je réduire ce code :

With Sheets("Panne retour")
    For bcl = 1 To derL
        If Cells(bcl, 2) = 6 Or Cells(bcl, 2) = 7 Or Cells(bcl, 2) = 8 Or Cells(bcl, 2) = 9 Or _
           Cells(bcl, 2) = 10 Or Cells(bcl, 2) = 11 Or Cells(bcl, 2) = 12 Or Cells(bcl, 2) = 13 Or _
           Cells(bcl, 2) = 14 Or Cells(bcl, 2) = 15 Or Cells(bcl, 2) = 16 Or Cells(bcl, 2) = 17 Or _
           Cells(bcl, 2) = 18 Or Cells(bcl, 2) = 19 Or Cells(bcl, 2) = 20 Or Cells(bcl, 2) = 21 Or _
           Cells(bcl, 2) = 22 Or Cells(bcl, 2) = 25 Or Cells(bcl, 2) = 26 Or Cells(bcl, 2) = 27 Or _
           Cells(bcl, 2) = 28 Or Cells(bcl, 2) = 29 Or Cells(bcl, 2) = 30 Or Cells(bcl, 2) = 31 Or _
           Cells(bcl, 2) = 32 Or Cells(bcl, 2) = 33 Or Cells(bcl, 2) = 34 Or Cells(bcl, 2) = 38 Or _
           Cells(bcl, 2) = 39 Or Cells(bcl, 2) = 42 Or Cells(bcl, 2) = 44 Or Cells(bcl, 2) = 45 Or _
           Cells(bcl, 2) = 47 Or Cells(bcl, 2) = 49 Or Cells(bcl, 2) = 50 Or Cells(bcl, 2) = 51 Or _
           Cells(bcl, 2) = 52 Or Cells(bcl, 2) = 53 Or Cells(bcl, 2) = 54 Or Cells(bcl, 2) = 55 Or _
           Cells(bcl, 2) = 56 Or Cells(bcl, 2) = 57 Or Cells(bcl, 2) = 60 Or Cells(bcl, 2) = 61 Or _
           Cells(bcl, 2) = 63 Or Cells(bcl, 2) = 64 Or Cells(bcl, 2) = 65 Or Cells(bcl, 2) = 66 Or _
           Cells(bcl, 2) = 67 Or Cells(bcl, 2) = 68 Or Cells(bcl, 2) = 69 Or Cells(bcl, 2) = 70 Or _
           Cells(bcl, 2) = 71 Or Cells(bcl, 2) = 72 Or Cells(bcl, 2) = 73 Or Cells(bcl, 2) = 74 Or _
           Cells(bcl, 2) = 75 Or Cells(bcl, 2) = 76 Or Cells(bcl, 2) = 77 Or Cells(bcl, 2) = 78 Or _
           Cells(bcl, 2) = 79 Or Cells(bcl, 2) = 80 Or Cells(bcl, 2) = 81 Or Cells(bcl, 2) = 82 Or _
           Cells(bcl, 2) = 83 Or Cells(bcl, 2) = 84 Or Cells(bcl, 2) = 85 Or Cells(bcl, 2) = 86 Then
           Cells(bcl, 2).Copy
           Cells(bcl, 4).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, _
           SkipBlanks:=False, Transpose:=False

            Application.CutCopyMode = False
        End If
    Next bcl
End With

Bonjour,

en procédant comme ceci:

With Sheets("Panne retour")
    For bcl = 1 To derL
        If Cells(bcl, 2) >= 6 And Cells(bcl, 2) <= 86 And Cells(bcl, 2) \ 1 = Cells(bcl, 2) Then
           Cells(bcl, 2).Copy
           Cells(bcl, 4).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, _
           SkipBlanks:=False, Transpose:=False

            Application.CutCopyMode = False
        End If
    Next bcl
End With

Concrètement ton test revenait à dire que la valeur devait être entre un nombre entier entre 6 et 86, j'ai testé que ce la valeur se situe entre 6 et 86 avec >=6 et <=86 et pour tester que la valeur est entière j'ai vérifier si la partie entière de la valeur est égale à la valeur de base avec \1 qui retourne la partie entière du résultat contrairement à /1 qui retourne tout le résultat.

EDIT: je n'avais pas vu que des valeurs manquaient entre 6 et 86, c'est voulu?

Oui, des valeurs ne sont pas comprises

Comme on a un nombre connu de valeurs on peut passer facilement par un select case comme ceci alors:

With Sheets("Panne retour")
    For bcl = 1 To derL
        Select Case Cells(bcl, 2)
        Case 6 To 22, 25 To 34, 38, 39, 42, 44, 45, 47, 49, 50 To 57, 60, 61, 63 To 86
            If Cells(bcl, 2) \ 1 = Cells(bcl, 2) Then
                Cells(bcl, 2).Copy
                Cells(bcl, 4).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, _
                SkipBlanks:=False, Transpose:=False

                Application.CutCopyMode = False
            End If
        End Select
    Next bcl
End With

Je mettrais dans un tableau toutes les valeurs ne remplissant pas les conditions entre 6 et 86. La suite est facile.

Sub Essai()
    Dim Chaine As String
    Dim tablo() As String
    Chaine = "23-24-35-36-37-40-41-43-46-48-58-59-62"

    tablo = Split(Chaine, "-")
End Sub

Attention : 23 sera dans tablo(0) et 62 dans tablo(12)

bonjour à tous

je rejoins @Ausecour sur ce coup là

sauf que je suis pas radin mais bon puisque c'est du paste value ben.. value de l'un = value de l'autre

With Sheets("Panne retour")
    For bcl = 1 To derL
        Select Case Cells(bcl, 2)
        Case 6 To 22, 25 To 34, 38, 39, 42, 44, 45, 47, 49, 50 To 57, 60, 61, 63 To 86
            If Cells(bcl, 2) \ 1 = Cells(bcl, 2) Then
                Cells(bcl, 4).Value = Cells(bcl, 2).value
            End If
        End Select
    Next bcl
End With

bonjour à tous

je rejoins @Ausecour sur ce coup là

sauf que je suis pas radin mais bon puisque c'est du paste value ben.. value de l'un = value de l'autre

With Sheets("Panne retour")
    For bcl = 1 To derL
        Select Case Cells(bcl, 2)
        Case 6 To 22, 25 To 34, 38, 39, 42, 44, 45, 47, 49, 50 To 57, 60, 61, 63 To 86
            If Cells(bcl, 2) \ 1 = Cells(bcl, 2) Then
                Cells(bcl, 4).Value = Cells(bcl, 2).value
            End If
        End Select
    Next bcl
End With

Ah je n'avais même pas fait gaffe à la suite du code, pas fan du paste value non plus

ok merci je vais regarder la meilleur option

Rechercher des sujets similaires à "reduire condition"