简体   繁体   English

Excel:动态条件格式和错误地默认引用

[英]Excel: Dynamic Conditional Formatting and Erroneously Defaulting References

All, I have a two-stage question regarding some slightly complex Conditional Formatting. 所有,关于一些稍微复杂的条件格式,我有两个阶段的问题。

Sample Table below. 下面的样品表。

   A              B        C          D
 1 Options        Choice   Billy      Suzie
 2 Option 1       Dog      Option 1   Option 2
 3 Option 2       Cat 
 4 Option 3       Snake     

Description: 描述:

  • The nature of the table is to provide a visual reference of what option has been selected (dog/cat) for each kid (Billy and Suzie). 该表的性质是为每个孩子(比利和苏西)选择哪种选项(狗/猫)提供直观的参考。
  • Columns A/B are linked and do not change (ie Option 1 is always dog) A / B列已链接且不会更改(即选项1始终为狗)
  • Columns C and D have drop down Menus with a selection of either "Option 1" or "Option 2", and are independent of one another (but can only use elements from the list, generated by Column A) C列和D列具有下拉菜单,其中选择了“选项1”或“选项2”,并且彼此独立(但只能使用由列A生成的列表中的元素)

Goal: 目标:

  • Color Code columns A and B, based on the drop down menu selections in C/DIe Billy is assigned the color blue. 根据C / DIe Billy中的下拉菜单选择,“颜色代码”列A和B被分配为蓝色。 Suzie is assigned pink. Suzie被分配为粉红色。 If I select "Option 1" in Billy's drop down menu, then Column A and B will turn red for "Option 1" and "Dog". 如果我在Billy的下拉菜单中选择“选项1”,则“选项1”和“狗”的列A和B将变为红色。 If Suzie wants a Cat, you can select the option, and Option 2/Cat will highlight Pink. 如果Suzie需要猫,则可以选择选项,然后选项2 /猫将突出显示粉红色。
  • In the event both Billy and Suzie select the same thing, the element is highlighted "Green". 如果Billy和Suzie选择相同的内容,则该元素将突出显示为“绿色”。
  • No selection and the entire thing is grey. 没有选择,整个东西都是灰色的。

Questions: 问题:

  1. I would like to select A1:B4 and generate one conditional formatting statement for each child. 我想选择A1:B4并为每个孩子生成一个条件格式语句。 Ie select them all, and gen. 即全部选中它们,然后生成。 the formatting rule "$A1=$C$1 ---- Highlight Blue". 格式规则“ $ A1 = $ C $ 1 ----高亮显示蓝色”。 And, by generating that rule, A3 and B3 would turn Blue if Billy selected Option 3. Currently, I am having to generate a statement for each row. 并且,通过生成该规则,如果Billy选择了选项3,则A3和B3将变为蓝色。当前,我必须为每一行生成一条语句。 Couple this with the fact that I have to do the three colors, I have to generate 3 rules per Option, rather than just 3 rules total. 再加上必须要做三种颜色的事实,我必须为每个Option生成3条规则,而不是总共3条规则。

    1. If, for instance, this table had MULTIPLE different versions, all on the same page, how could I, again, generate only 3 rules rather than one per line. 例如,如果此表在同一页面上具有多个不同的版本,那么我又怎么能仅生成3条规则,而不是每行一条。 Ie I had "Pets", "Toys" and "Dinner", each with their own options, and Billy and Suzie have a selection list for each category. 也就是说,我有“宠物”,“玩具”和“晚餐”,每个都有自己的选项,而比利和苏西则有每个类别的选择列表。 Can I highlight ALL Options and Choices and only create the 3 rules (one for each highlighted color)? 我可以突出显示所有选项和选择,而仅创建3条规则(每种突出显示的颜色一条)。

Bonus: This is less a question of how and more a question of why: I figured out half of the answer to question 2, and was able to select A1:B1 for each category (pets, toys and dinner) using Ctrl, and create a rule for each highlighted color using the formula "=$A1=$C1". 奖励:这不是一个如何做的问题,而是一个为什么的问题:我找出了问题2的一半答案,并且能够使用Ctrl为每个类别(宠物,玩具和晚餐)选择A1:B1,并创建使用公式“ = $ A1 = $ C1”的每种突出显示颜色的规则。 This made it so to where each category was independent of the other categories (billy selecting a dog wouldn't highlight a bike in a subsequent table, I would have to select bike for billy in that table). 这样一来,每个类别都可以独立于其他类别(在随后的表格中选择一只狗不会突出显示自行车,我必须在该表格中为比利选择自行车)。 BUT, when you click on a cell to add it into the formula box, it automatically gives it an absolute reference ($A$1). 但是,当您单击一个单元格以将其添加到公式框中时,它将自动为其提供绝对引用($ A $ 1)。 I did this, and then would delete the 2nd "$" for each cell. 我这样做了,然后删除每个单元格的第二个“ $”。 Once I hit "Ok" or "Apply", the cell reference would change, without fail, to "$A1048576", ie the bottom cell in that column. 一旦我单击“确定”或“应用”,单元格引用将毫无疑问地更改为“ $ A1048576”,即该列中的底部单元格。 I could manually change the number back to what I wanted, $A1, and it would accept the change and work how I wanted, but the behavior was VERY strange, and I was wondering if anyone knew what was happening/causing it. 我可以手动将数字改回我想要的值,$ A1,它会接受所做的更改并按我的意愿工作,但是这种行为非常奇怪,我想知道是否有人知道发生了什么/造成了什么。

This is a small, representative table for what I am trying to accomplish. 这是我要完成的小型代表表格。 The real data is more complex. 实际数据更为复杂。

Thanks in advance to anyone trying to answer this. 预先感谢任何尝试回答此问题的人。

There are a multitude of questions here, mainly (a) how to achieve without too much effort the various fills given the criteria (each fill potentially a different question) and (b) why certain behaviour. 这里有很多问题,主要是(a)如何在不付出过多努力的情况下实现给定标准的各种填充(每个填充可能会导致一个不同的问题),以及(b)为什么某些行为。 Considering only (a) and specifically your Q 1., first 'standard' fill grey to suit Then select Columns A and B and HOME > Styles - Conditional Formatting, New Rule..., Use a formula to determine which cells to format and Format values where this formula is true: : 仅考虑(a)特别是Q 1.,首先使用“标准”填充灰色以适合,然后选择A列和B列以及HOME>样式-条件格式,新规则..., 使用公式来确定要格式化的单元格格式化此公式为真的值 ::

=AND($D$1="Suzie",$D$2=$A1)  

Format... , select red colour Fill, OK , OK . 格式... ,选择红色填充, 确定确定

Then repeat with: 然后重复:

=AND($C$1="Billy",$C$2=$A1)  

for blue, and for green: 对于蓝色,对于绿色:

=AND($C2=$D2,$A1=C$2,$C2<>$D2)  

In general, you must expect one rule per colour. 通常,您必须期望每种颜色有一个规则。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM