简体   繁体   中英

Colour a cell range based on another cell's value?

I am trying to write a statement in MS Excel 2013 that does the following:

If cell E3 = "N/A" , make the background colour of cell range F3:N3 = black

If cell E3 = anything else , do nothing

Some sort of conditional formatting? I tried a few options but couldn't get it going? :(

Any suggestions?

Select cells F3 to N3. On the Home Ribbon click Conditional Formatting > New Rule > Use a formula to....

Use this formula

=isna($e3)

Note the placement of the $ sign. Select the Format button and apply a format. Confirm all dialogs.

If you wish to do this with Excel VBA (as per your question tags), then you can use the Interior.Color property of a cell range:

ActiveSheet.Range("F3:N3").Interior.Color = RGB(0,0,0)

If you need to clear the background if cell E3 is not "N/A" then use

ActiveSheet.Range("F3:N3").Interior.ColorIndex = 0

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