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 While Wend


Sujet :

Macros et VBA Excel

  1. #1
    Nouveau candidat au Club
    Femme Profil pro
    tehcnicien qualité
    Inscrit en
    Mars 2017
    Messages
    1
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 45
    Localisation : France, Eure et Loir (Centre)

    Informations professionnelles :
    Activité : tehcnicien qualité

    Informations forums :
    Inscription : Mars 2017
    Messages : 1
    Par défaut Boucle While Wend
    Bonjour à tous,

    Besoin d'aide pour une boucle que Excel ne veut pas.
    Savez-vous pourquoi cette bouche ne fonctionne pas?
    Il me met "erreur de compilation Wend sans while"
    Je ne comprends pas car j'ai bien un while au début....

    Merci d'avance!

    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
    finligneRFT = 24
    ligneRFT = 4
     
    While ligneRFT < finligneRFT
    INITIALE = Range("A" & ligneRFT).Value
     
    Sheets("COPIE").Select
    FinLigne = 400
    numeroligne = 3
    ERREUR = 0
     
        While numeroligne < FinLigne
    If Range("C" & numeroligne).Value = INITIALE And Range("J" & numeroligne).Value = "OK" And Range("B" & numeroligne).Value = moisanalysé Then ERREUR = ERREUR + 1
    If Range("Q" & numéroligne).Value = INITIALE And Range("J" & numeroligne).Value = "OK" And Range("B" & numeroligne).Value = moisanalysé Then ERREUR = ERREUR + 1
    numeroligne = numeroligne + 1
        Wend
     
     
    Sheets("RFT").Select
    If moisanalysé = "JANVIER" Then
    Range("O" & ligneRFT) = ERREUR
    If moisanalysé = "FEVRIER" Then
    Range("P" & ligneRFT) = ERREUR
    If moisanalysé = "MARS" Then
    Range("Q" & ligneRFT) = ERREUR
    If moisanalysé = "AVRIL" Then
    Range("R" & ligneRFT) = ERREUR
    If moisanalysé = "MAI" Then
    Range("S" & ligneRFT) = ERREUR
    If moisanalysé = "JUIN" Then
    Range("T" & ligneRFT) = ERREUR
    If moisanalysé = "JUILLET" Then
    Range("U" & ligneRFT) = ERREUR
    If moisanalysé = "AOUT" Then
    Range("V" & ligneRFT) = ERREUR
    If moisanalysé = "SEPTEMBRE" Then
    Range("W" & ligneRFT) = ERREUR
    If moisanalysé = "OCTOBRE" Then
    Range("X" & ligneRFT) = ERREUR
    If moisanalysé = "NOVEMBRE" Then
    Range("Y" & ligneRFT) = ERREUR
    If moisanalysé = "DECEMBRE" Then
    Range("Z" & ligneRFT) = ERREUR
     
    ligneRFT = ligneRFT + 1
     
    Wend

  2. #2
    Invité
    Invité(e)
    Par défaut
    Bonjour,
    Savez-vous pourquoi cette bouche ne fonctionne pas?
    Il me met "erreur de compilation Wend sans while"
    parce que ton code n'est pas indenté (en espalier) et que tu ne peux pas voir quand un If n'a pas de End IF!

    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
    Sub test()finligneRFT = 24
    ligneRFT = 4
    While ligneRFT < finligneRFT
        INITIALE = Range("A" & ligneRFT).Value
        Sheets("COPIE").Select
        FinLigne = 400
        numeroligne = 3
        ERREUR = 0
        While numeroligne < FinLigne
            If Range("C" & numeroligne).Value = INITIALE And Range("J" & numeroligne).Value = "OK" And Range("B" & numeroligne).Value = moisanalysé Then ERREUR = ERREUR + 1
            If Range("Q" & numéroligne).Value = INITIALE And Range("J" & numeroligne).Value = "OK" And Range("B" & numeroligne).Value = moisanalysé Then ERREUR = ERREUR + 1
            numeroligne = numeroligne + 1
        Wend
        Sheets("RFT").Select
        Select Case moisanalysé
            Case "JANVIER": Range("O" & ligneRFT) = ERREUR
            Case "FEVRIER": Range("P" & ligneRFT) = ERREUR
            Case "MARS": Range("Q" & ligneRFT) = ERREUR
            Case "AVRIL": Range("R" & ligneRFT) = ERREUR
            Case "MAI": Range("S" & ligneRFT) = ERREUR
            Case "JUIN": Range("T" & ligneRFT) = ERREUR
            Case "JUILLET": Range("U" & ligneRFT) = ERREUR
            Case "AOUT": Range("V" & ligneRFT) = ERREUR
            Case "SEPTEMBRE": Range("W" & ligneRFT) = ERREUR
            Case "OCTOBRE": Range("X" & ligneRFT) = ERREUR
            Case "NOVEMBRE": Range("Y" & ligneRFT) = ERREUR
            Case "DECEMBRE":  'Range("Z" & ligneRFT) = ERREUR
        End Select
        ligneRFT = ligneRFT + 1
    Wend
    End Sub
    If moisanalysé = "JANVIER" Then
    Range("O" & ligneRFT) = ERREUR
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    If moisanalysé = "JANVIER" Then
    Range("O" & ligneRFT) = ERREUR
    End IF
    'ou 
    If moisanalysé = "JANVIER" Then Range("O" & ligneRFT) = ERREUR

  3. #3
    Membre Expert
    Femme Profil pro
    Ingénieur
    Inscrit en
    Octobre 2016
    Messages
    1 703
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 30
    Localisation : France, Indre et Loire (Centre)

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

    Informations forums :
    Inscription : Octobre 2016
    Messages : 1 703
    Par défaut
    Il manque un end if après ta série de if.

    Pense à utiliser les balises code (bouton #) et à indenter ton code
    Bon courage pour la suite!

  4. #4
    Membre Expert Avatar de antonysansh
    Homme Profil pro
    Chargé d'études RH
    Inscrit en
    Mai 2014
    Messages
    1 115
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 33
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Chargé d'études RH
    Secteur : Finance

    Informations forums :
    Inscription : Mai 2014
    Messages : 1 115
    Par défaut
    Citation Envoyé par riaolle Voir le message
    Il manque un end if après ta série de if.
    Ce n'est pas exacte !
    Il manque un End If pour chaque If ou remplacer les If après le premier par Else If.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    If TestA Then
        TraitementA
    End If
    If TestB Then
        TraitementB
    End If
    Ou bien
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    If TestA Then
        TraitementA
    Else If TestB
        TraitementB
    End if

  5. #5
    Expert confirmé
    Homme Profil pro
    aucune
    Inscrit en
    Avril 2016
    Messages
    7 563
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 83
    Localisation : France, Pyrénées Atlantiques (Aquitaine)

    Informations professionnelles :
    Activité : aucune

    Informations forums :
    Inscription : Avril 2016
    Messages : 7 563
    Par défaut
    Bonjour
    J'aimerais personnellement savoir où et comment a été déclarée et initialisée la variable moisanalysé.
    Car si cela se trouve, nul besoin même d'expressions conditionnelles (ni If ni Select case) .

Discussions similaires

  1. [AC-2000] Sortir d'une boucle while wend
    Par 973thom dans le forum VBA Access
    Réponses: 2
    Dernier message: 03/09/2009, 10h14
  2. chargement du Combo Par sql boucle While wend
    Par r.mehdi dans le forum VB 6 et antérieur
    Réponses: 1
    Dernier message: 09/06/2008, 18h16
  3. Boucle While .. Wend
    Par petibonohm dans le forum Macros et VBA Excel
    Réponses: 9
    Dernier message: 21/02/2008, 16h19
  4. [VBA]Boucle While/Wend interrompue
    Par stéphane_ais2 dans le forum VBA Access
    Réponses: 6
    Dernier message: 29/03/2007, 15h05
  5. Recordset et boucle While...Wend
    Par sbeprod dans le forum Access
    Réponses: 9
    Dernier message: 24/07/2006, 16h48

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