简体   繁体   中英

Change row colour based on criteria of 3x cells EXCEL

I want to format the rows to be either red, yellow or blue based on whether one or more cells have been ticked.

So if column E has Y in that row (eg. E3) then the whole row would be blue, if F has Y then it would be yellow and if G has Y then it would be red.

I would normally use:

=IF(G="Y",TRUE,IF(F="Y",TRUE,IF(E="Y",TRUE,FALSE),FALSE)

But how would I specify which TRUE is which colour?

I suggest you to use VBA. Click "Visual Basic" from the "Developer" tab. Then click "Insert" above and add a module. If you then paste the code below and press F5, you will get the result you want as in the photo below. I assumed there were 11 lines in my code. You can change the number 11 by yourself.

> Sub colour()
>     For i = 1 To 11
>         If Cells(i, "E").Value = "Y" Then
>             Cells(i, "E").EntireRow.Interior.Color = vbBlue
>         End If
>         If Cells(i, "F").Value = "Y" Then
>             Cells(i, "F").EntireRow.Interior.Color = vbYellow
>         End If
>         If Cells(i, "G").Value = "Y" Then
>             Cells(i, "G").EntireRow.Interior.Color = vbRed
>         End If
>     Next 
> End Sub   

目标

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