| 12
 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
 
 |  
Sub test()
 
Dim ligneFin As Integer, ligneDeb As Integer, nbVal As Integer
Dim cpt_l As Integer, ligne_deb As Integer, ligne_fin As Integer
Dim val_defaut As String, val As String
 
 
derLigne = Sheets("tableau initial").Range("a" & Rows.Count).End(xlUp).Row
 
'Suppression des données dans la feuille "tableau final"
Sheets("tableau final").Cells.Clear
 
'Copie des données de la feuille "tableau initial" vers la feuille "tableau final"
For cpt_l = 1 To derLigne
    Sheets("tableau final").Cells(cpt_l, 1) = Sheets("tableau initial").Cells(cpt_l, 1)
    Sheets("tableau final").Cells(cpt_l, 2) = Sheets("tableau initial").Cells(cpt_l, 2)
    Sheets("tableau final").Cells(cpt_l, 3) = Sheets("tableau initial").Cells(cpt_l, 3)
    Sheets("tableau final").Cells(cpt_l, 4) = Sheets("tableau initial").Cells(cpt_l, 4)
    Sheets("tableau final").Cells(cpt_l, 5) = Sheets("tableau initial").Cells(cpt_l, 5)
    Sheets("tableau final").Cells(cpt_l, 6) = Left(Sheets("tableau initial").Cells(cpt_l, 1), 3)
Next cpt_l
 
derLigne = Sheets("tableau final").Range("a" & Rows.Count).End(xlUp).Row
val_defaut = Left(Sheets("tableau final").Cells(1, 1), 3)
 
For cpt_l = 1 To Sheets("tableau final").Range("a" & Rows.Count).End(xlUp).Row
    ligneDeb = cpt_l
    nbVal = Application.WorksheetFunction.CountIf(Sheets("tableau final").Range(Cells(ligneDeb, 6), Cells(derLigne, 6)), val_defaut)
    ligneFin = ligneDeb + nbVal
 
    'Ajout de la ligne total
    Sheets("tableau final").Rows(ligneFin).Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
    Sheets("tableau final").Cells(ligneFin, 1) = val_defaut
 
    'Mise en place de la formule
    Sheets("tableau final").Cells(ligneFin, 4).FormulaLocal = "=SOMME(" & Cells(ligneDeb, 4).Address & ":" & Cells(ligneFin - 1, 4).Address & ")"
    Sheets("tableau final").Cells(ligneFin, 5).FormulaLocal = "=SOMME(" & Cells(ligneDeb, 5).Address & ":" & Cells(ligneFin - 1, 5).Address & ")"
 
    Sheets("tableau final").Range(Cells(ligneFin, 1), Cells(ligneFin, 6)).Interior.ColorIndex = 6
 
    cpt_l = ligneFin
    derLigne = Sheets("tableau final").Range("a" & Rows.Count).End(xlUp).Row
    val_defaut = Left(Sheets("tableau initial").Cells(cpt_l + 1, 1), 3)
 
Next cpt_l
 
 
 
End Sub | 
Partager