Excel 2010 - Pivot Table Conditional Format

geekette

Board Regular
Joined
Sep 12, 2006
Messages
120
I have a pivot table that in an older version of excel I was able to apply some conditional formatting. I have now been upgraded to office 2010 and am finding that pivot tables no longer store the conditional formatting applied.

I've built a solution using vba - (which runs on the PivotTableUpdate), however it takes about a minute to run and am wondering if there is a smarter way to do this? The code and functions I am using are below. If there is any advice on how I can enhance this to make it smarter I would be so greatful :O)


Private Function FormatRedRow(RangeName As Range, rng As Range, OffsetRef As Integer, OffsetTotal As Integer)

'If the AWOL flag is = 1 then format the cell red
For Each RangeName In rng
If (RangeName.Offset(0, OffsetRef).Value = 1 And RangeName.Offset(0, OffsetTotal) > 0) Then
With RangeName.Interior
.ThemeColor = xlThemeColorAccent2
.TintAndShade = 0.399975585192419
End With
End If
Next RangeName

End Function

Private Function FormatGreenRow(RangeName As Range, rng As Range, OffsetRef As Integer, OffsetTotal As Integer)

'If the comment is other than Blank and range name > 0 format the row green
For Each RangeName In rng
If (RangeName.Offset(0, OffsetRef).Value <> " (blank)" And RangeName.Offset(0, OffsetTotal) > 0) Then
With RangeName.Interior
.ThemeColor = xlThemeColorAccent3
.TintAndShade = 0.399975585192419
End With
End If
Next RangeName

End Function

Private Function FormatBlanks(RangeName As Range, rng As Range)

'if any " (Blank) " in column format the text white

For Each RangeName In rng
If RangeName.Value = " (blank)" Then
With RangeName.Font
.ThemeColor = xlThemeColorDark1
.TintAndShade = 0
End With
End If
Next RangeName

End Function

Private Function FormatRedAbsence(RangeName As Range, rng As Range, OffsetRef As Integer)

For Each RangeName In rng
If RangeName.Offset(0, OffsetRef).Value = "Absence Not Logged" Then
With RangeName.Interior
.ThemeColor = xlThemeColorAccent2
.TintAndShade = 0.399975585192419
End With
End If
Next RangeName

End Function


Private Sub ConditionalFormat()

Dim StaffedTime As Range
Dim Lunch As Range
Dim TotalAbsence As Range
Dim MeasuredHours As Range
Dim Comment As Range
Dim All As Range



Application.ScreenUpdating = False

'First set all formatting to 0

Range("CondFmt_rng").Select

With Selection.Interior
.Pattern = xlNone
.TintAndShade = 0
.PatternTintAndShade = 0
End With

'Format Staffed Time Column
Call FormatRedRow(StaffedTime, Range("Summary_Staffed"), 6, -2)
Call FormatGreenRow(StaffedTime, Range("Summary_Staffed"), -1, -2)
Call FormatRedAbsence(StaffedTime, Range("Summary_Staffed"), -1)

'Format Lunch column
Call FormatRedRow(Lunch, Range("Summary_Lunch"), 5, -3)
Call FormatGreenRow(Lunch, Range("Summary_Lunch"), -2, -3)
Call FormatRedAbsence(Lunch, Range("Summary_Lunch"), -2)

'Format TotalAbsence column
Call FormatRedRow(TotalAbsence, Range("Summary_Absence"), 4, -4)
Call FormatGreenRow(TotalAbsence, Range("Summary_Absence"), -3, -4)
Call FormatRedAbsence(TotalAbsence, Range("Summary_Absence"), -3)

'Format MeasuredHours column
Call FormatRedRow(MeasuredHours, Range("Summary_Measured"), 3, -5)
Call FormatGreenRow(MeasuredHours, Range("Summary_Measured"), -4, -5)
Call FormatRedAbsence(MeasuredHours, Range("Summary_Measured"), -4)

'Format blanks as white so not visible
Call FormatBlanks(Comment, Range("Summary_Comment"))

Range("A1").Select

Application.ScreenUpdating = True

End Sub
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.

Forum statistics

Threads
1,224,586
Messages
6,179,730
Members
452,939
Latest member
WCrawford

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