Excel/VBA-根据列值填充数据透视表中单元格的颜色 [英] Excel/VBA - Fill color of a cell in pivot table according to column value
问题描述
我有一个数据透视表,该数据透视表的来源是另一张纸上的表格.源表如下所示:
I have a pivot table that the source is a table on another sheet. The source table looks like this:
客户 | 收入类型 | 值 | 月 | 控制 |
---|---|---|---|---|
A | 住宅 | 1000 | 一月 | 付费 |
A | 商业 | 2000 | 二月 | 未付款 |
B | 住宅 | 2000 | 二月 | 未付款 |
C | 商业 | 1500 | 二月 | 付费 |
D | 咨询 | 5000 | 三月 | 付费 |
数据透视表设置如下:
列-月
行-客户端
价值-价值总和
Column - Month
Row - Client
Value - Sum of value
客户 | 一月 | 二月 | 三月 |
---|---|---|---|
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.
提前谢谢!
推荐答案
如果无法使用条件格式设置,我不知道一种简单的方法来对数据透视表中的数据进行着色.剩下的唯一选择是VBA.
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.
这篇关于Excel/VBA-根据列值填充数据透视表中单元格的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!