Re : Pbm Boucle For Each sur plusieurs onglet
Bonjour Pierrot et merci pour ta réactivité,
effectivement ca a l'air d'être évident quand tu me le dis mais je n'ai peut être pas encore les bons réflexe
Donc OK pour le IF sur les noms de sheet.. Cela fonctionne.
Cependant, je suis confronté à un autre problème
En gros, j'ai une macro qui génère deux types d'onglets:
- les onglets appelés 1, 2, 3 ... 29 qui sont tirés de mon onglet "Conso à Date"
- les onglets 1H, 2H, 3H, ... 29H qui sont tirés de mon deuxième onglet "Conso Historique" (d'où le H).
La boucle doit servir a coller chacun de ses onglets dans un fichier template + le sauvegarder en utilisant la valeur d'une cellule.
La subtilité est que je dois coller :
- l'onglet 1 dans le fichier Template, dans un 1er onglet
- l'onglet 1H dans le même fichier Template, dans un 2nd onglet
- sauvegarder en utilisant la valeur de "1er onglet".Range("A1")
==> Helas, ca ne fonctionne pas!
Voici mon code au cas où tu verrais iù se trouve l'erreur:
Sub BoucleTotale()
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Génération des onglets "A Date" et "Historique" en utilisant le fichier template '
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Application.ScreenUpdating = False
Dim Sh As Worksheet, wb As Workbook
'Boucle passant sur chacun des onglets régions pour créer un report indépendants
For Each Sh In ThisWorkbook.Worksheets
If Sh.Name <> "Conso à date par région" And Sh.Name <> "Conso histo par région" Then
Set wb = Workbooks.Open("C:\Templates\Template Report Région.xls")
If IsNumeric(ActiveSheet.Name) Then
Sh.Range("A2:G36").Copy Destination:=wb.Sheets("Votre Région a date").Range("A65536").End(xlUp)(2)
Sh.Range("H2:H36").Copy Destination:=wb.Sheets("Votre Région a date").Range("J65536").End(xlUp)(2)
Sh.Range("I2:I36").Copy Destination:=wb.Sheets("Votre Région a date").Range("M65536").End(xlUp)(2)
Sh.Range("J2:J36").Copy Destination:=wb.Sheets("Votre Région a date").Range("P65536").End(xlUp)(2)
Sh.Range("K2:K36").Copy Destination:=wb.Sheets("Votre Région a date").Range("S65536").End(xlUp)(2)
Sh.Range("L2:L36").Copy Destination:=wb.Sheets("Votre Région a date").Range("V65536").End(xlUp)(2)
Sh.Range("M2:M36").Copy Destination:=wb.Sheets("Votre Région a date").Range("Y65536").End(xlUp)(2)
Sh.Range("N2:N36").Copy Destination:=wb.Sheets("Votre Région a date").Range("AB65536").End(xlUp)(2)
Else
Sh.Range("A2:G36").Copy Destination:=wb.Sheets("Votre Région Histo").Range("A65536").End(xlUp)(2)
Sh.Range("H2:H36").Copy Destination:=wb.Sheets("Votre Région Histo").Range("J65536").End(xlUp)(2)
Sh.Range("I2:I36").Copy Destination:=wb.Sheets("Votre Région Histo").Range("M65536").End(xlUp)(2)
Sh.Range("J2:J36").Copy Destination:=wb.Sheets("Votre Région Histo").Range("P65536").End(xlUp)(2)
Sh.Range("K2:K36").Copy Destination:=wb.Sheets("Votre Région Histo").Range("S65536").End(xlUp)(2)
Sh.Range("L2:L36").Copy Destination:=wb.Sheets("Votre Région Histo").Range("V65536").End(xlUp)(2)
Sh.Range("M2:M36").Copy Destination:=wb.Sheets("Votre Région Histo").Range("Y65536").End(xlUp)(2)
Sh.Range("N2:N36").Copy Destination:=wb.Sheets("Votre Région Histo").Range("AB65536").End(xlUp)(2)
End If
End If
Next Sh
MsgBox "Les Fichiers de Reporting Hebdomadaires ont été générés."
End Sub