Excel/VBA - Fill color of a cell in pivot table according to column value

半城伤御伤魂 提交于 2021-02-10 14:12:07

问题


I have a pivot table that the source is a table on another sheet. The source table looks like this:

Client Type of income Value Month Control
A Residential 1000 January Paid
A Commercial 2000 February Not paid
B Residential 2000 February Not paid
C Commercial 1500 February Paid
D Consulting 5000 March Paid

The pivot table is set like this:

Column - Month
Row - Client
Value - Sum of value

Client January February March
A 1000 2000 0
B 0 2000 0
C 0 1500 0
D 0 0 5000

Now I want to fill the color of the cells based on the column "Control" - that is not on the Pivot table. Every cell that is "not paid", I want it to be red.

Is this possible? I tried using conditional formatting, but without success.

Thank you in advance!


回答1:


I don't know of an easy way to color code data in a pivot table if it can't be done using conditional formatting, because after that, the only option remaining is VBA.

You can achieve your goal by putting the column "Control" in the filter section of the pivot table. This would also take care of the problem that would pop up if you have a paid and an unpaid bill by the same client in the same month.

My recommendation is to structure the pivot table in such a manner that you see paid and unpaid as categories.



来源:https://stackoverflow.com/questions/65486414/excel-vba-fill-color-of-a-cell-in-pivot-table-according-to-column-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!