Applying conditional formatting to all tables

h12345678

New Member
Joined
Jul 31, 2023
Messages
1
Office Version
  1. 2016
Platform
  1. Windows
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!!


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
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.

Forum statistics

Threads
1,215,076
Messages
6,122,987
Members
449,093
Latest member
Mr Hughes

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top