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
| Sub SommeDebCred()
Dim DerLig As Long, i As Long, Solde As Double
DerLig = Range("A" & Rows.Count).End(xlUp).Row + 1 ' Pour ajouter la ligne des Totaux
With Range("A" & DerLig)
.Value = "TOTAL au " & DateSerial(Year(Date) - 1, 12, 31)
.HorizontalAlignment = xlCenter
End With
For i = 1 To 2
With Cells(DerLig, i + 5)
.Value = Application.WorksheetFunction.Sum(Range(Cells(5, i + 5), Cells(DerLig - 1, i + 5)))
.NumberFormat = "#,##0"
End With
Next i
Range("A" & DerLig, "G" & DerLig + 2).Font.Bold = True
Range("A" & DerLig, "D" & DerLig).MergeCells = True 'Fusion de la ligne Total de A à D
Range("A" & DerLig + 2, "D" & DerLig + 2).MergeCells = True 'Fusion de la ligne Total de A à D
Range("A" & DerLig + 2, "G" & DerLig + 2).Font.ColorIndex = 3
With Range("A" & DerLig + 2)
.Value = "SOLDE"
.HorizontalAlignment = xlCenter
End With
Solde = Range("G" & DerLig).Value - Range("F" & DerLig).Value
If Solde < 0 Then Range("F" & DerLig + 2).Value = Solde Else: Range("G" & DerLig + 2).Value = Solde
Range("F" & DerLig + 2 & ":G" & DerLig + 2).NumberFormat = "#,##0"
End Sub |
Partager