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
| Option Explicit
Sub test()
Dim myAreas As Areas, b(), x, temp, i As Long, j As Long, n As Long
Application.ScreenUpdating = False
x = Array("Code", "Nom", "Donnée_2", "Donnée_3", "Donnée_4", "Donnée_5", _
"Donnée_6", "Donnée_7", "Donnée_8", "Donnée_9", "Donnée_10", _
"Donnée_11", "Donnée_12", "Donnée_13", "Donnée_14", "Donnée_15", _
"Total_Débit", "Total_Crédit"): n = 1
With Sheets("Format Initial")
With .Range("a2", .Range("a" & Rows.Count).End(xlUp))
On Error Resume Next
'.ColumnDifferences(.Find("Total_Données", lookat:=xlWhole)).Select
Set myAreas = .ColumnDifferences(.Find("Total_Données", lookat:=xlWhole)).Areas
On Error GoTo 0
ReDim b(1 To .Rows.Count, 1 To UBound(x) + 1)
For i = 0 To UBound(x)
b(1, i + 1) = x(i)
Next
End With
End With
If myAreas Is Nothing Then Exit Sub
For i = 1 To myAreas.Count
n = n + 1
With myAreas(i)
b(n, 1) = .Cells(1, 1).Value
b(n, 2) = .Cells(1, 2).Value
For j = 2 To .Rows.Count
temp = Application.Match(.Cells(j).Value, x, 0)
b(n, temp) = IIf(.Cells(j, 2).Value <> 0, .Cells(j, 2).Value, .Cells(j, 3).Value)
Next
b(n, UBound(b, 2) - 1) = Application.Sum(.Cells(2, 2).Resize(.Rows.Count - 1))
b(n, UBound(b, 2)) = Application.Sum(.Cells(2, 3).Resize(.Rows.Count - 1))
End With
Next
Set myAreas = Nothing
'Restitution et mise en forme
With Sheets("Feuil1").Cells(1)
.Parent.Cells.Clear
.Resize(n, UBound(b, 2)) = b
With .CurrentRegion
.Font.Name = "calibri"
.VerticalAlignment = xlCenter
.Borders(xlInsideVertical).Weight = xlThin
.BorderAround Weight:=xlThin
With .Rows(1)
.Font.Size = 11
.BorderAround Weight:=xlThin
With .Offset(, 2).Resize(, .Columns.Count - 11)
.Interior.ColorIndex = 43
End With
With .Offset(, 9).Resize(, .Columns.Count - 11)
.Interior.ColorIndex = 19
End With
With .Offset(, 16).Resize(, .Columns.Count - 16)
.Interior.ColorIndex = 15
End With
End With
With .Offset(1, 2).Resize(.Rows.Count - 1, .Columns.Count - 2)
.NumberFormat = "_(* #,##0.00_);_(* (#,##0.00);_(* ""-""??_);_(@_)"
End With
.Columns.ColumnWidth = 12
End With
.Parent.Activate
End With
Application.ScreenUpdating = True
End Sub |