简体   繁体   English

如果此当前单元格为空白,则使用Excel条件格式公式

[英]Excel conditional formatting formula if THIS current cell is blank

I'm trying to do something that seems simple in concept at first, yet Googling reveals no pages that explain how to do it, NOR are there and emergent pages that say something with the gist of " don't bother because it can't be done ". 我一开始尝试做的是概念上简单的事情,但Google搜索没有显示任何页面解释操作方法,也没有NOR,并且出现了一些新页面,这些内容带有“ 不要打扰,因为它不能完成 ”。 What I'm trying to do is highlight a column of cells in Excel and create a rule that says this ( pseudocode ): 我想要做的是突出显示Excel中的一列单元格,并创建一个表示以下内容( 伪代码 )的规则:

If THIS cell is blank
   Change the text color to white and fill color to Red
   Display the text "[INFO NEEDED]" //(without quotes)

If the cell is not blank, then the rule will not be triggered. 如果单元格不为空,则不会触发该规则。

Unfortunately, when I web search for excel conditional formatting formula "this cell" blank I keep wrong answers of two varieties: 不幸的是,当我在网上搜索excel conditional formatting formula "this cell" blank我留下了两个错误的答案:

  1. "How to format cells based on other cells" AND “如何基于其他单元格格式化单元格”并且

  2. "How to format blank cells" ( but not using a formula approach ) “如何格式化空白单元格”( 但不使用公式方法

To be extra clear: I'm **not* looking for how to do it based on values in other cells, nor with the "Format only cells that contain" method. 需要特别清楚的是:我不是在*寻找*基于其他单元格中的值,也不希望使用“仅格式化包含单元格的格式”的方法。

I realize that it may turn out to be just not possible, but I wanted to run it by the readers on Stack Overflow to see if this can be done, but isn't often, and perhaps gain insight into why. 我意识到可能根本不可能,但是我想让读者在Stack Overflow上运行它,以查看是否可以做到这一点,但并不常见,也许还可以了解原因。

It is not possible to make this pseudocode work using just conditional formatting. 仅使用条件格式无法使该伪代码起作用。 You can accomplish the first part of the requirement, ie, check in the condition formula whether the cell is empty (ISBLANK(address)). 您可以完成需求的第一部分,即检查条件公式是否该单元格为空(ISBLANK(地址))。 You cannot, however, change the value of the cell because: 1) Conditional formatting is dealing just with the formatting; 但是,您不能更改单元格的值,因为:1)条件格式仅处理格式; 2) The cell will no longer be blank after you have inserted the text; 2)插入文本后,单元格将不再为空白; 3) Excell formulas do not allow you to use circular references, ie, the results that depend on the value in the same formula. 3)Excell公式不允许您使用循环引用,即,结果依赖于同一公式中的值。 What you can do is to use VBA to do this (and to change the cell color inside the function instead of referring to conditional formatting). 您可以使用VBA进行此操作(并更改函数内部的单元格颜色,而不是引用条件格式)。 Please find the suggested code below. 请在下面找到建议的代码。 A1 must be replaced with an address of a cell that you need to check, and the file must be saved as .xlsm to enable the macro. A1必须替换为您需要检查的单元格的地址,并且文件必须另存为.xlsm才能启用宏。

Private Sub Worksheet_Change(ByVal Target As Range)
   If (IsEmpty(Range("A1").Value) = True) Then
      Range("A1").Value = "[INFO NEEDED]"
      Range("A1").Interior.Color = vbRed
      Range("A1").Font.Color = vbWhite
    Else
      Range("A1").Interior.Color = vbWhite
      Range("A1").Font.Color = vbBlack
   End If
End Sub

Taking a stab at this: 对此采取行动:

Rather than providing you with this specific solution , I am rather going to try to address the root of your problem . 与其为您提供此特定解决方案 ,不如尝试解决您问题根源 It seems that you want to prevent users from inputting blank cells. 看来您想防止用户输入空白单元格。

Rather than displaying an error message and changing the formatting if a cell is blank, why not just use data validation to simply not even allow blank cells? 为什么不显示错误消息并在单元格为空白的情况下更改格式,为什么不仅仅使用数据验证甚至不允许空白单元格呢?

You can set up data validation to not allow blank cells, and display an error message if a user tries to input a blank cell. 您可以将数据验证设置为不允许空白单元格,并在用户尝试输入空白单元格时显示错误消息。 See below. 见下文。

在此处输入图片说明

在此处输入图片说明

Now if I try to delete the contents of this cell, the following message box appears: 现在,如果我尝试删除此单元格的内容,则会出现以下消息框:

在此处输入图片说明

Again, I realize this doesn't answer your question exactly, but it may provide an alternate solution. 再一次,我意识到这并不能完全回答您的问题,但是它可以提供替代解决方案。

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

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