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 each cell in Range(.)


Sujet :

Macros et VBA Excel

  1. #1
    Candidat au Club
    Femme Profil pro
    Assistante de pôle
    Inscrit en
    Mai 2015
    Messages
    9
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Hauts de Seine (Île de France)

    Informations professionnelles :
    Activité : Assistante de pôle

    Informations forums :
    Inscription : Mai 2015
    Messages : 9
    Points : 3
    Points
    3
    Par défaut Boucle For each cell in Range(.)
    Bonjour,

    J'ai lu cette discussion.

    J'ai le même soucis, peut-être pourriez-vous m'aider.

    Voici mon premier code qui fonctionne en boucle mais seulement pour la première valeur de cellule de ma plage
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    Sub boucle()
     
     
       For Each Cell In Sheets("Extraction").Range("C4:C107")
            If Cell.Value <> 0 Then
            Call Sub_PDF_All
     
            End If
     
       Next Cell
     
    End Sub

    Voici le code modifié suite à votre discussion :
    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
    Sub boucle()
     
       For Each Cell In Sheets("Extraction").Range("C4:C107")
                Sub_PDF_All CStr(Cell(1, 1).Value)
     
       Next Cell
     
    End Sub
     
    Sub Sub_PDF_All()
     
     autECLSession.autECLPS.SendKeys Sheets("Extraction").Range("C4:C107")
     
    Dim NbCopy As Integer
    Dim debut As Integer
    Dim fin As Integer
    Dim TamponProp As Boolean
    Dim PDFFileName As String
    Dim myPath As String
     
    myPath = ThisWorkbook.Path
     
    Application.ScreenUpdating = False
     
            Sheets("Base des paramètres").Select
            Sheets("Base des paramètres").Range(Cells(5, 2 + i), Cells(299, 2 + i)).Copy
                    Sheets("Extraction").Range("E1").PasteSpecial _
                       Paste:=xlPasteValues
     
     
                  PDFFileName = myPath & "\" & Sheets("Extraction").Range("E23").Value & " - " & Sheets("Extraction").Range("E3")
     
                If shtExtraction.Range("E187").Value = 12 And shtExtraction.Range("E19").Value = "CE" Then
                   Sheets(Array("Fiche 0", "Fiche 2", "Fiche 3", "Fiche 4", "Fiche 5", "Fiche 6", "Eval 1", "12 ans")).Select
     
                Else
     
                If shtExtraction.Range("E187").Value = 12 And shtExtraction.Range("E19").Value = "Actu." Then
                   Sheets(Array("Fiche 0", "Eval 1", "12 ans")).Select
     
                Else
     
                If shtExtraction.Range("E19").Value = "CE" Then
                   Sheets(Array("Fiche 0", "Fiche 2", "Fiche 3", "Fiche 4", "Fiche 5", "Fiche 6", "Eval 1", "Eval 2")).Select
     
                Else
     
                Sheets(Array("Fiche 0", "Eval 1", "Eval 2")).Select
     
                End If
     
                End If
     
                End If
     
                ActiveSheet.ExportAsFixedFormat _
                            Type:=xlTypePDF, _
                            Filename:=PDFFileName, _
                            Quality:=xlQualityStandard, _
                            IncludeDocProperties:=True, _
                            IgnorePrintAreas:=False, _
                            OpenAfterPublish:=False
     
     
    shtExtraction.Select
    shtExtraction.Range("E1:E299").ClearContents
    shtExtraction.Range("E2").Select
     
     
    shtExtraction.Select
    shtExtraction.Range("A1").Select
     
    Application.CutCopyMode = False
    Application.ScreenUpdating = True
     
     
    End Sub
    Mais j'ai alors une erreur de compilation au niveau de cette ligne :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
     Sub_PDF_All CStr(Cell(1, 1).Value)
    Je n'arrive pas à comprendre ce qui ne fonctionne pas. Avez-vous une idée ?

    Merci d'avance,

  2. #2
    Invité
    Invité(e)
    Par défaut
    Bonjour,
    tu déclare Sub Sub_PDF_All() !
    et en suite tu fais ça Sub_PDF_All CStr(Cell(1, 1).Value)) ?

    il est où ton paramètre?

    Sub Sub_PDF_All(Myparamètre)

  3. #3
    Candidat au Club
    Femme Profil pro
    Assistante de pôle
    Inscrit en
    Mai 2015
    Messages
    9
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Hauts de Seine (Île de France)

    Informations professionnelles :
    Activité : Assistante de pôle

    Informations forums :
    Inscription : Mai 2015
    Messages : 9
    Points : 3
    Points
    3
    Par défaut
    Merci beaucoup pour votre réponse. En effet je n'avais pas mis le paramètre, ci-dessous le code modifié. Cependant une erreur d'incompatibilité se produit au niveau de cette ligne :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    PDF_All CStr(Cell(1, 1).Value)
    Je ne comprend pas pourquoi.

    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
    Sub boucle()
     
    Actif = sheets("Extraction").Range("C4:C107")
     
       For Each Cell In Actif
                PDF_All CStr(Cell(1, 1).Value)
     
       Next Cell
     
    End Sub
     
    Sub PDF_All(Actif As String)
     
     autECLSession.autECLPS.SendKeys Actif
     
    Dim NbCopy As Integer
    Dim debut As Integer
    Dim fin As Integer
    Dim TamponProp As Boolean
    Dim PDFFileName As String
    Dim myPath As String
     
    myPath = ThisWorkbook.Path
     
    Application.ScreenUpdating = False
     
     
     
     
            sheets("Base des paramètres").Select
            sheets("Base des paramètres").Range(Cells(5, 2 + i), Cells(299, 2 + i)).Copy
                    sheets("Extraction").Range("E1").PasteSpecial _
                       Paste:=xlPasteValues
     
     
     
                  PDFFileName = myPath & "\" & sheets("Extraction").Range("E23").Value & " - " & sheets("Extraction").Range("E3")
     
     
                If shtExtraction.Range("E187").Value = 12 And shtExtraction.Range("E19").Value = "CE" Then
                   sheets(Array("Fiche 0", "Fiche 2", "Fiche 3", "Fiche 4", "Fiche 5", "Fiche 6", "Eval 1", "12 ans")).Select
     
                Else
     
                If shtExtraction.Range("E187").Value = 12 And shtExtraction.Range("E19").Value = "Actu." Then
                   sheets(Array("Fiche 0", "Eval 1", "12 ans")).Select
     
                Else
     
                If shtExtraction.Range("E19").Value = "CE" Then
                   sheets(Array("Fiche 0", "Fiche 2", "Fiche 3", "Fiche 4", "Fiche 5", "Fiche 6", "Eval 1", "Eval 2")).Select
     
                Else
     
                sheets(Array("Fiche 0", "Eval 1", "Eval 2")).Select
     
                End If
     
                End If
     
                End If
     
                ActiveSheet.ExportAsFixedFormat _
                            Type:=xlTypePDF, _
                            Filename:=PDFFileName, _
                            Quality:=xlQualityStandard, _
                            IncludeDocProperties:=True, _
                            IgnorePrintAreas:=False, _
                            OpenAfterPublish:=False
     
     
     
    shtExtraction.Select
    shtExtraction.Range("E1:E299").ClearContents
    shtExtraction.Range("E2").Select
     
     
     
    shtExtraction.Select
    shtExtraction.Range("A1").Select
     
    Application.CutCopyMode = False
    Application.ScreenUpdating = True
     
     
     
     
    End Sub

  4. #4
    Invité
    Invité(e)
    Par défaut
    si nous somme bien d'accord, il s'agit d'un code VbScript, donc pas de typage [Actif As String]

  5. #5
    Candidat au Club
    Femme Profil pro
    Assistante de pôle
    Inscrit en
    Mai 2015
    Messages
    9
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Hauts de Seine (Île de France)

    Informations professionnelles :
    Activité : Assistante de pôle

    Informations forums :
    Inscription : Mai 2015
    Messages : 9
    Points : 3
    Points
    3
    Par défaut
    Merci encore, le problème persiste tout de même sur cette ligne :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    PDF_All CStr(Cell(1, 1).Value)
    avec une incompatibilité de type.

  6. #6
    Invité
    Invité(e)
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    PDF_All CStr("" & Cell(1, 1).Value)

  7. #7
    Candidat au Club
    Femme Profil pro
    Assistante de pôle
    Inscrit en
    Mai 2015
    Messages
    9
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Hauts de Seine (Île de France)

    Informations professionnelles :
    Activité : Assistante de pôle

    Informations forums :
    Inscription : Mai 2015
    Messages : 9
    Points : 3
    Points
    3
    Par défaut
    Malheureusement le problème reste le même : incompatibilité de type.

  8. #8
    Invité
    Invité(e)
    Par défaut
    relis le poste #4 sur la gestion des objet Excel!

Discussions similaires

  1. [Débutant] Boucle For Each Cell qui ne fonctionne pas
    Par FTMFB dans le forum Windows Forms
    Réponses: 3
    Dernier message: 05/11/2015, 17h23
  2. [XL-2010] Boucle For each cell in Range(.)
    Par hunk72 dans le forum Macros et VBA Excel
    Réponses: 3
    Dernier message: 20/10/2015, 17h59
  3. [XL-2013] Décrémenter une boucle For Each Cell in Range ?
    Par ldubs dans le forum Macros et VBA Excel
    Réponses: 5
    Dernier message: 09/12/2014, 17h41
  4. test avant d'entrer dans une boucle For each cell in selection
    Par totoro02 dans le forum Macros et VBA Excel
    Réponses: 7
    Dernier message: 13/01/2009, 09h27
  5. aide vba boucle for each paramétrée en range
    Par gotlieb dans le forum Macros et VBA Excel
    Réponses: 6
    Dernier message: 27/07/2006, 08h55

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