ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   macro for formatting/colour cells (https://www.excelbanter.com/excel-programming/422785-macro-formatting-colour-cells.html)

Mayte

macro for formatting/colour cells
 
is there a way to use a macro for conditional formatting?

I have to colour a cell if the value met one of 2 conditionals: "TOP" or
"LOW".

in Sheet 1, I have all the values (E6:E256)
...these values in sheet1 are actually formulas pulling from other sheets
in the same book.
in Sheet 2, I have whether those value are TOP (T6:T256) or LOW (U6:U256)

sample:
E6 in sheet1 has a value of 98% and T6 in sheet2 marks it as TOP so, E6 in
sheet1 should be green
E7 in sheet1 has a value of 5% and U7 in sheet2 marks it as LOW so, E7 in
sheet1 should be red

any ideas how to do this would be greatly appreciate it!

cheers,
Mayte

JLGWhiz

macro for formatting/colour cells
 
You can call up the Conditional Formatting dialogs box in VBA with:

CF = Application.Dialogs(xlDialogConditionalFormatting) .Show

You can also use If statements to do the coloring like:

If ActiveSheet.Range("E6").Value = .98 Then
Range("E6").Interior.ColorIndex = 10
End If

The advantage of using the CF color is that it automatically reverts to no
fill if the criteria is not met. The disadvantage is that if you want to
write code based on the color of the cell, it gets pretty complex. The CF
interior color is on a different object level than the range interior color
and is not necessarily visible even though the CF setting indicates the
color. To get a true color value for CF, you have to evaluate whether the
cell value meets the CF criteria to turn the color on.

"Mayte" wrote:

is there a way to use a macro for conditional formatting?

I have to colour a cell if the value met one of 2 conditionals: "TOP" or
"LOW".

in Sheet 1, I have all the values (E6:E256)
...these values in sheet1 are actually formulas pulling from other sheets
in the same book.
in Sheet 2, I have whether those value are TOP (T6:T256) or LOW (U6:U256)

sample:
E6 in sheet1 has a value of 98% and T6 in sheet2 marks it as TOP so, E6 in
sheet1 should be green
E7 in sheet1 has a value of 5% and U7 in sheet2 marks it as LOW so, E7 in
sheet1 should be red

any ideas how to do this would be greatly appreciate it!

cheers,
Mayte


Mayte

macro for formatting/colour cells
 
thanks!


All times are GMT +1. The time now is 05:05 PM.

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