Excel 多条件条件格式化

huangapple go评论79阅读模式
英文:

Excel Conditional Formatting with Multiple Conditions

问题

我有一个与条件格式规则有关的问题。提前警告,我是新学习Excel公式的,所以我已经阅读了很多文档,但还没有解决问题。

我有一个包含以下值的工作表:

让我们称A1:A3为每周地区。

A1单元格 - NC

A2单元格 - TX

A3单元格 - CA

让我们称B1:B3为选择的地区,B4是串联。

B1单元格 - TX

B2单元格 - CA

B3单元格 - NM

B4单元格 - =CONCATENATE(A1:A3)

这周的B4输出将是‘NCTXCA’。我考虑使用=JOIN(“,”,A1:A3)会产生‘NC,TX,CA’,但由于每周区域单元格根据周的位置而变化,当单元格A1:A3为空时,单元格B4不是空白的,并显示单元格中的‘,,’。我认为这是因为它仍然考虑了单元格A1和A2之间以及A2和A3之间的分隔。我希望解决这个问题,因为这会排除文本可能产生其他潜在地区的可能性。例如,在‘NCTXCA’中,您可以看到CT可能是另一个可能会破坏格式的地区。这是一个次要的问题。

进入主要的条件格式问题:

在工作表上,我按顺序设置了以下条件格式规则:

*单元格B1:B3为空

范围 - B1:B3

格式 - 为空

样式 - 背景颜色为蓝色

*单元格B1:B3中的文本位于B4中

范围 - B1:B3

格式 - =IFERROR(FIND(B1, $B$4),FALSE)

样式 - 背景颜色为绿色

*单元格B1:B3中的文本不在B4中

范围 - B1:B3

格式 - =IFERROR(FIND(B1, $B$4),TRUE)

样式 - 背景颜色为红色

*** 问题 ***

这似乎可以检查B1:B3单元格是否为空并将它们设为蓝色,如果文本在B4中并将其设为绿色,如果文本不在B4中并将其设为红色;但是,随着每周区域的变化,A1:A3单元格可能为空并且不包含任何地区。使用当前的格式,当B4为空(因为A1:A3中没有分配任何区域时),B1:B3单元格将变为红色,因为这些单元格中的文本与空白的B4单元格不匹配。是否有一种方式可以使B4为空并且B1:B3单元格包含文本时它们也是蓝色的(因为它们既不对也不错)?

我尝试使用ISBLANK(B4) ,但似乎无法找到我需要用于格式化的公式。

提前感谢!

英文:

I am having an issue with the conditional formatting rules. Forewarning, I am new to learning excel formulas so I have read through a lot of documentation but haven’t been able to solve it.

I have a sheet that has the following values:

Let’s call A1:A3 the weekly areas.

A1 Cell - NC

A2 Cell - TX

A3 Cell - CA

Let’s call B1:B3 the picked areas and B4 is the concatenation.

B1 Cell - TX

B2 Cell - CA

B3 Cell - NM

B4 Cell - =CONCATENATE(A1:A3)

The B4 output for this week for be ‘NCTXCA’. I thought about using =JOIN(“,”,A1:A3) which would produce ‘NC,TX,CA’ but as the weekly area cells change based off of the weeks locations, when cells A1:A3 are blank… Cell B4 is not blank and shows ‘,,’ in the cell. I assume this is because it is still accounting for the separation between Cell A1 and A2 and A2 from A3. I’d like to get this fixed as it eliminates the possibility that the text could produce another potential area. For example, in ‘ NCTXCA’ you can see that CT could be another potential area that could mess up the formatting. That is a secondary question.

On to the main conditional formatting question:

On the sheet I have the following conditional formatting rules in order:

*Cells B1:B3 are blank

Range - B1:B3

Format - is empty

Style - Background color is Blue

*Cell B1:B3 text are in B4

Range - B1:B3

Format - =IFERROR(FIND(B1, $B$4),FALSE)

Style - Background color is Green

*Cell B1:B3 text are not in B4

Range - B1:B3

Format - =IFERROR(FIND(B1, $B$4),TRUE)

Style - Background color is Red

*** QUESTION ***

This does seem to work for checking if the B1:B3 cells are blank and making them Blue, if the text is within B4 and making it Green, if the text is not within B4 and making it Red; however, as the weekly areas change the A1:A3 cells may be blank and not contain any areas. With the current formatting, when B4 is blank (because there aren’t any areas assigned in A1:A3) the B1:B3 cells are red because the text in those cells do not match the empty B4 cell. Is there a way to format the cells so if B4 is blank and the B1:B3 cells contain text they are Blue as well (because they are neither right nor wrong)?

I have tried using ISBLANK(B4) and I can’t seem to figure out the formula I’d need to use for the formatting.

Thanks in advance!

答案1

得分: 3

你的主要问题似乎是:“是否有一种方法可以使单元格格式化,以便如果B4为空,并且B1:B3单元格包含文本,则它们也是蓝色的(因为它们既不正确也不错误)?”

忽略你提到的所有其他格式规则,对于B1:B3包含文本且B4为空的格式条件如下:

=AND(B1<>"",$B$4="")

将此条件应用于B1:B3。这会根据你指定的条件使这些单元格变为蓝色(下面是前两张图片)。AND()要求两个条件同时满足,这在这里是需要的。我会让你自己想办法如何将其与所有其他条件结合起来。

Excel 多条件条件格式化

Excel 多条件条件格式化

使用条件格式,你只需要一个在你想要应用格式时返回TRUE,在任何其他条件下返回FALSE的公式。我通常会在一个单元格中构建这个公式,然后在得到正确结果后将其粘贴到条件格式对话框中(下面是条件公式的示例)。

Excel 多条件条件格式化

英文:

Your main question seems to be: "Is there a way to format the cells so if B4 is blank and the B1:B3 cells contain text they are Blue as well (because they are neither right nor wrong)?"

Ignoring all the other formatting rules you have, a format condition for B1:B3 when they contain text and B4 is blank is this:

=AND(B1&lt;&gt;&quot;&quot;, $B$4=&quot;&quot;)

Apply that to B1:B3. That turns those cells blue under the condition you've specified (first 2 pictures below). The AND() requires that both conditions hold simultaneously, which you need here. I'll let you figure out how to fit it in with all the other conditions.

Excel 多条件条件格式化

Excel 多条件条件格式化

With conditional formatting, all you need is a formula that returns TRUE when you want to turn on a format, and FALSE under any other condition. I often build the formula in a cell, then paste it into the conditional format dialog once I've got it right (below).

Excel 多条件条件格式化

答案2

得分: 1

=ISBLANK($B$4) 是正确的公式。检查你是否使用了绝对引用(美元符号)。同时确保在规则管理器中,ISBLANK 规则位于你的红色规则之上。规则是从上到下应用的,因此满足条件的第一个规则将被使用。

至于你的第二个问题,JOIN 不是一个工作表公式,我猜你是指 TEXTJOINTEXTJOIN 的第二个参数是 ignore_empty。如果你使用 TRUE,它将忽略你的空单元格。

英文:

=ISBLANK($B$4) is the correct formula. Check that you have used absolute references (the dollar signs). And check that the ISBLANK rule is above your red rule in the Rules Manager. The rules are applied from top to bottom, so the first rule that satisfies the criteria will be used.

Excel 多条件条件格式化

To your second question, JOIN is not a worksheet formula, I assume you mean TEXTJOIN? The second argument for TEXTJOIN is ignore_empty. If you use TRUE it will ignore your empty cells.

huangapple
  • 本文由 发表于 2023年5月17日 08:01:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/76267781.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定