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
|
Sub TCD()
Dim Msg, Style, Title, choix1, choix
'On Error Resume Next
Application.ScreenUpdating = False
ActiveWorkbook.Names.Add Name:="mazone", RefersToR1C1:= _
"=OFFSET(Test!R1C1,,,COUNTA(Test!C1),2)" ' creation de la zone de nom
Columns("D:E").ClearContents ' efface la colonne D et E
Msg = "Souhaitez-vous effacer le TCD ?" ' Définit le message d'effacement.
Style = vbYesNo + vbCritical + vbDefaultButton2 ' Définit les boutons.
Title = "Effacement du TCD " ' Définit le titre.
choix = MsgBox(Msg, Style, Title) ' Affiche le message.
If choix = vbYes Then ' L'utilisateur a choisi Oui.
ActiveSheet.PivotTables("tcd").TableRange2.Clear 'Efface le TCD
choix1 = MsgBox(" souhaitez vous le recréer ?", Style, "Demande de Création ") 'Ouvre un nouveau MSGBOX pour la création du TCD
If choix1 = vbNo Then ' si la réponse est Non on sort de la macro
Exit Sub
Else 'sinon on crée le nouveau TCD
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:="mazone" _
).CreatePivotTable TableDestination:=Range("H6"), TableName:="TCD"
With ActiveSheet.PivotTables("TCD")
ActiveSheet.PivotTables("TCD").AddDataField ActiveSheet. _
PivotTables("TCD").PivotFields("RTO"), "Nombre de RTO", xlCount
With .PivotFields("RTO")
.Orientation = xlPageField
.Position = 1
End With
With .PivotFields("Nombre de RTO")
.Caption = "Min de RTO"
.Function = xlMin
End With
With .PivotFields("APP")
.Orientation = xlRowField
.Position = 1
End With
End With
Worksheets("Test").Range("J2").Value = Worksheets("Test").PivotTables("TCD").TableRange1.Rows.Count
End If
Else ' L'utilisateur a choisi Non.
Exit Sub ' Effectue une action.
End If
Application.ScreenUpdating = True
End Sub |
Partager