ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Program cell background color (https://www.excelbanter.com/excel-programming/296995-program-cell-background-color.html)

nebb

Program cell background color
 
My Excel worksheet has numerous cells that contain the same type formul
resulting in placing either *, or **, or *** in each of these cells
The data on the sheet is changed each week such that any cell, in an
particular week, might contain any of the three possibilities.
I would like to be able to run a macro that would insert one backgroun
color in each cell that contains one *, another color in those cell
that contain **, and still another background color in those cells tha
contain ***.
Any help would be greatly appreciated

--
Message posted from http://www.ExcelForum.com


Dave Peterson[_3_]

Program cell background color
 
As long as you don't exceed three possibilities, you could use a non-macro
approach.

You could use Format|Conditinal formatting...

Give it three conditions:
Cell value is ="*"
and a nice format
click Add
cell value is ="**"
and another nice format
click add
cell value is = "***"
and a last nice format

(Conditional formatting only supports 3 conditions, though.)

"nebb <" wrote:

My Excel worksheet has numerous cells that contain the same type formula
resulting in placing either *, or **, or *** in each of these cells.
The data on the sheet is changed each week such that any cell, in any
particular week, might contain any of the three possibilities.
I would like to be able to run a macro that would insert one background
color in each cell that contains one *, another color in those cells
that contain **, and still another background color in those cells that
contain ***.
Any help would be greatly appreciated.

---
Message posted from http://www.ExcelForum.com/


--

Dave Peterson


Bob Phillips[_6_]

Program cell background color
 
Here's a macro that can be easily extended should you need more than 3
colours

Sub colours()
Dim iLastRow As Long
Dim i As Long

iLastRow = Cells(Rows.Count, "A").End(xlUp).Row
For i = 1 To iLastRow
With Cells(i, "A")
Select Case .Value
Case "*": .Interior.ColorIndex = 3 'red
Case "**": .Interior.ColorIndex = 5 'blue
Case "***": .Interior.ColorIndex = 10 'green
End Select
End With
Next i

End Sub

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Dave Peterson" wrote in message
...
As long as you don't exceed three possibilities, you could use a non-macro
approach.

You could use Format|Conditinal formatting...

Give it three conditions:
Cell value is ="*"
and a nice format
click Add
cell value is ="**"
and another nice format
click add
cell value is = "***"
and a last nice format

(Conditional formatting only supports 3 conditions, though.)

"nebb <" wrote:

My Excel worksheet has numerous cells that contain the same type formula
resulting in placing either *, or **, or *** in each of these cells.
The data on the sheet is changed each week such that any cell, in any
particular week, might contain any of the three possibilities.
I would like to be able to run a macro that would insert one background
color in each cell that contains one *, another color in those cells
that contain **, and still another background color in those cells that
contain ***.
Any help would be greatly appreciated.

---
Message posted from http://www.ExcelForum.com/


--

Dave Peterson





All times are GMT +1. The time now is 03:15 AM.

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