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 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303
| Option Explicit
Sub TCD()
'Developped by koobcam - march 2011
Dim a As Integer
Dim b As Integer
Dim c As Integer
Dim d As Integer
Dim e As Integer
Dim f As Integer
Dim n As Integer
Dim p As Integer
Dim nbcar As Integer
Dim Show As String
Dim Year As String
Dim k As String
Dim col() As String
Dim pvtItem As PivotItem
'Identification de l'ensemble des colonnes pour les plages du TCD
a = ActiveSheet.Range("A65536").End(xlUp).Row
b = ActiveSheet.Range("IV4").End(xlToLeft).Column
ReDim col(b)
For n = 1 To b
col(n) = Cells(4, n).Value
Next
'Création d'un TCD
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
"PASCOM!R4C1:R" & a & "C" & b).CreatePivotTable TableDestination:="", TableName:= _
"RAPPRO_PSOFT", DefaultVersion:=xlPivotTableVersion10
ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells(3, 1)
ActiveSheet.Cells(3, 1).Select
' Nommer la nouvelle feuille et insérer un titre
ActiveSheet.Name = "RAPPRO_PSOFT"
Rows("1:1").Select
Selection.Insert Shift:=xlDown
Selection.Insert Shift:=xlDown
Selection.Insert Shift:=xlDown
ActiveCell.FormulaR1C1 = "Rapprochement du CA PASCOM_PSOFT"
Range("A1").Select
With Selection
.Font.Bold = True
.Font.Underline = xlUnderlineStyleSingle
.WrapText = False
End With
Range("A1:B1").Select
With Selection
.Merge
.HorizontalAlignment = xlLeft
End With
'Sélection des champs colonnes du TCD
With ActiveSheet.PivotTables("RAPPRO_PSOFT").PivotFields(col(17))
.Orientation = xlDataField
.Position = 1
End With
With ActiveSheet.PivotTables("RAPPRO_PSOFT").PivotFields(col(2))
.Orientation = xlColumnField
.Position = 1
End With
' Ordonnancement de la ventilation PASCOM
For Each pvtItem In ActiveSheet.PivotTables("RAPPRO_PSOFT").PivotFields(col(2)).VisibleItems
k = pvtItem.Name
Select Case k
Case "Vente"
ActiveSheet.PivotTables("RAPPRO_PSOFT").PivotFields(col(2)).PivotItems("Vente").Position = 1
Case "A risque"
ActiveSheet.PivotTables("RAPPRO_PSOFT").PivotFields(col(2)).PivotItems("A risque").Position = 2
Case "Contentieux"
ActiveSheet.PivotTables("RAPPRO_PSOFT").PivotFields(col(2)).PivotItems("Contentieux").Position = 3
Case "Autres Ventes"
ActiveSheet.PivotTables("RAPPRO_PSOFT").PivotFields(col(2)).PivotItems("Autres Ventes").Position = 4
Case "Evènements"
ActiveSheet.PivotTables("RAPPRO_PSOFT").PivotFields(col(2)).PivotItems("Evènements").Position = 5
Case "Echanges"
ActiveSheet.PivotTables("RAPPRO_PSOFT").PivotFields(col(2)).PivotItems("Echanges").Position = 6
Case Else
End Select
Next
'Sélection des champs lignes du TCD
'Typo 1
With ActiveSheet.PivotTables("RAPPRO_PSOFT").PivotFields(col(5))
.Orientation = xlRowField
.Position = 1
End With
'Typo 2
With ActiveSheet.PivotTables("RAPPRO_PSOFT").PivotFields(col(6))
.Orientation = xlRowField
.Position = 2
End With
'Code Product
With ActiveSheet.PivotTables("RAPPRO_PSOFT").PivotFields(col(11))
.Orientation = xlRowField
.Position = 3
End With
'Lib Product
With ActiveSheet.PivotTables("RAPPRO_PSOFT").PivotFields(col(12))
.Orientation = xlRowField
.Position = 4
End With
' Sélection et mise au format des Sous-totaux en ligne
'>> TOTAL
ActiveSheet.PivotTables("RAPPRO_PSOFT").PivotSelect _
"'Column Grand Total'", xlDataAndLabel, True
Selection.Font.Bold = True
With Selection.Interior
.ColorIndex = 40
.Pattern = xlSolid
End With
'>> Lib Product
ActiveSheet.PivotTables("RAPPRO_PSOFT").PivotFields(col(12)). _
Subtotals = Array(False, False, False, False, False, False, False, False, False, False, _
False, False)
'>> Code Product
ActiveSheet.PivotTables("RAPPRO_PSOFT").PivotFields(col(11)). _
Subtotals = Array(False, False, False, False, False, False, False, False, False, False, _
False, False)
'>> Typo 2
ActiveSheet.PivotTables("RAPPRO_PSOFT").PivotSelect _
"'Typo2'[All;Total]", xlDataAndLabel, True
Selection.Font.Bold = True
With Selection.Interior
.ColorIndex = 37
.Pattern = xlSolid
End With
ActiveSheet.PivotTables("RAPPRO_PSOFT").PivotFields(col(6)).LayoutBlankLine = True
'>> Typo 1
ActiveSheet.PivotTables("RAPPRO_PSOFT").PivotSelect _
"'Typo1'[All;Total]", xlDataAndLabel, True
Selection.Font.Bold = True
With Selection.Interior
.ColorIndex = 35
.Pattern = xlSolid
End With
ActiveSheet.PivotTables("RAPPRO_PSOFT").PivotFields(col(5)).LayoutBlankLine = True
'Identification du Salon et de la Session
Year = Sheets("PASCOM").Range("F2").Value
Show = Sheets("PASCOM").Range("E2").Value
Rows(3).Select
Selection.Insert Shift:=xlDown
Selection.Insert Shift:=xlDown
Range("A3").Value = Show
Range("A4").Value = Year
Range("A3:A4").Select
With Selection
.Borders(xlDiagonalDown).LineStyle = xlNone
.Borders(xlDiagonalUp).LineStyle = xlNone
.HorizontalAlignment = xlCenter
.Font.Bold = True
End With
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
' Mise en forme des nombres
Columns("E:K").Select
Call MEF_Nombre.MEF_Nombre
' Ajustement de l'alignement
Range("C:C").Select
With Selection
.HorizontalAlignment = xlCenter
End With
'--------------------------------------
'Fixation de la largeur des colonnes
Columns("A:A").ColumnWidth = 21.43
Columns("B:B").ColumnWidth = 26.86
Columns("C:C").ColumnWidth = 7.14
Columns("D:'D").ColumnWidth = 25#
Columns("E:K").ColumnWidth = 11#
'--------------------------------------
'Mise en page des Entiquettes de colonne du TCD
ActiveSheet.PivotTables("RAPPRO_PSOFT").PivotFields("Somme de Net" & Chr(10) & "YTD N"). _
Caption = "Net Année N ()"
Rows("8:8").RowHeight = 12.75
Rows("9:9").Select
With Selection
.WrapText = True
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.EntireRow.AutoFit
.Font.Bold = True
End With
Rows("10:10").Select
ActiveWindow.FreezePanes = True
' Mise en page finale pour Impression
Rows("1:1").RowHeight = 21.75
e = ActiveSheet.Range("A65536").End(xlUp).Row
f = ActiveSheet.Range("A9").End(xlToRight).Column
With ActiveSheet.PageSetup
.PrintTitleRows = "$1:$9"
.Orientation = xlLandscape
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = 20
End With
' Plage dynamique de la zone d'impression
Range(Cells(1, 1), Cells(e, f)).Select
ActiveSheet.PageSetup.PrintArea = Selection.Address
'Mise en page finale et Cache des champs du TCD
Call MiseEnPage_Final.MiseEnPage_Final
ActiveWorkbook.ShowPivotTableFieldList = False
Range("A1").Select
End Sub |
Partager