Option Explicit
Sub Consolidation_Classeur()
'Déclarations des variables.
'Les tableaux.
Dim t(), temp()
'Les lignes et colonnes.
Dim i&, ii&, j&, jj&
'Les onglets.
Dim n%
'On se place sur la feuille "Total"
With Sheets(54)
'On détermine la taille du Tableau final.
ii = .Cells.Find("*", , , , xlByRows, xlPrevious).Row
jj = .Cells.Find("*", , , , xlByColumns, xlPrevious).Column
'On enregistre le tableau en l'état actuel.
ReDim t(1 To ii, 1 To jj)
End With
'On boucle les Feuilles 1 à 53.
For n = 1 To 53
'On se place dans la Feuille.
With Sheets(n)
'On crée le tableau temporaire.
'Selon les dimensions du tableau final.
temp = .Range(.Cells(1, 1), .Cells(ii, jj)).Value
'On va boucler les tableaux.
Call Somme_Tableau(t(), temp(), n)
End With
Next n
'On reporte le tableau final.
With Sheets(54)
With .Range(.Cells(1, 1), .Cells(ii, jj))
.ClearContents
.Value = t
End With
End With
End Sub
Sub Somme_Tableau(Tableau1(), Tableau2(), Niveau%)
Dim i&, j&, k%
Dim Colonne()
Colonne = Array(3, 6, 7, 9, 11, 13, 15, 16, 18, 20, 21, 22)
For i = LBound(Tableau1, 1) To UBound(Tableau1, 1)
For k = LBound(Colonne) To UBound(Colonne)
j = Val(Colonne(k))
If Not IsNumeric(Tableau2(i, j)) And Niveau = 1 Then
Tableau1(i, j) = Tableau2(i, j)
ElseIf (Tableau2(i, j)) > 0 Then
Tableau1(i, j) = Tableau1(i, j) + Tableau2(i, j)
End If
Next k, i
End Sub