Hi everyone,
I’m new to this forum / VBA and I’m trying to create a code that applies conditional formatting for all columns in every pivot table and refreshes every table in my Excel workbook. I’ve been able to set this up for one pivot table / one sheet but I’m not sure how to change my code so it applies to every pivot table in my workbook. Currently I have around 10+ different pivot tables so I’m struggling with creating a code that doesn’t take too long to update too. I’ve uploaded my code and I’d really appreciate any help!!
I’m new to this forum / VBA and I’m trying to create a code that applies conditional formatting for all columns in every pivot table and refreshes every table in my Excel workbook. I’ve been able to set this up for one pivot table / one sheet but I’m not sure how to change my code so it applies to every pivot table in my workbook. Currently I have around 10+ different pivot tables so I’m struggling with creating a code that doesn’t take too long to update too. I’ve uploaded my code and I’d really appreciate any help!!
ActiveSheet.PivotTables (1). PivotCache. Refresh
Set pt = ActiveSheet. PivotTables ("PivotTable3")
For Each ptFld In pt. DataBodyRange. Columns
ptFld. Select ptFld. FormatConditions.Delete
Selection. FormatConditions.AddColorScale ColorScaleType: =3
Selection. FormatConditions (Selection. FormatConditions. Count) . SetFirstPriority Selection. FormatConditions (1). ColorScaleCriteria (1). Type =
xlConditionValueLowestValue
With Selection. FormatConditions (1) .ColorScaleCriteria (1) . FormatColor
.Color = 7039480
.TintAndShade = 0
End With
Selection. FormatConditions (1) .ColorScaleCriteria (2) .Type =
xlConditionValuePercentile
Selection.FormatConditions (1). ColorScaleCriteria (2) . Value = 50
With Selection. FormatConditions (1) .ColorScaleCriteria (2) .FormatColor
Color = 8711167
. TintAndShade = 0
End With
Selection. FormatConditions (1) .ColorScaleCriteria (3) .Type =
x1ConditionValueHighestValue
With Selection.FormatConditions (1). ColorScaleCriteria (3) .FormatColor
.Color = 8109667
.TintAndShade
= O
End With
Next ptFld
End Sub