Conflit de compilation

Fermé
scorpmax24 Messages postés 2 Date d'inscription vendredi 20 avril 2018 Statut Membre Dernière intervention 20 avril 2018 - Modifié le 21 avril 2018 à 23:08
yg_be Messages postés 22705 Date d'inscription lundi 9 juin 2008 Statut Contributeur Dernière intervention 19 avril 2024 - 20 avril 2018 à 22:23
Bonjour, je suis actuellement en train de me torturer la tête sur une macro pour le boulot.
j'ai repris un fichier Excel sur lequel j'ai juste une mise à jour à faire.
je souhaite copier deux colonnes supplémentaires via un bouton.
voici la macro :

Sub BouclerColonne()
       Dim MaListe  As ListObject 'As ListColumn
    Dim MonArchive  As ListObject
    Dim cel As Range, OT As Range
    Dim Z As Integer
    Dim A As Integer
    Dim MaCellule As Variant
    Dim MaPlage As Range
    Set MaListe = Sheets("EnCours").ListObjects("Tbl_EnCours")
    Set MonArchive = Sheets("Archives").ListObjects("Tbl_Archives")
  

' MISE A JOUR COMMENTAIRE
  
    Sheets("EnCours").Select
    Range("Tbl_EnCours[[#Headers],[N° Ordre Client]]").Select
    Range(Selection, Selection.End(xlToRight)).Select
    Selection.Copy
    Sheets("Archives").Select
    Range("Tbl_Archives[[#Headers],[N° Ordre Client]]").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False

 
    For Each cel In MaListe.ListColumns("Commentaire du Jour").DataBodyRange.Cells
        If MaListe.ListColumns("Information de la veille").DataBodyRange.Cells(cel.Row - 2).Value <> "" Then
            If cel.Value = "" Or IsNull(cel.Value) Then
                cel.Value = MaListe.ListColumns("Information de la veille").DataBodyRange.Cells(cel.Row - 2).Value
            Else
                cel.Value = cel.Value & " - " & MaListe.ListColumns("Information de la veille").DataBodyRange.Cells(cel.Row - 2).Value
            End If
            
    For Each cel In MaListe.ListColumns("Date / heure montage").DataBodyRange.Cells
        If MaListe.ListColumns("Type montage").DataBodyRange.Cells(cel.Row - 2).Value <> "" Then
            If cel.Value = "" Or IsNull(cel.Value) Then
                cel.Value = MaListe.ListColumns("Type montage").DataBodyRange.Cells(cel.Row - 2).Value
            Else
                cel.Value = cel.Value & " - " & MaListe.ListColumns("Type montage").DataBodyRange.Cells(cel.Row - 2).Value
            End If
        End If
        MonOT = MaListe.ListColumns("N° Ordre Client").DataBodyRange.Cells(cel.Row - 2).Value
        For Each OT In MonArchive.ListColumns("N° Ordre Client").DataBodyRange.Cells
            If OT.Value = MonOT Then
                MonArchive.ListRows(OT.Row - 1).Delete
                Exit For
            End If
        Next
        
'        If Not IsEmpty(cel.Value) Then  'cel.Value <> "" Or Not IsNull(cel.Value) Or
'            MonArchive.ListRows.Add (1)
'
'            MonOT = MaListe.ListColumns("N° Ordre Client").DataBodyRange.Cells(cel.Row - 2).Value
'
'        End If
        'MsgBox cel.Address & " : " & CStr(cel.Value)
    Next cel
   
    NbLignes = MaListe.DataBodyRange.Rows.Count
    NbLignesInit = MonArchive.DataBodyRange.Rows.Count
    With MonArchive
          .Resize .Range.Resize(NbLignesInit + NbLignes, .Range.Columns.Count)
          LastCol = .Range.Columns.Count
    End With
    
    
    MaListe.DataBodyRange.Copy
    MonArchive.DataBodyRange.Cells(NbLignesInit + 1, 1).PasteSpecial (xlPasteValues)
    Sheets("Archives").Select
    Worksheets("Archives").Columns(LastCol + 1).Delete
    
      
  Sheets("EnCours").Select
  Range("I1").Select
     
       
  MsgBox "Votre archivage s'est bien effectué. Vous pouvez enregistrer puis fermer où refaire une extraction OMS"
   
End Sub


Au niveau des lignes qui suivent, j'ai un problème car lorsque que j'essaye ma macro la ligne "Sub BouclerColonne()" apparait en jaune et j'ai le message "erreur de compilation, variable de contrôle for déjà utilisée. les lignes que jai ajouté sont celles qui suivent :

For Each cel In MaListe.ListColumns("Date / heure montage").DataBodyRange.Cells
        If MaListe.ListColumns("Type montage").DataBodyRange.Cells(cel.Row - 2).Value <> "" Then
            If cel.Value = "" Or IsNull(cel.Value) Then
                cel.Value = MaListe.ListColumns("Type montage").DataBodyRange.Cells(cel.Row - 2).Value
            Else
                cel.Value = cel.Value & " - " & MaListe.ListColumns("Type montage").DataBodyRange.Cells(cel.Row - 2).Value
            End If


merci de votre aide

2 réponses

yg_be Messages postés 22705 Date d'inscription lundi 9 juin 2008 Statut Contributeur Dernière intervention 19 avril 2024 1 471
20 avril 2018 à 19:41
bonjour,
dans l'extrait suivant:
For Each cel In MaListe.ListColumns("Commentaire du Jour").DataBodyRange.Cells 
If MaListe.ListColumns("Information de la veille").DataBodyRange.Cells(cel.Row - 2).Value <> "" Then 
If cel.Value = "" Or IsNull(cel.Value) Then 
cel.Value = MaListe.ListColumns("Information de la veille").DataBodyRange.Cells(cel.Row - 2).Value 
Else 
cel.Value = cel.Value & " - " & MaListe.ListColumns("Information de la veille").DataBodyRange.Cells(cel.Row - 2).Value 
End If 

For Each cel In MaListe.ListColumns("Date / heure montage").DataBodyRange.Cells 

le premier
for each cel
est toujours en cours, et tu fais un second
for each
avec également cel.
donc "variable de contrôle for déjà utilisée"
si tu veux imbriquer les
for each
, ce qui est parfaitement autorisé, il faut utiliser deux variables différentes, donc pas deux fois "cel".
0
scorpmax24 Messages postés 2 Date d'inscription vendredi 20 avril 2018 Statut Membre Dernière intervention 20 avril 2018
20 avril 2018 à 20:16
très bien,
je débute cependant, qu'est ce que je pourrais mettre pour que ça fonctionne ?
0
yg_be Messages postés 22705 Date d'inscription lundi 9 juin 2008 Statut Contributeur Dernière intervention 19 avril 2024 1 471
20 avril 2018 à 22:23
alors explique-nous ce que tu veux faire de plus: quelles colonnes souhaites-tu copier vers où via quel bouton?
0