ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Change cell color (https://www.excelbanter.com/excel-programming/441820-change-cell-color.html)

Johan

Change cell color
 
How do i write a macro or VBA program that will change the color of a cell
based on set conditions?

eg. if the cell value <20 then change the color to red.

Jacob Skaria

Change cell color
 
Try the below

With Selection
.FormatConditions.Delete
.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=AND(RC<"""",RC<20)"
.FormatConditions(1).Interior.ColorIndex = 3
End With

--
Jacob (MVP - Excel)


"Johan" wrote:

How do i write a macro or VBA program that will change the color of a cell
based on set conditions?

eg. if the cell value <20 then change the color to red.


Simon Lloyd[_1340_]

Change cell color
 

It's not a good idea to use vba if you don't have to, Excels own built
in conditional format function is faster and more efficient, although on
very large spreadsheets can cause a problem.


Johan;703659 Wrote:

How do i write a macro or VBA program that will change the color of a
cell
based on set conditions?

eg. if the cell value <20 then change the color to red.


--
Simon Lloyd

Regards,
Simon Lloyd
'Excel Chat' (http://www.thecodecage.com/forumz/chat.php)
------------------------------------------------------------------------
Simon Lloyd's Profile: http://www.thecodecage.com/forumz/member.php?u=1
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=196874

http://www.thecodecage.com/forumz



All times are GMT +1. The time now is 11:48 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com