假设我有以下表格结构 (A1:C3)
A B C
1 H1 H2 H3
2 1 1 3
3 4 5 4
如何应用具有以下条件的条件格式:
- 仅标题单元格 (H1,H2,H3) 着色
- 着色方案为 2 或 3 色阶
- 值用于计算颜色的应该是 A2/A3、B2/B3、C2/C3(范围是 0-1)
注意:我不是在寻找 VBA 解决方案,因为我可以自己制作,但如果您有一些疯狂的 1 班轮请告诉:)
注意:我不想应用很多规则,例如 if x<0.3 red
、if 0.3 等。
有什么干净的解决方案吗?
可以根据公式的值应用 3 色标吗?
Suppose I have the following table structure (A1:C3)
A B C
1 H1 H2 H3
2 1 1 3
3 4 5 4
How can I apply a conditional formatting with the following conditions:
- Only the header cells (H1,H2,H3) are colored
- The coloring scheme is 2 or 3-color-scale
- The values used for computing the color should be A2/A3, B2/B3, C2/C3 (range is 0-1)
Note: I'm not looking for a VBA solution, as I can make my own, but if you have some crazy 1 liner please tell :)
Note: I don't want to apply a lot of rules like if x<0.3 red
, if 0.3<x<0.6 orange
etc.
Is there any clean solution for this?
Can a 3-color-scale be applied based on the value of a formula?
发布评论
评论(2)
我认为您正在寻找一些有趣的东西,但不幸的是并不存在。我只看到两个选项。
您可以使用三个条件进行条件格式设置,如果您想使用默认单元格颜色作为三个条件之一,甚至可以只使用两个条件格式(例如,公式为 =(A2/A3)<0.3,公式为 =(A2/A3) <0.6,或任何您想要的阈值)。您可以在 Excel 中的一个标题单元格上手动应用此格式,然后将其复制到所有标题;或通过VBA应用它。
或者,您可以在 VBA 中为标题着色,然后在工作表上放置一个按钮来调用代码来更新颜色。
在我看来,第一个选项(条件格式)更适合,因为它会根据单元格值自动更新颜色。不过,我必须承认,我不太明白为什么你要寻找比这更“干净”的东西,因为它实际上是一个非常简单的解决方案。两个条件就构成“很多规则”吗?不是英语的任何延伸......
I think you're looking for something nifty that unfortunately doesn't exist. I just see the two options.
You can either do conditional formatting with three conditions, or even just two if you want to use the default cell color as one of the three (e.g. Formula Is =(A2/A3)<0.3, Formula Is =(A2/A3)<0.6, or whatever you want your threshold values to be). You can apply this fomatting manually on one header cell in Excel, and copy it across to all headers; or apply it through VBA.
Or you can color the headers in VBA, and place a button on your sheet that calls the code to update the colors.
Sounds to me like the first option (conditional formatting) is better suited, because it will update the colors automatically based on the cell values. I have to admit, though, I don't quite see why you're looking for something "cleaner" than this, because it's actually a really simple solution. Do two conditions constitute "a lot of rules"? Not by any stretch of the English language...
以下是 Jean-François Corbett 代码的改编版,它从红-黄-绿渐变中获取颜色:
Here is an adaptation of Jean-François Corbett's code that takes the color from a red-yellow-green gradient: