简体   繁体   English

根据 3x 单元格 EXCEL 的标准更改行颜色

[英]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.因此,如果 E 列在该行中有Y (例如 E3),则整行将为蓝色,如果 F 有Y ,则为黄色,如果 G 有Y ,则为红色。

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?但是我如何指定哪个TRUE是哪个颜色?

I suggest you to use VBA.我建议你使用 VBA。 Click "Visual Basic" from the "Developer" tab.单击“开发人员”选项卡中的“Visual Basic”。 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.如果您然后粘贴下面的代码并按 F5,您将获得您想要的结果,如下图所示。 I assumed there were 11 lines in my code.我假设我的代码中有 11 行。 You can change the number 11 by yourself.您可以自己更改数字 11。

> 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   

目标

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

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