简体   繁体   中英

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?

Like if it returns true then color it green if false color it red

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

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?

Formula for Green

=Sheet3!C35=""

Formula for Red

=Sheet3!C35<>""

Edit: Added picture showing formatting.

在此处输入图片说明

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