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 150 151 152 153 154 155 156
| Sub Random_Hebdo_KW()
'
' Random_Hebdo_KW Macro
'
'
' Désactivation du Screen Refreshing
Application.ScreenUpdating = False
'Suppression des lignes indésirables
Rows("1:5").Delete Shift:=xlUp
' Changement du nom des colonnes
Range("K1").FormulaR1C1 = "CA"
Range("I1").FormulaR1C1 = "Match Type"
' Ajustement de la taille des colonnes
Cells.EntireColumn.AutoFit
' Sélection des données et création d'un tableau "Data"
ActiveSheet.ListObjects.Add(xlSrcRange, Range(ActiveCell, Cells(ActiveCell.End(xlDown).Row, ActiveCell.End(xlToRight).Column)), , xlYes).Name = "Data"
Range("Data[#All]").Select
ActiveSheet.ListObjects("Data").TableStyle = "TableStyleMedium13"
' Création des nouvelles colonnes avec formules
Range("L1").FormulaR1C1 = "Pos*Imp"
Range("L2").FormulaR1C1 = "=[@[Position moy.]]*[@Impressions]"
Range("M1").FormulaR1C1 = "N° Semaine"
Range("M2").FormulaR1C1 = "=ISOWEEKNUM([@Semaine])"
Range("N1").FormulaR1C1 = "Année"
Range("N2").FormulaR1C1 = "=YEAR([@Semaine])"
' Mise en force des valeurs des colonnes
Range("Data[Impressions]").Select
Selection.Style = "Comma"
Selection.NumberFormat = "_-* #,##0 __-;-* #,##0 __-;_-* ""-""?? __-;_-@_-"
Range("Data[Clics]").Select
Selection.Style = "Comma"
Selection.NumberFormat = "_-* #,##0 __-;-* #,##0 __-;_-* ""-""?? __-;_-@_-"
Range("Data[Coût]").Select
Selection.Style = "Currency"
Selection.NumberFormat = "_-* #,##0 $_-;-* #,##0 $_-;_-* ""-""?? $_-;_-@_-"
Range("Data[Conversions]").Select
Selection.Style = "Comma"
Selection.NumberFormat = "_-* #,##0 __-;-* #,##0 __-;_-* ""-""?? __-;_-@_-"
Range("Data[CA]").Select
Selection.Style = "Currency"
Selection.NumberFormat = "_-* #,##0 $_-;-* #,##0 $_-;_-* ""-""?? $_-;_-@_-"
' Suppression des lignes inutiles du tableau
Dim UselessAdWordsLines As Range
For Each UselessAdWordsLines In ActiveSheet.UsedRange
If UselessAdWordsLines Like "*Rapport*" Or UselessAdWordsLines Like "*Total*" Then UselessAdWordsLines.Rows.EntireRow.Delete
Next
' Ajout d'une feuille "TCD"
Sheets.Add
ActiveSheet.Name = "TCD"
' Création du TCD "TCD_Data"
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:="Data", Version:=6).CreatePivotTable TableDestination:="TCD!R3C1", TableName:="TCD_Data", DefaultVersion:=6
Sheets("TCD").Select
With ActiveSheet.PivotTables("TCD_Data").PivotFields("N° Semaine")
.Orientation = xlRowField
.Position = 1
End With
With ActiveSheet.PivotTables("TCD_Data").PivotFields("Compte")
.Orientation = xlRowField
.Position = 2
End With
With ActiveSheet.PivotTables("TCD_Data").PivotFields("Match Type")
.Orientation = xlRowField
.Position = 3
End With
' Création des champs calculés
ActiveSheet.PivotTables("TCD_Data").CalculatedFields.Add "@CTR", "=Clics /Impressions", True
ActiveSheet.PivotTables("TCD_Data").CalculatedFields.Add "@CPC", "=Coût /Clics", True
ActiveSheet.PivotTables("TCD_Data").CalculatedFields.Add "@Pos. Moy.", "='Pos*Imp' /Impressions", True
ActiveSheet.PivotTables("TCD_Data").CalculatedFields.Add "@ROI", "=CA /Coût", True
ActiveSheet.PivotTables("TCD_Data").AddDataField ActiveSheet.PivotTables("TCD_Data").PivotFields("Impressions"), " Impressions", xlSum
ActiveSheet.PivotTables("TCD_Data").AddDataField ActiveSheet.PivotTables("TCD_Data").PivotFields("Clics"), " Clics", xlSum
ActiveSheet.PivotTables("TCD_Data").AddDataField ActiveSheet.PivotTables("TCD_Data").PivotFields("Coût"), " Coût", xlSum
ActiveSheet.PivotTables("TCD_Data").AddDataField ActiveSheet.PivotTables("TCD_Data").PivotFields("@Pos. Moy."), " Pos. Moy.", xlSum
ActiveSheet.PivotTables("TCD_Data").AddDataField ActiveSheet.PivotTables("TCD_Data").PivotFields("Conversions"), " Conversions", xlSum
ActiveSheet.PivotTables("TCD_Data").AddDataField ActiveSheet.PivotTables("TCD_Data").PivotFields("CA"), " CA", xlSum
' Mise en Forme en-tête du TCD
Range("A3").Select
ActiveSheet.PivotTables("TCD_Data").CompactLayoutRowHeader = " "
Rows("3:3").Select
Selection.Replace What:="Somme de ", Replacement:=" ", LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
' Mise au bon format des valeurs
ActiveSheet.PivotTables("TCD_Data").PivotSelect "' Impressions':' Clics'", xlDataAndLabel, True
Selection.Style = "Comma"
Selection.NumberFormat = "_-* #,##0 __-;-* #,##0 __-;_-* ""-""?? __-;_-@_-"
ActiveSheet.PivotTables("TCD_Data").PivotSelect "' Coût'", xlDataAndLabel, True
Selection.Style = "Currency"
Selection.NumberFormat = "_-* #,##0 $_-;-* #,##0 $_-;_-* ""-""?? $_-;_-@_-"
ActiveSheet.PivotTables("TCD_Data").PivotSelect "' Pos. Moy.'", xlDataAndLabel, True
Selection.NumberFormat = "0.00"
ActiveSheet.PivotTables("TCD_Data").PivotSelect "' Conversions'", xlDataAndLabel, True
Selection.Style = "Comma"
Selection.NumberFormat = "_-* #,##0 __-;-* #,##0 __-;_-* ""-""?? __-;_-@_-"
ActiveSheet.PivotTables("TCD_Data").PivotSelect "' CA'", xlDataAndLabel, True
Selection.Style = "Currency"
Selection.NumberFormat = "_-* #,##0 $_-;-* #,##0 $_-;_-* ""-""?? $_-;_-@_-"
With ActiveSheet.PivotTables("TCD_Data").PivotFields("Match Type")
.Orientation = xlRowField
.Position = 2
End With
With ActiveSheet.PivotTables("TCD_Data").PivotFields("Compte")
.Orientation = xlRowField
.Position = 2
End With
' Changement du style d'affichage du TCD
Range("A4").Select
Range(Selection, Selection.End(xlDown)).Select
ActiveSheet.PivotTables("TCD_Data").RowAxisLayout xlTabularRow
ActiveWindow.SmallScroll Down:=-15
Range("B6").Select
ActiveSheet.PivotTables("TCD_Data").PivotFields("Compte").Subtotals = Array(False, False, False, False, False, False, False, False, False, False, False, False)
Range("A27").Select
ActiveSheet.PivotTables("TCD_Data").PivotFields("N° Semaine").Subtotals = Array(False, False, False, False, False, False, False, False, False, False, False, False)
Range("A28").Select
ActiveSheet.PivotTables("TCD_Data").ColumnGrand = False
Range("A4:C27").Select
ActiveSheet.PivotTables("TCD_Data").RepeatAllLabels xlRepeatLabels
ActiveSheet.PivotTables("TCD_Data").PivotSelect "Exact", xlDataAndLabel, True
Cells.Select
Range("B9").Activate
Cells.EntireColumn.AutoFit
Range("D5").Select
ActiveSheet.PivotTables("TCD_Data").TableStyle2 = "PivotStyleMedium10"
' Réactivation du Screen Refreshing
Application.ScreenUpdating = True
End Sub |
Partager