IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Macros et VBA Excel Discussion :

Boucle For / Next


Sujet :

Macros et VBA Excel

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Homme Profil pro
    employé
    Inscrit en
    Septembre 2015
    Messages
    43
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 33
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : employé

    Informations forums :
    Inscription : Septembre 2015
    Messages : 43
    Par défaut Boucle For / Next
    Bonjour à tous,

    Aujourd'hui je bloque sur une boucle ou il y a un IF, ci dessous un extrait du code qui est dans ma boucle.

    Je m'explique je boucle sur différences cellules et en fonction du résultat il faudrait que ça incrémente la première cellule vide de cette même ligne mais je n'arrive pas à voir comment faire

    Si l'un de vous peux m'éclairer ce serait gentil.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
            If Cells(l, 3) > 0 And Cells(l, 3) > Cells(l, 5) And Cells(l, 3) > Cells(l, 7) And Cells(l, 3) > Cells(l, 9) And Cells(l, 3) > Cells(l, 11) And Cells(l, 3) > Cells(l, 13) And Cells(l, 3) > Cells(l, 15) And Cells(l, 3) > Cells(l, 17) And Cells(l, 3) > Cells(l, 19) And Cells(l, 3) > Cells(l, 21) And Cells(l, 22) <> Cells(l, 2) And Left(Cells(l, 2).Value, 3) <> Left(Cells(l, 22).Value, 3) Then
            Cells(l, 23) = Cells(l, 2)
            End If
     
            If Cells(l, 5) > 0 And Cells(l, 22) <> Cells(l, 4) And Cells(l, 23) <> Cells(l, 4) And _
            Left(Cells(l, 4).Value, 3) <> Left(Cells(l, 22).Value, 3) And Left(Cells(l, 4).Value, 3) <> Left(Cells(l, 24).Value, 3) Then
            Cells(l, 24) = Cells(l, 4)
            End If

  2. #2
    Expert éminent Avatar de Menhir
    Homme Profil pro
    Ingénieur
    Inscrit en
    Juin 2007
    Messages
    16 037
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Finistère (Bretagne)

    Informations professionnelles :
    Activité : Ingénieur
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2007
    Messages : 16 037
    Par défaut
    Je ne comprends pas ta question.
    Dans le code que tu présentes, quelle cellule doit être incrémentée ?

  3. #3
    Inactif  

    Homme Profil pro
    cuisiniste
    Inscrit en
    Avril 2009
    Messages
    15 374
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Var (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : cuisiniste
    Secteur : Bâtiment

    Informations forums :
    Inscription : Avril 2009
    Messages : 15 374
    Billets dans le blog
    8
    Par défaut re
    bonjour
    je pense que tu parle de ta colonne 24

    comme nous avons pas tout le code de la boucle c'est difficile de deviner

    dans ta boucle remplace le "1" par la variable d'incrémentation de for

    sinon le reste du code m'a l'air correct je n'ai pas pu tester bien que peut être simplifié je pense
    mes fichiers dans les contributions:
    mail avec CDO en vba et mail avec CDO en vbs dans un HTA
    survol des bouton dans userform
    prendre un cliché d'un range

    si ton problème est résolu n'oublie pas de pointer : : ça peut servir aux autres
    et n'oublie pas de voter

  4. #4
    Membre averti
    Homme Profil pro
    employé
    Inscrit en
    Septembre 2015
    Messages
    43
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 33
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : employé

    Informations forums :
    Inscription : Septembre 2015
    Messages : 43
    Par défaut
    oui excuse moi c'est bien mon 23, 24, etc qui représente ma colonne mon "L" quand t'a lui et correspond à ma ligne.

    que veux tu dire par "dans ta boucle remplace le "1" par la variable d'incrémentation de for "?

  5. #5
    Membre confirmé
    Profil pro
    Administration et finances
    Inscrit en
    Mai 2012
    Messages
    19
    Détails du profil
    Informations personnelles :
    Localisation : Algérie

    Informations professionnelles :
    Activité : Administration et finances
    Secteur : Bâtiment

    Informations forums :
    Inscription : Mai 2012
    Messages : 19
    Par défaut
    Bonsoir matthieu69,
    Pour le premier test, on peut utiliser une boucle For...Next en introduisant une variable booléenne pour sortir de la boucle quand la condition Cells(1,3)>Cells(1, x) ne se vérifie pas. Voici un bout de code (qui ne fait rien de plus que le votre):
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    If Cells(1, 3) > 0 And Cells(l, 22) <> Cells(l, 2) And Left(Cells(l, 2).Value, 3) <> Left(Cells(l, 22).Value, 3) Then
        Dim i As Integer, bSup As Boolean
        For i = 5 To 21 Step 2
            bSup = (Cells(1, 3) > Cells(1, i))
            If bSup = False Then Exit For
        Next
        If bSup = True Then Cells(1, 23) = Cells(1, 2)
    End If

  6. #6
    Membre averti
    Homme Profil pro
    employé
    Inscrit en
    Septembre 2015
    Messages
    43
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 33
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : employé

    Informations forums :
    Inscription : Septembre 2015
    Messages : 43
    Par défaut
    je reviens vers vous car je n'y arrive pas , je n'arrive pas à partir des ******* il faudrait que si me IF et juste il incrémente la première cellule de cette même ligne.

    Etant débutant je pense que le code et surement long et peut surement etre simplifier, mais soyez indulgent

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    Private Sub Equivalence()
     
    Application.ScreenUpdating = False
     
    Dim nbl As Long, nbc As Long
     
    nbl = Sheets("Test").Cells(Rows.Count, 1).End(xlUp).Row
    nbc = Sheets("Test").Cells(1, Cells.Columns.Count).End(xlToLeft).Column
     
    For l = 3 To nbl
     
            If Cells(l, 3) > Cells(l, 5) And Cells(l, 3) > Cells(l, 7) And Cells(l, 3) > Cells(l, 9) And Cells(l, 3) > Cells(l, 11) And Cells(l, 3) > Cells(l, 13) And Cells(l, 3) > Cells(l, 15) And Cells(l, 3) > Cells(l, 17) And Cells(l, 3) > Cells(l, 19) And Cells(l, 3) > Cells(l, 21) Then
            Cells(l, 22) = Cells(l, 2)
            End If
     
            If Cells(l, 5) > Cells(l, 3) And Cells(l, 5) > Cells(l, 7) And Cells(l, 5) > Cells(l, 9) And Cells(l, 5) > Cells(l, 11) And Cells(l, 5) > Cells(l, 13) And Cells(l, 5) > Cells(l, 15) And Cells(l, 5) > Cells(l, 17) And Cells(l, 5) > Cells(l, 19) And Cells(l, 5) > Cells(l, 21) Then
            Cells(l, 22) = Cells(l, 4)
            End If
     
            If Cells(l, 7) > Cells(l, 3) And Cells(l, 7) > Cells(l, 5) And Cells(l, 7) > Cells(l, 9) And Cells(l, 7) > Cells(l, 11) And Cells(l, 7) > Cells(l, 13) And Cells(l, 7) > Cells(l, 15) And Cells(l, 7) > Cells(l, 17) And Cells(l, 7) > Cells(l, 19) And Cells(l, 7) > Cells(l, 21) Then
            Cells(l, 22) = Cells(l, 6)
            End If
     
            If Cells(l, 9) > Cells(l, 3) And Cells(l, 9) > Cells(l, 5) And Cells(l, 9) > Cells(l, 7) And Cells(l, 9) > Cells(l, 11) And Cells(l, 9) > Cells(l, 13) And Cells(l, 9) > Cells(l, 15) And Cells(l, 9) > Cells(l, 17) And Cells(l, 9) > Cells(l, 19) And Cells(l, 9) > Cells(l, 21) Then
            Cells(l, 22) = Cells(l, 8)
            End If
     
            If Cells(l, 11) > Cells(l, 3) And Cells(l, 11) > Cells(l, 5) And Cells(l, 11) > Cells(l, 7) And Cells(l, 11) > Cells(l, 9) And Cells(l, 11) > Cells(l, 13) And Cells(l, 11) > Cells(l, 15) And Cells(l, 11) > Cells(l, 17) And Cells(l, 11) > Cells(l, 19) And Cells(l, 11) > Cells(l, 21) Then
            Cells(l, 22) = Cells(l, 10)
            End If
     
            If Cells(l, 13) > Cells(l, 3) And Cells(l, 13) > Cells(l, 5) And Cells(l, 13) > Cells(l, 7) And Cells(l, 13) > Cells(l, 9) And Cells(l, 13) > Cells(l, 11) And Cells(l, 13) > Cells(l, 15) And Cells(l, 13) > Cells(l, 17) And Cells(l, 13) > Cells(l, 19) And Cells(l, 13) > Cells(l, 21) Then
            Cells(l, 22) = Cells(l, 12)
            End If
     
            If Cells(l, 15) > Cells(l, 3) And Cells(l, 15) > Cells(l, 5) And Cells(l, 15) > Cells(l, 7) And Cells(l, 15) > Cells(l, 9) And Cells(l, 15) > Cells(l, 11) And Cells(l, 15) > Cells(l, 13) And Cells(l, 15) > Cells(l, 17) And Cells(l, 15) > Cells(l, 19) And Cells(l, 15) > Cells(l, 21) Then
            Cells(l, 22) = Cells(l, 14)
            End If
     
            If Cells(l, 17) > Cells(l, 3) And Cells(l, 17) > Cells(l, 5) And Cells(l, 17) > Cells(l, 7) And Cells(l, 17) > Cells(l, 9) And Cells(l, 17) > Cells(l, 11) And Cells(l, 17) > Cells(l, 13) And Cells(l, 17) > Cells(l, 15) And Cells(l, 17) > Cells(l, 19) And Cells(l, 17) > Cells(l, 21) Then
            Cells(l, 22) = Cells(l, 16)
            End If
     
            If Cells(l, 19) > Cells(l, 3) And Cells(l, 19) > Cells(l, 5) And Cells(l, 19) > Cells(l, 7) And Cells(l, 19) > Cells(l, 9) And Cells(l, 9) > Cells(l, 11) And Cells(l, 19) > Cells(l, 13) And Cells(l, 19) > Cells(l, 15) And Cells(l, 19) > Cells(l, 17) And Cells(l, 19) > Cells(l, 21) Then
            Cells(l, 22) = Cells(l, 18)
            End If
     
            If Cells(l, 21) > Cells(l, 3) And Cells(l, 21) > Cells(l, 5) And Cells(l, 21) > Cells(l, 7) And Cells(l, 21) > Cells(l, 9) And Cells(l, 21) > Cells(l, 11) And Cells(l, 21) > Cells(l, 13) And Cells(l, 21) > Cells(l, 15) And Cells(l, 21) > Cells(l, 17) And Cells(l, 21) > Cells(l, 19) Then
            Cells(l, 22) = Cells(l, 20)
            End If
     
    '***********************************************************************************************************************************'
     
            If Cells(l, 3) > 0 And Cells(l, 3) > Cells(l, 5) And Cells(l, 3) > Cells(l, 7) And Cells(l, 3) > Cells(l, 9) And Cells(l, 3) > Cells(l, 11) And Cells(l, 3) > Cells(l, 13) And Cells(l, 3) > Cells(l, 15) And Cells(l, 3) > Cells(l, 17) And Cells(l, 3) > Cells(l, 19) And Cells(l, 3) > Cells(l, 21) And Cells(l, 22) <> Cells(l, 2) And Left(Cells(l, 2).Value, 3) <> Left(Cells(l, 22).Value, 3) Then
            Cells(l, 23) = Cells(l, 2)
            End If
     
            If Cells(l, 5) > 0 And Cells(l, 22) <> Cells(l, 4) And Cells(l, 23) <> Cells(l, 4) And _
            Left(Cells(l, 4).Value, 3) <> Left(Cells(l, 22).Value, 3) And Left(Cells(l, 4).Value, 3) <> Left(Cells(l, 24).Value, 3) Then
            Cells(l, 24) = Cells(l, 4)
            End If
     
            If Cells(l, 7) > 0 And Cells(l, 22) <> Cells(l, 6) And Cells(l, 23) <> Cells(l, 6) And Cells(l, 24) <> Cells(l, 6) And _
            Left(Cells(l, 6).Value, 3) <> Left(Cells(l, 22).Value, 3) And Left(Cells(l, 6).Value, 3) <> Left(Cells(l, 23).Value, 3) And Left(Cells(l, 6).Value, 3) <> Left(Cells(l, 25).Value, 3) Then
            Cells(l, 25) = Cells(l, 6)
            End If
     
            If Cells(l, 9) > 0 And Cells(l, 22) <> Cells(l, 8) And Cells(l, 23) <> Cells(l, 8) And Cells(l, 24) <> Cells(l, 8) And Cells(l, 25) <> Cells(l, 8) And _
            Left(Cells(l, 8).Value, 3) <> Left(Cells(l, 22).Value, 3) And Left(Cells(l, 8).Value, 3) <> Left(Cells(l, 23).Value, 3) And Left(Cells(l, 8).Value, 3) <> Left(Cells(l, 25).Value, 3) And Left(Cells(l, 8).Value, 3) <> Left(Cells(l, 26).Value, 3) Then
            Cells(l, 26) = Cells(l, 8)
            End If
     
            If Cells(l, 11) > 0 And Cells(l, 22) <> Cells(l, 10) And Cells(l, 23) <> Cells(l, 10) And Cells(l, 24) <> Cells(l, 10) And Cells(l, 25) <> Cells(l, 10) And Cells(l, 26) <> Cells(l, 10) And _
            Left(Cells(l, 10).Value, 3) <> Left(Cells(l, 22).Value, 3) And Left(Cells(l, 10).Value, 3) <> Left(Cells(l, 23).Value, 3) And Left(Cells(l, 10).Value, 3) <> Left(Cells(l, 25).Value, 3) And Left(Cells(l, 10).Value, 3) <> Left(Cells(l, 26).Value, 3) And Left(Cells(l, 10).Value, 3) <> Left(Cells(l, 27).Value, 3) Then
            Cells(l, 27) = Cells(l, 10)
            End If
     
            If Cells(l, 13) > 0 And Cells(l, 22) <> Cells(l, 12) And Cells(l, 23) <> Cells(l, 12) And Cells(l, 24) <> Cells(l, 12) And Cells(l, 25) <> Cells(l, 12) And Cells(l, 26) <> Cells(l, 12) And Cells(l, 27) <> Cells(l, 12) And _
            Left(Cells(l, 12).Value, 3) <> Left(Cells(l, 22).Value, 3) And Left(Cells(l, 12).Value, 3) <> Left(Cells(l, 23).Value, 3) And Left(Cells(l, 12).Value, 3) <> Left(Cells(l, 25).Value, 3) And Left(Cells(l, 12).Value, 3) <> Left(Cells(l, 26).Value, 3) And Left(Cells(l, 12).Value, 3) <> Left(Cells(l, 27).Value, 3) And Left(Cells(l, 12).Value, 3) <> Left(Cells(l, 28).Value, 3) Then
            Cells(l, 28) = Cells(l, 12)
            End If
     
            If Cells(l, 15) > 0 And Cells(l, 22) <> Cells(l, 14) And Cells(l, 23) <> Cells(l, 14) And Cells(l, 24) <> Cells(l, 14) And Cells(l, 25) <> Cells(l, 14) And Cells(l, 26) <> Cells(l, 14) And Cells(l, 27) <> Cells(l, 14) And Cells(l, 28) <> Cells(l, 14) And _
            (Left(Cells(l, 14).Value, 3) <> Left(Cells(l, 22).Value, 3) And Left(Cells(l, 14).Value, 3) <> Left(Cells(l, 23).Value, 3) And Left(Cells(l, 14).Value, 3) <> Left(Cells(l, 25).Value, 3) And Left(Cells(l, 14).Value, 3) <> Left(Cells(l, 26).Value, 3) And Left(Cells(l, 14).Value, 3) <> Left(Cells(l, 27).Value, 3) And Left(Cells(l, 14).Value, 3) <> Left(Cells(l, 28).Value, 3) And Left(Cells(l, 14).Value, 3) <> Left(Cells(l, 29).Value, 3)) Then
            Cells(l, 29) = Cells(l, 14)
            End If
     
            If Cells(l, 17) > 0 And Cells(l, 22) <> Cells(l, 16) And Cells(l, 23) <> Cells(l, 16) And Cells(l, 24) <> Cells(l, 16) And Cells(l, 25) <> Cells(l, 16) And Cells(l, 26) <> Cells(l, 16) And Cells(l, 27) <> Cells(l, 16) And Cells(l, 28) <> Cells(l, 16) And Cells(l, 29) <> Cells(l, 16) And _
            (Left(Cells(l, 16).Value, 3) <> Left(Cells(l, 22).Value, 3) And Left(Cells(l, 16).Value, 3) <> Left(Cells(l, 23).Value, 3) And Left(Cells(l, 16).Value, 3) <> Left(Cells(l, 25).Value, 3) And Left(Cells(l, 16).Value, 3) <> Left(Cells(l, 26).Value, 3) And Left(Cells(l, 16).Value, 3) <> Left(Cells(l, 27).Value, 3) And Left(Cells(l, 16).Value, 3) <> Left(Cells(l, 28).Value, 3) And Left(Cells(l, 16).Value, 3) <> Left(Cells(l, 29).Value, 3) And Left(Cells(l, 16).Value, 3) <> Left(Cells(l, 30).Value, 3)) Then
            Cells(l, 30) = Cells(l, 16)
            End If
     
            If Cells(l, 19) > 0 And Cells(l, 22) <> Cells(l, 18) And Cells(l, 23) <> Cells(l, 18) And Cells(l, 24) <> Cells(l, 18) And Cells(l, 25) <> Cells(l, 18) And Cells(l, 26) <> Cells(l, 18) And Cells(l, 27) <> Cells(l, 18) And Cells(l, 28) <> Cells(l, 18) And Cells(l, 29) <> Cells(l, 18) And Cells(l, 30) <> Cells(l, 18) And _
            (Left(Cells(l, 18).Value, 3) <> Left(Cells(l, 22).Value, 3) And Left(Cells(l, 18).Value, 3) <> Left(Cells(l, 23).Value, 3) And Left(Cells(l, 18).Value, 3) <> Left(Cells(l, 25).Value, 3) And Left(Cells(l, 18).Value, 3) <> Left(Cells(l, 26).Value, 3) And Left(Cells(l, 18).Value, 3) <> Left(Cells(l, 27).Value, 3) And Left(Cells(l, 18).Value, 3) <> Left(Cells(l, 28).Value, 3) And Left(Cells(l, 18).Value, 3) <> Left(Cells(l, 29).Value, 3) And Left(Cells(l, 18).Value, 3) <> Left(Cells(l, 30).Value, 3) And Left(Cells(l, 18).Value, 3) <> Left(Cells(l, 31).Value, 3)) Then
            Cells(l, 31) = Cells(l, 18)
            End If
     
            If Cells(l, 21) > 0 And Cells(l, 22) <> Cells(l, 20) And Cells(l, 23) <> Cells(l, 20) And Cells(l, 24) <> Cells(l, 20) And Cells(l, 25) <> Cells(l, 20) And Cells(l, 26) <> Cells(l, 20) And Cells(l, 27) <> Cells(l, 20) And Cells(l, 28) <> Cells(l, 20) And Cells(l, 29) <> Cells(l, 20) And Cells(l, 30) <> Cells(l, 20) And Cells(l, 31) <> Cells(l, 20) And _
            (Left(Cells(l, 20).Value, 3) <> Left(Cells(l, 22).Value, 3) And Left(Cells(l, 20).Value, 3) <> Left(Cells(l, 23).Value, 3) And Left(Cells(l, 20).Value, 3) <> Left(Cells(l, 25).Value, 3) And Left(Cells(l, 20).Value, 3) <> Left(Cells(l, 26).Value, 3) And Left(Cells(l, 20).Value, 3) <> Left(Cells(l, 27).Value, 3) And Left(Cells(l, 20).Value, 3) <> Left(Cells(l, 28).Value, 3) And Left(Cells(l, 20).Value, 3) <> Left(Cells(l, 29).Value, 3) And Left(Cells(l, 20).Value, 3) <> Left(Cells(l, 30).Value, 3) And Left(Cells(l, 20).Value, 3) <> Left(Cells(l, 31).Value, 3) And Left(Cells(l, 20).Value, 3) <> Left(Cells(l, 32).Value, 3)) Then
            Cells(l, 32) = Cells(l, 20)
            End If

Discussions similaires

  1. les boucles for..next
    Par dispa dans le forum Windows Forms
    Réponses: 3
    Dernier message: 27/06/2007, 14h23
  2. boucle for next ? peut être mais comment
    Par caro2552 dans le forum VBA Access
    Réponses: 11
    Dernier message: 07/02/2007, 20h26
  3. [VB.net] Boucle for next avec un tableau
    Par grand_prophete dans le forum Windows Forms
    Réponses: 4
    Dernier message: 31/05/2006, 11h08
  4. [VB6] Problème contrôle Timer et boucle For-Next ...
    Par Stéphane BEHMENBURG dans le forum VB 6 et antérieur
    Réponses: 6
    Dernier message: 01/12/2005, 17h36
  5. Réponses: 3
    Dernier message: 03/11/2005, 19h22

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo