+ Reply to Thread
Results 1 to 1 of 1

How to apply conditional formatting to pivot table with VBA. Record macro is not working

  1. #1
    Registered User
    Join Date
    06-25-2020
    Location
    USA
    MS-Off Ver
    2016
    Posts
    1

    How to apply conditional formatting to pivot table with VBA. Record macro is not working

    VBA Excel 2016

    I have a pivot table of operating expenses and I want it to change to red any cells that have YoY growth >.3 or <-.3. For that I need the macro to automatically apply these two conditions:

    (value in column "2018 Ave. PSF" - value in column "2017 Ave. PSF")/(value in column "2017 Ave. PSF")>.3
    (value in column "2018 Ave. PSF" - value in column "2017 Ave. PSF")/(value in column "2017 Ave. PSF")<-.3

    I have columns that already make those calculations, but having those columns activated disrupts my pivot charts.

    This is my (very) wrong VBA code:

    Sub PercentFormat( . . . )

    'Set Variables
    Dim pf as PivotField
    Dim pt as PivotTable

    Application.ScreenUpdating = False

    For Each pf In pt.DataFields

    If Abs((Range("2018 Ave PSF").Value - Range("2017 Ave PSF").Value) / Range("2017 Ave PSF").Value) > 0.3 Then

    Cell.Interior.Color = vbRed
    Cell.Font.Color = vbWhite
    End If

    If Abs((Range("2018 Ave PSF").Value - Range("2017 Ave PSF").Value) / Range(column with year 1).Value) < -0.3 Then

    Cell.Interior.Color = vbRed
    Cell.Font.Color = vbWhite
    End If Next

    Application.ScreenUpdating = True

    End Sub
    Attached Images Attached Images

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 0
    Last Post: 02-25-2016, 10:22 PM
  2. Replies: 2
    Last Post: 09-04-2015, 02:47 AM
  3. Conditional formatting macro - apply to all rows
    By iwalke in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-22-2015, 07:17 AM
  4. Replies: 1
    Last Post: 05-28-2014, 06:31 PM
  5. How to apply conditional formatting for a pivot chart
    By bala.peddi in forum Excel Charting & Pivots
    Replies: 0
    Last Post: 05-09-2014, 03:36 AM
  6. Replies: 9
    Last Post: 11-05-2013, 05:03 PM
  7. [SOLVED] Macro to apply several conditional formatting criteria
    By useR in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-04-2005, 12:05 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1