简体   繁体   English

在Excel中,如果单元格值为X,则高亮显示行和列

[英]In Excel, highlight row and column if cells value is X

I want to apply a global rule to an excel sheet such that if a specific cell's value is, say, -1 , then the corresponding row and column will be highlighted. 我想将全局规则应用于excel表,这样,如果特定单元格的值是-1 ,则相应的行和列将突出显示。

The reason behind: Each row is automatically filled (using queries from a data base). 背后的原因:每行都会自动填充(使用数据库中的查询)。 Since each line is MUCH longer than the screen's width, I want both row and column to be highlighted in case a value in one of the cells is -1 . 由于每行比屏幕的宽度长很多,因此我希望行和列都高亮显示,以防其中一个单元格的值为-1 I consider this value globally forbidden. 我认为此值在全球范围内都是禁止的。

Are you sure you want to use VBA for this? 您确定要为此使用VBA吗? This can easily be done in Excel itself. 这可以在Excel本身中轻松完成。 Select the column, go to "Conditional Formatting" in the ribbon. 选择列,转到功能区中的“条件格式”。 Select "New Rule" and "Use a formula to determine which cells to format". 选择“新规则”和“使用公式来确定要格式化的单元格”。 Add the format (cell color, for example) and enter =A1="-1" as formula. 添加格式(例如,单元格颜色)并输入= A1 =“-1”作为公式。 That should do the trick. 这应该够了吧。

With two CF rules (say each with Applies to of =$A:$Z) 有两个CF规则(例如,每个规则适用于= $ A:$ Z)

=NOT(ISERROR(MATCH(-1,A1:Z1,0))) 

and

=NOT(ISERROR(MATCH(-1,A1:A100)))   

the first (in sequence of application - orange in the example) will highlight rows containing cells filled with -1 from the extreme left (assuming LTR) to the last cell in the row containing a cell filled with -1 and the second (yellow in the example) will highlight columns containing cells filled with -1 down to one row less than the last cell in the column filed with -1 : 第一(在应用程序的序列-在该示例中橙色)将突出含有填充单元格的行-1从最左端(假设LTR)填充有含有细胞的行中的最后一个单元-1和第二(黄色(示例)将突出显示包含填充有-1的单元格的列,比包含-1的列中的最后一个单元格少一行:

SO25245326示例

For row highlighting I created the rule: 为了突出显示行,我创建了规则:

=MATCH(-1,A:A,0)

and for column highlighting: 对于列突出显示:

=MATCH(-1,1:1,0)

Finally I let the two rules apply to the range of interest. 最后,我让这两个规则适用于兴趣范围。 For example: =$A:$AP 例如: =$A:$AP

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

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