XL 2013 Fomat d'un tableau croisé dynamique

Chrystel01

XLDnaute Occasionnel
Bonjour,

Quand je colle un tableau croisé dynamique (collage valeur + format) je perds une partie de son format (zones en rouge ci-dessous)
Connaissez-vous svp un moyen de conserver ce format ?
Je vous remercie par avance

Chrystel

1613335367326.png
 

Pièces jointes

  • TCD.xlsx
    12.6 KB · Affichages: 12
Solution
Bonsoir Christel01, le forum,

c est la cellule étudiée dans le TCD.

c(1, 5) est la 5ème cellule à droite à partir de c.

Une solution plus générale et plus élaborée dans le fichier joint :
VB:
Sub Coller()
Dim col%, c As Range, i%
Application.ScreenUpdating = False
With Sheets("tcd").PivotTables(1).TableRange1
    col = .Columns.Count + 2
    .EntireColumn.Copy .EntireColumn.Cells(1, col) 'pour copier les largeurs des colonnes
    .Columns(col).EntireColumn.Resize(, .Columns.Count).Clear 'RAZ
    For Each c In .Cells
        c(1, col) = c
        c(1, col).Interior.Color = c.DisplayFormat.Interior.Color
        c(1, col).Font.Color = c.DisplayFormat.Font.Color
        c(1, col).Font.Bold = c.DisplayFormat.Font.Bold...

job75

XLDnaute Barbatruc
Alors utilisez cette macro avec DisplayFormat :
VB:
Sub Coller()
Dim c As Range, i%
For Each c In [A3:C12] 'plage à adapter
    c(1, 5) = c
    c(1, 5).Interior.Color = c.DisplayFormat.Interior.Color
    c(1, 5).Font.Color = c.DisplayFormat.Font.Color
    c(1, 5).Font.Bold = c.DisplayFormat.Font.Bold
    For i = 7 To 10
        If c.DisplayFormat.Borders(i).LineStyle <> xlNone Then c(1, 5).Borders(i).Weight = c.DisplayFormat.Borders(i).Weight
Next i, c
End Sub
 

job75

XLDnaute Barbatruc
Bonsoir Christel01, le forum,

c est la cellule étudiée dans le TCD.

c(1, 5) est la 5ème cellule à droite à partir de c.

Une solution plus générale et plus élaborée dans le fichier joint :
VB:
Sub Coller()
Dim col%, c As Range, i%
Application.ScreenUpdating = False
With Sheets("tcd").PivotTables(1).TableRange1
    col = .Columns.Count + 2
    .EntireColumn.Copy .EntireColumn.Cells(1, col) 'pour copier les largeurs des colonnes
    .Columns(col).EntireColumn.Resize(, .Columns.Count).Clear 'RAZ
    For Each c In .Cells
        c(1, col) = c
        c(1, col).Interior.Color = c.DisplayFormat.Interior.Color
        c(1, col).Font.Color = c.DisplayFormat.Font.Color
        c(1, col).Font.Bold = c.DisplayFormat.Font.Bold
        For i = 7 To 10
            If c.DisplayFormat.Borders(i).LineStyle <> xlNone Then c(1, 5).Borders(i).Weight = c.DisplayFormat.Borders(i).Weight
    Next i, c
End With
End Sub
A+
 

Pièces jointes

  • TCD(1).xlsm
    22.2 KB · Affichages: 5

Discussions similaires