[英]Conditional formating on an entire row based on contents in one column
I have a table that I want to color the font red in an entire row IF the contents in column N contains the word EMPTY. 我有一个表格,如果第N列的内容包含单词EMPTY,则我想在整行中将字体涂成红色。
For example: 例如:
if N2=EMPTY then 如果N2 =空
Format A2 through AG2 通过AG2格式化A2
.Font.Color = vbRed .Font.Color = vbRed
I would like to do this in VBA, thoughts? 我想在VBA中这样做吗?
Currently I can format the N2 cell but can't figure out how to push this across the entire row. 目前,我可以格式化N2单元格,但无法弄清楚如何将其推入整行。
Just format columns A:AG of the row that you are processing: 只需格式化要处理的行的A:AG列:
Sub test()
Dim r As Long
r = 2
If Cells(r, "N").Value = "EMPTY" Then
Rows(r).Range("A1:AG1").Font.Color = vbRed
End If
End Sub
And, of course, that could be easily be placed into a loop: 而且,当然,可以轻松地将其放入循环中:
Sub test()
Dim r As Long
For r = 2 To 100
If Cells(r, "N").Value = "EMPTY" Then
Rows(r).Range("A1:AG1").Font.Color = vbRed
End If
Next
End Sub
Note: If you wanted to format the entire row, and not just columns A:AG, leave the .Range("A1:AG1")
part out of the statement, so that it just says: 注意:如果要设置整个行的格式,而不仅仅是A:AG列的格式,请将
.Range("A1:AG1")
部分保留在语句的外面,使其仅显示:
Rows(r).Font.Color = vbRed
Based on comments that you don't want to use VBA, just conditional formatting, apply a conditional format based on a formula of =$N1="EMPTY"
in cell A1, and copy that to whatever cells you want it to apply to: 根据您不希望使用VBA的注释,仅进行条件格式设置,在单元格A1中基于
=$N1="EMPTY"
的公式应用条件格式,然后将其复制到您希望将其应用于的任何单元格:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.