TCD format des nombres dans la zone valeur
Bonjour,
J'ai écrit un code pour mettre à jour mes différents TCD. Mon souci est que je n'arrive pas à mettre les nombres avec xxx.Style = "comma".
Pourriez-vous m'aider ?
Voici mon code :
Code:
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
| Sub RemplacerChampValeurAvecInput()
Dim ws As Worksheet
Dim pt As PivotTable
Dim pf As PivotField
Dim champAMod As String
Dim champRemplacer As String
Dim champSomme As String
Dim df As PivotField
Dim trouve As Boolean
champAMod = InputBox("Quelle est l'ancienne période (AAAA-MM)?")
If champAMod = "" Then
MsgBox "Aucune ancienne période saisie.", vbExclamation
Exit Sub
End If
champRemplacer = InputBox("Quelle est la nouvelle période (AAAA-MM)?")
If champRemplacer = "" Then
MsgBox "Aucune nouvelle période saisie.", vbExclamation
Exit Sub
End If
champSomme = "Somme de " & champAMod
For Each ws In ThisWorkbook.Worksheets
For Each pt In ws.PivotTables
' Chercher si le champ "Somme de champAMod" est dans les valeurs
trouve = False
For Each df In pt.DataFields
If df.Name = champSomme Then
trouve = True
Exit For
End If
Next df
If trouve Then
' Supprimer le champ "Somme de champAMod" des valeurs
On Error Resume Next
pt.DataFields(df.Name).Orientation = xlHidden
On Error GoTo 0
End If
' Ajouter le champ "champRemplacer" dans les valeurs s'il n'existe pas déjà
trouve = False
For Each df In pt.DataFields
If df.SourceName = champRemplacer Then
trouve = True
Exit For
End If
Next df
If Not trouve Then
On Error Resume Next
Dim nouveauChamp As PivotField
Set nouveauChamp = pt.AddDataField(pt.PivotFields(champRemplacer))
On Error GoTo 0
If Not nouveauChamp Is Nothing Then
'nouveauChamp.NumberFormat = "_-* # ##0,00\ __-;-* # ##0,00\ __-;_-* ""-""??\ __-;_-@_-" => ne me donne pas le format que je souhaite
nouveauChamp.Style = "comma"
End If
End If
pt.RefreshTable
Next pt
Next ws
MsgBox "Mise à jour des champs valeurs terminée !", vbInformation
End Sub |
Je vous remercie pour votre aide.