Pivottable conditional formating

doriannjeshi

Active Member
Joined
Apr 5, 2015
Messages
338
Office Version
  1. 365
Platform
  1. Windows
Hi,
How to apply conditional formating to a pivotable based on values of another column value

this is the base table
numberMonthDayNight
TRUEJanuary14
TRUEJanuary18
SEMIJanuary24
FALSEJanuary14
SEMIMay13
TRUEMay28
FALSEMay13
SEMIMay24
FALSEMay24
TRUEOctober18
TRUEOctober24
FALSEOctober13


Here values of Day , conditional formating for values = 2

1731792200705.png


I want to apply this cell color formating based on the values of column Day to the pivot with the values of Night .
This is an example as my table is very large and I need the most efficient way. Because I will have to do this with a macro and then apply permanent color formating

1731792335078.png
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Because I will have to do this with a macro and then apply permanent color formating
If you are doing it with a macro, do you really need the Conditional Formatting? Could a macro just apply the colour directly? Something like this?
Assuming the PivotTable is in the 'Day' mode when this code is run.

VBA Code:
Sub Test()
  Dim rFound As Range
  Dim FirstAddr As String
  
  Const ValueOfInterest As Double = 2 '<- Value you are looking for
  
  With ActiveSheet.PivotTables(1).DataBodyRange
    With .Resize(.Rows.Count - 1)
      .Interior.Color = xlNone
      Set rFound = .Find(What:=ValueOfInterest, LookAt:=xlWhole)
      If Not rFound Is Nothing Then
        FirstAddr = rFound.Address
        Do
          rFound.Interior.Color = vbGreen
          Set rFound = .Find(What:=ValueOfInterest, After:=rFound, LookAt:=xlWhole)
        Loop Until rFound.Address = FirstAddr
      End If
    End With
  End With
End Sub

Before the code is run:
1731801054391.png


After the code is run:
1731801105225.png


Now change to 'Night' mode:
1731801161684.png
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,159
Members
453,021
Latest member
Justyna P

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