简体   繁体   中英

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.

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 . I consider this value globally forbidden.

Are you sure you want to use VBA for this? This can easily be done in Excel itself. 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. That should do the trick.

With two CF rules (say each with Applies to of =$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 :

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

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