Private Sub Worksheet_Activate()
Dim LO As ListObject, ncol1%, ncol2%, nlig&, col%, Tcible, Tsource, n%, i&, x$, p%, style$
Application.ScreenUpdating = False
Cells.Delete 'RAZ
Set LO = Sheets("Import").ListObjects(1) 'tableau structuré
LO.Range.Copy
Cells(1).PasteSpecial xlPasteValues 'colle seulement les valeurs
ncol1 = UsedRange.Columns.Count
ncol2 = 3 + 3 * (ncol1 - 3)
UsedRange.Rows(2).Insert xlDown 'insère la ligne des sous-titres
nlig = UsedRange.Rows.Count
If nlig = 1 Then nlig = 2 'si le tableau est vide
With UsedRange.Resize(nlig, ncol2)
For col = ncol2 - 2 To 4 Step -3
.Cells(2, col).Resize(, 3) = Array("HT", "TVA", "TTC")
Tcible = .Columns(col).Resize(, 3) 'matrice, plus rapide
Tsource = .Columns(ncol1 - n): If col > 4 Then .Columns(ncol1 - n).ClearContents: n = n + 1
Tcible(1, 1) = Tsource(1, 1) 'titre
For i = 3 To UBound(Tcible)
x = Tsource(i, 1)
p = InStr(x, "HT"): If p Then Tcible(i, 1) = Val(Replace(Replace(Replace(Mid(x, p + 2), Chr(160), ""), ":", ""), ",", "."))
p = InStr(x, "TVA"): If p Then Tcible(i, 2) = Val(Replace(Replace(Replace(Mid(x, p + 3), Chr(160), ""), ":", ""), ",", "."))
p = InStr(x, "TTC"): If p Then Tcible(i, 3) = Val(Replace(Replace(Replace(Mid(x, p + 3), Chr(160), ""), ":", ""), ",", "."))
Next i
.Columns(col).Resize(, 3) = Tcible 'restitution
Next col
'---couleurs sur 4 lignes---
n = IIf(nlig < 4, nlig, 4) 'si moins de 4 lignes
style = LO.TableStyle 'mémorise
LO.TableStyle = "TableStyleMedium3" 'le style que vous voulez
.Resize(2).Interior.Color = LO.Range(1).DisplayFormat.Interior.Color
.Resize(2).Font.Color = LO.Range(1).DisplayFormat.Font.Color
.Resize(2).Font.Bold = True 'gras
If n > 2 Then .Rows(3).Interior.Color = LO.Range(2, 1).DisplayFormat.Interior.Color
If n > 3 Then .Rows(4).Interior.Color = LO.Range(3, 1).DisplayFormat.Interior.Color
LO.TableStyle = style 'état initial
'---bordures et formats sur 4 lignes---
.Resize(n).Borders.Weight = xlThin
.Resize(1, 3).Borders(xlEdgeBottom).LineStyle = xlNone
.Resize(n).BorderAround xlDouble 'contour bordure double
.Rows(n).Borders(xlEdgeBottom).Weight = xlThin 'sauf ligne du bas
For col = 1 To 3: .Columns(col).ColumnWidth = LO.Range(1, col).ColumnWidth: Next col
.Resize(n, 3).WrapText = True 'renvoi à la ligne
With .Columns(4).Resize(n, ncol2 - 3)
.HorizontalAlignment = xlCenter
.ColumnWidth = 12.5 'à adapter
.NumberFormat = "#,##0.00 €"
End With
For col = 4 To ncol2 Step 3
.Columns(col).Resize(1, 3).HorizontalAlignment = xlCenterAcrossSelection
.Columns(col).Resize(n, 3).Borders(xlEdgeLeft).LineStyle = xlDouble 'bordure double
Next col
'---propagation des formats sur toutes les lignes---
If nlig > 4 Then .Rows("3:4").AutoFill .Rows(3).Resize(nlig - 2), xlFillFormats
.Rows(nlig).Borders(xlEdgeBottom).LineStyle = xlDouble 'bordure double en dernière ligne
'---fin---
.Resize(2).RowHeight = 25 'titres et sous-titres
.Rows(1).Select: ActiveWindow.Zoom = True 'ajuste le zoom
Application.Goto .Cells(1), True 'cadrage
End With
ActiveWindow.SplitRow = 2: ActiveWindow.FreezePanes = True 'fige les volets
End Sub