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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
|
Sub Test()
Dim Plage As Range
Dim Cel As Range
Dim TblDebit()
Dim TblCredit()
Dim TblDonneesCredit
Dim TblDonneesDebit
Dim I As Integer
Dim J As Integer
Dim Col As Integer
'défini la plage
With Worksheets("Format Initial")
Set Plage = .Range(.Cells(2, 1), .Cells(.Rows.Count, 1).End(xlUp))
End With
'titres des colonnes
TblDonneesDebit = Array("", "", "Donnée_2", "Donnée_3", "Donnée_4", "Donnée_5", _
"Donnée_6", "Donnée_7", "Donnée_8")
TblDonneesCredit = Array("Donnée_9", "Donnée_10", "Donnée_11", "Donnée_12", _
"Donnée_13", "Donnée_14", "Donnée_15")
'défini le nombre de lignes du tableau (+ 1 = ligne des titres)
I = Application.CountIf(Plage, "Total_Données") + 1
'les bornes étant connues, dimensionne les tableaux
ReDim TblDebit(1 To I, 1 To UBound(TblDonneesDebit) + 1)
ReDim TblCredit(1 To I, 1 To UBound(TblDonneesCredit) + 1)
'rempli la première ligne de chaque tableau (les titres)
For I = 1 To UBound(TblDonneesDebit) + 1: TblDebit(1, I) = TblDonneesDebit(I - 1): Next I
For I = 1 To UBound(TblDonneesCredit) + 1: TblCredit(1, I) = TblDonneesCredit(I - 1): Next I
'évite la ligne des titres
I = 2
For Each Cel In Plage
If Cel.Value <> "Total_Données" Then
Select Case Cel.Value
Case "Donnée_1"
TblDebit(I, 1) = Cel.Value
TblDebit(I, 2) = Cel.Offset(, 1).Value
Case "Donnée_2", "Donnée_3", "Donnée_4", "Donnée_5", "Donnée_6", "Donnée_7", "Donnée_8"
J = Application.Match(Cel.Value, TblDonneesDebit, 0)
TblDebit(I, J) = Cel.Offset(, 1).Value
Case "Donnée_9", "Donnée_10", "Donnée_11", "Donnée_12", "Donnée_13", "Donnée_14", "Donnée_15"
J = Application.Match(Cel.Value, TblDonneesCredit, 0)
TblCredit(I, J) = Cel.Offset(, 2).Value
End Select
Else
'ligne suivante
I = I + 1
End If
Next Cel
With Worksheets("Format Final")
'supprime tout formatage et valeurs
With .Cells
.Clear
.ClearFormats
.Font.ColorIndex = 0
.Font.Bold = False
.Borders(xlEdgeLeft).LineStyle = xlNone
.Borders(xlEdgeTop).LineStyle = xlNone
.Borders(xlEdgeBottom).LineStyle = xlNone
.Borders(xlEdgeRight).LineStyle = xlNone
.Borders(xlInsideVertical).LineStyle = xlNone
.Borders(xlInsideHorizontal).LineStyle = xlNone
.FormatConditions.Delete
End With
'colle les valeurs, formate les nombres et colore la fonte en bleu
.Range(.Cells(1, 1), .Cells(UBound(TblDebit, 1), UBound(TblDebit, 2))).Value = TblDebit
.Range(.Cells(1, 1), .Cells(UBound(TblDebit, 1), UBound(TblDebit, 2))).NumberFormat = "_(* #,##0.00_);_(* (#,##0.00);_(* ""-""??_);_(@_)"
.Range(.Cells(1, 3), .Cells(UBound(TblDebit, 1), UBound(TblDebit, 2))).Font.ColorIndex = 5
Col = .Cells(1, .Columns.Count).End(xlToLeft).Column + 1
'double traits verticaux en séparation des tableaux
.Range(.Cells(1, Col - 1), .Cells(UBound(TblDebit, 1), Col - 1)).Borders(xlEdgeRight).LineStyle = xlDouble
'colle les valeurs, formate les nombres et colore la fonte en bleu
.Range(.Cells(1, Col), .Cells(UBound(TblCredit, 1), UBound(TblCredit, 2) + Col - 1)).Value = TblCredit
.Range(.Cells(1, Col), .Cells(UBound(TblCredit, 1), UBound(TblCredit, 2) + Col - 1)).NumberFormat = "_(* #,##0.00_);_(* (#,##0.00);_(* ""-""??_);_(@_)"
.Range(.Cells(1, Col), .Cells(UBound(TblCredit, 1), UBound(TblCredit, 2) + Col - 1)).Font.ColorIndex = 3
'double traits verticaux en séparation des tableaux et colonnes de sommage
Col = .Cells(1, .Columns.Count).End(xlToLeft).Column + 1
.Range(.Cells(1, Col - 1), .Cells(UBound(TblDebit, 1), Col - 1)).Borders(xlEdgeRight).LineStyle = xlDouble
'titres de deux colonnes
.Cells(1, Col).Value = "Total_Debit"
.Cells(1, Col + 1).Value = "Total_Crédit"
'formule de sommage
.Cells(2, Col).Formula = "=SUM(C2:I2)": .Cells(2, Col).AutoFill .Range(.Cells(2, Col), .Cells(UBound(TblDebit, 2) - 1, Col))
.Cells(2, Col + 1).Formula = "=SUM(J2:P2)": .Cells(2, Col + 1).AutoFill .Range(.Cells(2, Col + 1), .Cells(UBound(TblCredit, 2) + 1, Col + 1))
'coloration des fontes
.Range(.Cells(2, Col), .Cells(UBound(TblDebit, 2) - 1, Col)).Font.ColorIndex = 5
.Range(.Cells(2, Col + 1), .Cells(UBound(TblCredit, 2) + 1, Col + 1)).Font.ColorIndex = 3
'mise en gras de la ligne d'entêtes
.Range(.Cells(1, 3), .Cells(1, Col + 1)).Font.Bold = True
'cadrillage
With .Range(.Cells(1, 1), .Cells(UBound(TblDebit, 1), Col + 1))
.Borders(xlEdgeLeft).LineStyle = xlContinuous
.Borders(xlEdgeTop).LineStyle = xlContinuous
.Borders(xlEdgeBottom).LineStyle = xlContinuous
.Borders(xlEdgeRight).LineStyle = xlContinuous
.Borders(xlInsideHorizontal).LineStyle = xlContinuous
End With
'double traits verticaux en fin de tableau
.Range(.Cells(1, Col + 1), .Cells(UBound(TblDebit, 1), Col + 1)).Borders(xlEdgeRight).LineStyle = xlDouble
With .Range(.Cells(2, 1), .Cells(UBound(TblCredit, 1), Col + 1))
.FormatConditions.Add 2, , "=MOD(LIGNE();2)=0"
.FormatConditions(1).Interior.Color = 10086399
End With
End With
End Sub |
Partager