Private Sub Worksheet_Activate()
'la feuille "IMPRESSION" doit obligatoirement comporter 15 colonnes
'réparties en 3 groupes de 5
Dim ligdeb%, textdeb$, Ntitres%, hmax%, c As Range, T As Range
Dim h%, tablo, rest(), n%, col%, lig%, i%, j%, k%
'---données initiales à adapter---
ligdeb = 83 '1ère ligne du 1er tableau
textdeb = "SDIS 57"
Ntitres = 11 'nombre de lignes des titres
hmax = 36 'hauteur initiale des tableaux
Application.ScreenUpdating = False
'---RAZ de la feuille---
Cells.Clear 'efface tout
Sheets("IMPRESSION").Cells.Copy
[A1].PasteSpecial xlPasteValues 'collage spécial-valeurs
[A1].PasteSpecial xlPasteFormats 'collage spécial-formats
[A:O].FormatConditions.Delete 'supprime les MFC
[P1].Copy [P1] 'vide le presse-papiers
Application.Goto [A1:O1], True 'cadrage
ActiveWindow.Zoom = True 'zoom
'---traitement de chaque tableau---
For Each c In [A:A].SpecialCells(xlCellTypeConstants)
If c.Row >= ligdeb And Trim(c) = textdeb Then
Set T = c(Ntitres + 1).Resize(hmax, 15)
h = Application.RoundUp(Application.CountIf(T, "ü") / 3, 0)
If h Then
tablo = T 'matrice, plus rapide
ReDim rest(1 To h, 1 To 15)
n = 0
For col = 1 To 11 Step 5
For lig = 1 To hmax
If tablo(lig, col + 4) = "ü" Then
i = (n Mod h) + 1
j = Int(n / h)
j = IIf(j = 0, 1, IIf(j = 1, 6, 11))
For k = 0 To 4
rest(i, j + k) = tablo(lig, col + k)
Next k
n = n + 1
End If
Next lig
Next col
Intersect(T, [D:D,I:I,N:N]).Font.Bold = False 'police non gras
Intersect(T, [D:D,I:I,N:N]).NumberFormat = "@" '"0000000"
T(1).Resize(h, 15) = rest
End If
If h < hmax Then T(h + 1, 1).Resize(hmax - h).EntireRow.Delete
End If
Next c
End Sub