auto-formatting pivot tables

miconian

Well-known Member
Joined
Aug 18, 2004
Messages
769
I have a large workbook, with similar pivot tables on every sheet. Some rows of the pivot tables have fill color. I need to loop through the workbook and make these fill colors consistent.

I set about doing this by recording a macro of myself putting in the fill color for one particular type of row, and here's what it produced:

Code:
PivotFormat()
'
'PivotFormat
'
    ActiveSheet.PivotTables("PivotTable12").PivotSelect _
        "'Sold To Customer'[All;Total] Jones", xlDataAndLabel, True
    With Selection.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .ThemeColor = xlThemeColorAccent5
        .TintAndShade = 0.599993896298105
        .PatternTintAndShade = 0
    End With
End Sub

Notice the word "Jones" on the second line of code. Jones is the data selected under "report filter." That can't be in the generic code, because with each worksheet, a different person's name is going to appear there.

Perhaps there is some kind of wildcard variable I can put into the code instead of "Jones"?

I'm also open to different approaches. All these pivot tables pull data from the same source, if that matters.

Thank you!
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Are you using the name as a page field? I'm not sure where "report filter" is references to?
 
Upvote 0
Based on a little searching, it does seem that Report Filter and Page Field are the same thing, perhaps from different versions of Excel. I'm in Excel 2007 for Windows.
 
Upvote 0
it looks like the report filter and page filter are the differences of 2007/2003. That field is usually in the same cell so it would seem that you could have the macro read that field. I would setup the macro to assign that cell value as a variable. I do not have 2007 here so I can't test it out for you. But maybe that will give a direction to work towards
 
Upvote 0
to assign a value in a cell use something like:

pvreport = Range("a1")

ActiveSheet.PivotTables("PivotTable12").PivotSelect _
pvreport, xlDataAndLabel, True

this is untested
 
Upvote 0
I'm not trying to assign a value to a cell, and I'm really not sure how your last comment relates to my question. But thanks for reading.
 
Upvote 0
Ok my reply wasn't assign a value to a cell, but it is reading a value from a cell. That value is then used in the macro. :)
 
Upvote 0
Notice the word "Jones" on the second line of code. Jones is the data selected under "report filter." That can't be in the generic code, because with each worksheet, a different person's name is going to appear there.

Perhaps there is some kind of wildcard variable I can put into the code instead of "Jones"?

ok let's go back. Your first post said you were looking for a variable to read the data of the report filter. Is that right? That was what I was answering? So now I'm confused :confused:
 
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,176
Members
451,543
Latest member
cesymcox

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