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 :

Syntax error IF AND IF THEN AND AND


Sujet :

Macros et VBA Excel

  1. #1
    Membre averti
    Femme Profil pro
    Consultant fonctionnel
    Inscrit en
    Septembre 2013
    Messages
    25
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France

    Informations professionnelles :
    Activité : Consultant fonctionnel
    Secteur : Aéronautique - Marine - Espace - Armement

    Informations forums :
    Inscription : Septembre 2013
    Messages : 25
    Par défaut Syntax error IF AND IF THEN AND AND
    Bonjour,

    Je rencontre le message d'erreur "syntax error" pour le code suivant :

    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
    Sub Macro1()
    Dim i, j As Integer
     
    For i = 2 To 5295
    For j = 2 To 359
     
    If Sheets("SCL").Cells(i, 2).Value = Sheets("Feuil1).Cells(j, 2).Value And
    Sheets("SCL").Cells(i, 64).Value = Sheets("Feuil1").Cells(j, 18).Value Then
    Sheets("SCL").Cells(i, 70).Value = Sheets("Feuil1").Cells(i, 20).Value And
    Sheets("SCL").Cells(i, 35).Value = Sheets("Feuil1").Cells(i, 24).Value And
    Sheets("SCL").Cells(i, 36).Value = Sheets("Feuil1").Cells(i, 25).Value And
    Sheets("SCL").Cells(i, 37).Value = Sheets("Feuil1").Cells(i, 26).Value And
     
    Sheets("SCL").Cells(i, 40).Value = Sheets("Feuil1").Cells(i, 27).Value And
    Sheets("SCL").Cells(i, 41).Value = Sheets("Feuil1").Cells(i, 28).Value And
    Sheets("SCL").Cells(i, 42).Value = Sheets("Feuil1").Cells(i, 29).Value And
     
    Sheets("SCL").Cells(i, 44).Value = Sheets("Feuil1").Cells(i, 30).Value And
    Sheets("SCL").Cells(i, 45).Value = Sheets("Feuil1").Cells(i, 31).Value And
    Sheets("SCL").Cells(i, 46).Value = Sheets("Feuil1").Cells(i, 32).Value And
     
    Sheets("SCL").Cells(i, 47).Value = Sheets("Feuil1").Cells(i, 33).Value And
    Sheets("SCL").Cells(i, 48).Value = Sheets("Feuil1").Cells(i, 34).Value And
    Sheets("SCL").Cells(i, 49).Value = Sheets("Feuil1").Cells(i, 35).Value And
     
    Sheets("SCL").Cells(i, 58).Value = Sheets("Feuil1").Cells(i, 36).Value And
    Sheets("SCL").Cells(i, 59).Value = Sheets("Feuil1").Cells(i, 37).Value And
    Sheets("SCL").Cells(i, 60).Value = Sheets("Feuil1").Cells(i, 38).Value And
     
    Rows("i:i").Select
        With Selection.Interior
            .Pattern = xlSolid
            .PatternColorIndex = xlAutomatic
            .Color = 255
            .TintAndShade = 0
            .PatternTintAndShade = 0
        End With
    End If
     
    Next j
    Next i
    End Sub
    Pouvez-vous m'aider sur la syntaxe svp ?

    Merci bien,

  2. #2
    Invité
    Invité(e)
    Par défaut
    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
    Sub Macro1()
    Dim i, j As Integer
     
    For i = 2 To 5295
    For j = 2 To 359
     
    If Sheets("SCL").Cells(i, 2).Value = Sheets("Feuil1").Cells(j, 2).Value And _
    Sheets("SCL").Cells(i, 64).Value = Sheets("Feuil1").Cells(j, 18).Value And _
    Sheets("SCL").Cells(i, 70).Value = Sheets("Feuil1").Cells(i, 20).Value And _
    Sheets("SCL").Cells(i, 35).Value = Sheets("Feuil1").Cells(i, 24).Value And _
    Sheets("SCL").Cells(i, 36).Value = Sheets("Feuil1").Cells(i, 25).Value And _
    Sheets("SCL").Cells(i, 37).Value = Sheets("Feuil1").Cells(i, 26).Value And _
    Sheets("SCL").Cells(i, 40).Value = Sheets("Feuil1").Cells(i, 27).Value And _
    Sheets("SCL").Cells(i, 41).Value = Sheets("Feuil1").Cells(i, 28).Value And _
    Sheets("SCL").Cells(i, 42).Value = Sheets("Feuil1").Cells(i, 29).Value And _
    Sheets("SCL").Cells(i, 44).Value = Sheets("Feuil1").Cells(i, 30).Value And _
    Sheets("SCL").Cells(i, 45).Value = Sheets("Feuil1").Cells(i, 31).Value And _
    Sheets("SCL").Cells(i, 46).Value = Sheets("Feuil1").Cells(i, 32).Value And _
    Sheets("SCL").Cells(i, 47).Value = Sheets("Feuil1").Cells(i, 33).Value And _
    Sheets("SCL").Cells(i, 48).Value = Sheets("Feuil1").Cells(i, 34).Value And _
    Sheets("SCL").Cells(i, 49).Value = Sheets("Feuil1").Cells(i, 35).Value And _
    Sheets("SCL").Cells(i, 58).Value = Sheets("Feuil1").Cells(i, 36).Value And _
    Sheets("SCL").Cells(i, 59).Value = Sheets("Feuil1").Cells(i, 37).Value And _
    Sheets("SCL").Cells(i, 60).Value = Sheets("Feuil1").Cells(i, 38).Value Then
     
    Rows("i:i").Select
        With Selection.Interior
            .Pattern = xlSolid
            .PatternColorIndex = xlAutomatic
            .Color = 255
            .TintAndShade = 0
            .PatternTintAndShade = 0
        End With
    End If
     
    Next j
    Next i
    End If
    End Sub

  3. #3
    Membre averti
    Femme Profil pro
    Consultant fonctionnel
    Inscrit en
    Septembre 2013
    Messages
    25
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France

    Informations professionnelles :
    Activité : Consultant fonctionnel
    Secteur : Aéronautique - Marine - Espace - Armement

    Informations forums :
    Inscription : Septembre 2013
    Messages : 25
    Par défaut
    rdurupt,

    Tu as changé ce que je voulais faire :

    Je veux remplacer les valeurs de 16 colonnes et ensuite les surligner en rouge pour voir les colonnes dont les valeurs ont changé.

    Il faut mettre le Then après les deux premières conditions If.

  4. #4
    Inactif  
    Homme Profil pro
    Inscrit en
    Septembre 2012
    Messages
    1 733
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations forums :
    Inscription : Septembre 2012
    Messages : 1 733
    Par défaut
    Ton code c'est n'importe quoi....

    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
    Sub Macro1()
    Dim i, j As Integer
     
    For i = 2 To 5295
    For j = 2 To 359
     
    If Sheets("SCL").Cells(i, 2).Value = Sheets("Feuil1").Cells(j, 2).Value And Sheets("SCL").Cells(i, 64).Value = Sheets("Feuil1").Cells(j, 18).Value Then
        Sheets("SCL").Cells(i, 70).Value = Sheets("Feuil1").Cells(i, 20).Value
        Sheets("SCL").Cells(i, 35).Value = Sheets("Feuil1").Cells(i, 24).Value
        Sheets("SCL").Cells(i, 36).Value = Sheets("Feuil1").Cells(i, 25).Value
        Sheets("SCL").Cells(i, 37).Value = Sheets("Feuil1").Cells(i, 26).Value
        Sheets("SCL").Cells(i, 40).Value = Sheets("Feuil1").Cells(i, 27).Value
        Sheets("SCL").Cells(i, 41).Value = Sheets("Feuil1").Cells(i, 28).Value
        Sheets("SCL").Cells(i, 42).Value = Sheets("Feuil1").Cells(i, 29).Value
        Sheets("SCL").Cells(i, 44).Value = Sheets("Feuil1").Cells(i, 30).Value
        Sheets("SCL").Cells(i, 45).Value = Sheets("Feuil1").Cells(i, 31).Value
        Sheets("SCL").Cells(i, 46).Value = Sheets("Feuil1").Cells(i, 32).Value
        Sheets("SCL").Cells(i, 47).Value = Sheets("Feuil1").Cells(i, 33).Value
        Sheets("SCL").Cells(i, 48).Value = Sheets("Feuil1").Cells(i, 34).Value
        Sheets("SCL").Cells(i, 49).Value = Sheets("Feuil1").Cells(i, 35).Value
        Sheets("SCL").Cells(i, 58).Value = Sheets("Feuil1").Cells(i, 36).Value
        Sheets("SCL").Cells(i, 59).Value = Sheets("Feuil1").Cells(i, 37).Value
        Sheets("SCL").Cells(i, 60).Value = Sheets("Feuil1").Cells(i, 38).Value
     
        Rows("i:i").Select
        With Selection.Interior
            .Pattern = xlSolid
            .PatternColorIndex = xlAutomatic
            .Color = 255
            .TintAndShade = 0
            .PatternTintAndShade = 0
        End With
    End If
     
    Next j
    Next i
    End Sub

  5. #5
    Invité
    Invité(e)
    Par défaut
    Citation Envoyé par Daniela_ Voir le message
    rdurupt,

    Tu as changé ce que je voulais faire :

    Je veux remplacer les valeurs de 16 colonnes et ensuite les surligner en rouge pour voir les colonnes dont les valeurs ont changé.

    Il faut mettre le Then après les deux premières conditions If.
    ce n'est pas improbable

  6. #6
    Membre averti
    Femme Profil pro
    Consultant fonctionnel
    Inscrit en
    Septembre 2013
    Messages
    25
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France

    Informations professionnelles :
    Activité : Consultant fonctionnel
    Secteur : Aéronautique - Marine - Espace - Armement

    Informations forums :
    Inscription : Septembre 2013
    Messages : 25
    Par défaut
    En fait j'avais oublié le " sur la première ligne...

    Pourquoi c'est n'importe quoi ?

  7. #7
    Inactif  
    Homme Profil pro
    Inscrit en
    Septembre 2012
    Messages
    1 733
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations forums :
    Inscription : Septembre 2012
    Messages : 1 733
    Par défaut
    parce que tu mets des and à la fin de chaque ligne

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Livre Cocoa and Objective C up and running
    Par Byron dans le forum XCode
    Réponses: 2
    Dernier message: 30/05/2010, 21h45
  2. if . . . then . . . ; Syntax error
    Par foolib dans le forum SQL Procédural
    Réponses: 6
    Dernier message: 25/01/2009, 12h59
  3. Passer du drag and drop -> au drag and ghost: simuler un drag
    Par Anonymouse dans le forum AWT/Swing
    Réponses: 2
    Dernier message: 22/11/2007, 04h37
  4. [FPDF] error: Image file has no extension and no type was specified:
    Par demsbf dans le forum Bibliothèques et frameworks
    Réponses: 4
    Dernier message: 28/09/2007, 15h47

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