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
| 'Oblige a déclarer toutes la variable (du coup une alerte si on à fait une faute de frappe dans le nom d'une variable)
Option Explicit
Sub Lancement_macrodiplom()
Call Certificat
Call Transfertdiplo
End Sub
Sub Transfertdiplo()
Dim CelSource As Range
Dim CelCible As Range
Dim Compteur As Integer
Dim NBlignes As Integer
Dim a As Integer
Dim b As Integer
Dim c As Integer
'Début à la cellule A2 pas A4 je pense
Set CelSource = Worksheets("Résultat").Range("a2")
Set CelCible = Worksheets("Diplomes").Range("a19")
NBlignes = Application.CountA(Sheets("Résultat").Range("A:A")) - 1
Application.ScreenUpdating = False
Worksheets("Résultat").Activate
'L'utilisation de ActiveSheet peut jouer de vilain tour, autant utiliser le codename de la feuille
With Feuil3 'ActiveSheet
'x = NBlignes *41
For c = 0 To NBlignes - 1
If Not IsEmpty(CelSource.Offset(c, 8).Value) Then
For a = 1 To NBlignes Step 41
'??
'For Compteur = 1 To 1
' les pages
CelCible(a, 1).Value = CelSource.Offset(c, 9).Value
CelCible(a + 6, 1).Value = CelSource.Offset(c, 2).Value
CelCible(a + 11, 1).Value = CelSource.Offset(c).Value
CelCible(a + 14, 1).Value = VBA.Format((CelSource.Offset(c, 8).Value), """Avec: ""0.00%")
Set CelSource = CelSource.Offset(1)
Set CelCible = CelCible.Offset(42)
'Next
Next
End If
Next
End With
End Sub
Sub Certificat()
Dim SHsource As Worksheet, SHcible As Worksheet, x As Integer
Dim PlageSource As Range, CelluleCible As Range, I As Integer
Dim NBlignes As Integer
Set SHsource = ThisWorkbook.Sheets("Certificat") '<-- classeur source
Set SHcible = ThisWorkbook.Sheets("Diplomes") '<-- classeur cible
Set PlageSource = SHsource.Range("A1:A42") '<-- plage de cellules à copier
NBlignes = Application.CountA(Sheets("Résultat").Range("I:I")) - 1
Z = NBlignes * 42
For j = 1 To Z Step 42
Set CelluleCible = SHcible.Cells(j, 1) '<-- destination (à partir de F11)
PlageSource.Copy CelluleCible '<-- copie de la plage
'adaptation hauteur des lignes
x = 0
For I = CelluleCible.Row To CelluleCible.Row + PlageSource.Rows.Count
x = x + 1
SHcible.Cells(I, 1).RowHeight = PlageSource.Rows(x).RowHeight
Next
'adaptation largeur des colonnes
PlageSource.Resize(, PlageSource.Columns.Count).Copy
SHcible.Cells(1, CelluleCible.Column).Resize(, PlageSource.Columns.Count).PasteSpecial xlPasteColumnWidths
' x = 0
' For I = CelluleCible.Column To CelluleCible.Column + PlageSource.Columns.Count
' x = x + 1
' SHcible.Cells(1, I).ColumnWidth = PlageSource.Columns(x).ColumnWidth
' Next
Next j
End Sub |
Partager