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
| Option Explicit
Sub Toto()
'
Dim LigneTotal, LignePrevSsTot , Rw, LigneNonVide As Long 'les num de ligne von jusqu'à 65636, il faut un long
Dim colTotal, Col As Integer 'les n° de colonne vont jusqu'à 256, un integer suffit
Dim PlageNonVide As Range
Dim ssTot As Long 'sous-total
'
LigneTotal = Range("A65536").End(xlUp).Row
colTotal = Range("A4").End(xlToRight).Column
For Col = 2 To colTotal
If Cells(4, Col) = "2006" Or Cells(4, Col) = "2007" Then
LignePrevSsTot = 4
For Rw = LignePrevSsTot + 1 To LigneTotal - 1
If Cells(Rw, 1) Like "Total*" Then
Set PlageNonVide = Range(Cells(LignePrevSsTot + 1, Col), Cells(Rw - 1, Col))
ssTot = Application.WorksheetFunction.Sum(PlageNonVide)
Cells(Rw, Col).Select 'debug
Cells(Rw, Col).Value = ssTot
LignePrevSsTot = Rw
End If
Next Rw
End If
Next Col
End Sub |