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
| Sub Editions()
Dim k As Integer, i As Integer, j As Integer
'Gele l'écran pour la vitesse du traitement
Application.ScreenUpdating = False
'Tris sur la feuille de données
With Sheets(1)
'Garde les 3 premiers caractère des Editions (MM PAP -> MM )
For k = 2 To .Cells(Rows.Count, 1).End(xlUp).Row
.Range("I" & k) = Left(.Range("I" & k), 3)
Next
i = 2
While .Range("A" & i) <> ""
'Si un même annonce paraît la même date mais dans des Edition différentes
'on ajoute les Editions à la suite, on ajoute le prix de l'un au premier
'ainsi que la taille. Enfin on supprime les lignes inutiles
If (.Range("D" & i) = .Range("D" & i + 1)) _
And (.Range("I" & i) <> .Range("I" & i + 1)) _
And (.Range("E" & i) = .Range("E" & i + 1)) Then
'Compte le nombre de même annonces qui se suivent
j = 1
While .Range("D" & i) = .Range("D" & i + j) _
And (.Range("I" & i) <> .Range("I" & i + j)) _
And (.Range("E" & i) = .Range("E" & i + j))
j = j + 1
Wend
For k = 1 To j - 1
.Range("I" & i) = .Range("I" & i) & " " & .Range("I" & i + 1)
.Range("H" & i) = .Range("H" & i) + .Range("H" & i + 1)
.Rows(i + 1).Delete
Next
End If
'Tri pour le tableau croisé dynamique
If .Range("Q" & i) <> "Mots" Then .Range("Q" & i & ":" & "S" & i).ClearContents
If (.Range("T" & i) <> "Col x Hauteur (mm)") And (.Range("T" & i) <> "Mm") Then .Range("T" & i & ":" & "V" & i).ClearContents
If .Range("W" & i) <> "Quantité" Then .Range("W" & i & ":" & "Y" & i).ClearContents
i = i + 1
Wend
End With
Sheets(4).Select
Range("B7").Select
ActiveSheet.PivotTableWizard xlDatabase, Range("Feuil1!P1:Y" & i)
ActiveSheet.PivotTables("Tableau croisé dynamique3").PivotCache.Refresh
ActiveWorkbook.ShowPivotTableFieldList = False
'Mise en page
If Range("J6") <> "" Then
Range("B7:J7,B8:J8,B10:J10,B11:J11,B13:J13,B14:J14").Borders(xlEdgeBottom).LineStyle = xlContinuous
Else
Range("B7:H7,B8:H8,B10:H10,B11:H11,B13:H13,B14:H14").Borders(xlEdgeBottom).LineStyle = xlContinuous
End If
Columns("B:M").Style = "Comma"
Columns("I:M").ColumnWidth = 17#
If Range("I6") = "" Then Columns("I").Hidden = True
If Range("H6") = "" Then Columns("H").Hidden = True
Sheets(3).Select
Range("B10").Select
ActiveSheet.PivotTableWizard xlDatabase, Range("Feuil1!A1:N" & i)
ActiveSheet.PivotTables("Tableau croisé dynamique1").PivotCache.Refresh
Sheets(2).Select
Range("B10").Select
ActiveSheet.PivotTableWizard xlDatabase, Range("Feuil1!A1:N" & i)
ActiveSheet.PivotTables("Tableau croisé dynamique2").PivotCache.Refresh
With Columns("C")
.Style = "Comma"
.EntireColumn.AutoFit
End With
j = 8
While (Range("B" & j) <> "Total") And (Range("B" & j - 1) <> "Total")
Range("B" & j & ":" & "C" & j).Interior.ColorIndex = 34
Range("B" & j + 1 & ":" & "C" & j + 1).Interior.ColorIndex = 40
j = j + 2
Wend
If Range("B" & j) = "Total" Then
Range("B" & j & ":" & "C" & j).Interior.ColorIndex = 45
Else
Range("B" & j - 1 & ":" & "C" & j - 1).Interior.ColorIndex = 45
End If
Sheets(1).Visible = False
Sheets(2).Name = "Montants par zone"
Sheets(3).Name = "Détail"
Sheets(4).Name = "Montants par types gratuits"
Application.ScreenUpdating = True
End Sub |
Partager