Sub Test()
Dim xrg, xArea, x, rech
Application.ScreenUpdating = False
Columns(3).Clear
Columns(3).Font.Size = 8
ActiveSheet.PivotTables("Tableau croisé dynamique1").PivotFields("CD_EMPRISE"). _
ShowDetail = True
ActiveSheet.PivotTables("Tableau croisé dynamique1").PivotSelect _
"lu_couleur[All]", xlLabelOnly + xlFirstRow, True
Set xrg = Selection
On Error Resume Next
For Each xArea In xrg.Areas
For Each x In xArea
rech = Application.Match(x, Sheets("RefRal").Columns(1), 0)
If IsError(rech) Then
Cells(x.Row, "c") = x.Value
Else
Cells(x.Row, "c").Interior.Color = HexaRGB(Sheets("RefRal").Cells(rech, "c"))
End If
Next x
Next xArea
On Error GoTo 0
Range("c1").EntireColumn.HorizontalAlignment = xlVAlignCenter
Range("c1").EntireColumn.AutoFit
Range("a1").Select
End Sub
Function HexaRGB(ByVal Hex As String)
Dim R, G, B
Hex = Right$("000000" & Replace(Hex, "#", ""), 6)
R = Val("&H" & Mid(Hex, 1, 2))
G = Val("&H" & Mid(Hex, 3, 2))
B = Val("&H" & Mid(Hex, 5, 2))
HexaRGB = RGB(R, G, B)
End Function