Sorry, I am new at MS Excel.
I want to set cell A1 color to red if cell G1 is green
and the same time
I want to set cell A1 color to yellow if cell F1 is not empty
If two rules are true, priority should have the second one. If no rule is true, nothing should be done with cell.
How to do that?
Are you familiar with VBA? You can use the code below. If you are not familiar with VBA, use the conditional formatting option.
Conditional formating:
VBA: You can activate cells with
Range("A1")
Each cell has several parameters like colors or values, that you can read and edit.
Range("A1").Value 'Value
Range("A1").Interior.ColorIndex 'Color of cells
Code for your requirements could look like
If Range("G1").Interior.ColorIndex = 4 then '4 = color code for green
Range("A1").Interior.ColorIndex = 3 '3 = color code for red
End If
If (Range("F1").Value = 0 Then
Range("A1").Interior.Colorindex = 6 '6 = color code for yellow
End If
You can find the color-codes here: Microsoft Docs Color Codes
You'll need to use VBA code to trigger that first rule, because conditional formatting won't pick up on other cells' colours. Newbie guide:
If ThisWorksheet.Range("F1").Value <> "" Then
ThisWorksheet.Range("A1").Interior.Color = vbYellow
ElseIf ThisWorksheet.Range("G1").Interior.Colour = vbGreen Then
ThisWorksheet.Range("A1").Interior.Colour = vbRed
End If
Bear in mind that it's checking if G1 is vbGreen
- Excel is very rigid and this won't trigger on just any shade of green. Test it and see if it works.
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.