简体   繁体   English

基于单元格中IF公式结果的条件格式

[英]Conditional formatting based on the result of IF formula in the cell

Is there a way we can do conditional formatting based on the result of IF condition present in cell no matter what it returns? 有没有一种方法可以根据单元格中存在的IF条件的结果进行条件格式化,无论它返回什么?

Like if it returns true then color it green if false color it red 就像如果返回true则将其上色为绿色,如果为false则将其上色为红色

The formula looks like this on sheet2 =IF(Sheet3!C35="", Sheet3!B35, Sheet3!C35) it can return any value which is in B or column C that's what makes it hard for me to conditionally format it using hardcoded values or ranges because they are not well defined 该公式在sheet2 =IF(Sheet3!C35="", Sheet3!B35, Sheet3!C35)上看起来像这样,它可以返回B或C列中的任何值,这使我很难使用硬编码有条件地对其进行格式设置值或范围,因为它们的定义不明确

I thought of doing it via a macro like this 我想通过这样的宏来做

Private Sub Worksheet_Change(ByVal Target As Range)
Application.ScreenUpdating = False
Application.EnableEvents = False

    If Target.Cells.Count = 1 And Target.Cells.HasFormula Then
            'Logic to check the if condition
    End If

Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub

Could you just place these conditional rules in the same cell as the if statement? 您可以将这些条件规则与if语句放在同一单元格中吗?

Formula for Green 绿色配方

=Sheet3!C35=""

Formula for Red 红色配方

=Sheet3!C35<>""

Edit: Added picture showing formatting. 编辑:添加图片显示格式。

在此处输入图片说明

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

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