简体   繁体   中英

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 ". What I'm trying to do is highlight a column of cells in Excel and create a rule that says this ( pseudocode ):

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:

  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.

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)). You cannot, however, change the value of the cell because: 1) Conditional formatting is dealing just with the formatting; 2) The cell will no longer be blank after you have inserted the text; 3) Excell formulas do not allow you to use circular references, ie, the results that depend on the value in the same formula. 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). 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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