Is it possible to program a cell fill color to change to one color or another based on certain criteria. For example, is it possible to setup up a stoplight alert system whereby the cell displays green if the difference between two numbers is between certain values, and red or orange when other criteria are met?
![]() |
Patch reliability is unclear, but widespread attacks make patching prudent. Go ahead and patch, but watch out for potential problems. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
-
Logic Based Color Display (Office 2003)
Home » Forums » AskWoody support » Productivity software by function » MS Excel and spreadsheet help » Logic Based Color Display (Office 2003)
- This topic has 10 replies, 2 voices, and was last updated 17 years, 11 months ago.
Viewing 1 reply threadAuthorReplies-
WSHansV
AskWoody LoungerJuly 7, 2007 at 11:12 am #1071069You can use conditional formatting:
– Select cell D2.
– Set the fill color to orange (this will be the default).
– Select Format | Conditional Formatting…
– Select ‘Cell value is’ from the first dropdown (the default), ‘less than’ from the second dropdown, and enter -5 in the box next to it.
– Click Format…
– Activate the Pattern tab and select red as fill color, then click OK.
– Click Add >>
– Select ‘Cell value is’ from the first dropdown (the default), ‘greater than’ from the second dropdown, and enter 5 in the box next to it.
– Click Format…
– Activate the Pattern tab and select green as fill color, then click OK.
– Click OK.Note: you may want to change the number format so that negative numbers aren’t displayed in red – red on red is invisible!
See attached version.
-
WSHansV
AskWoody LoungerJuly 7, 2007 at 11:15 am #1071070Additional comment:
It wasn’t clear from your worksheet how you want the cell to be colored if its value is exactly equal to -5 or +5. Depending on your preference, you can use ‘less than or equal to’ instead of ‘less than’ and ‘greater than or equal to’ instead of ‘greater than’ in the Conditional Formatting dialog.
-
WSeuler
AskWoody LoungerJuly 7, 2007 at 11:24 am #1071071you cannot imagine how much I appreciate your responsiveness ……. and how silly I feel for not having found this myself …… each time I pull down the format menu the option stares me in the face …. simple as pie she said .. yep, in the future I will most certainly try a little harder on the self help tread mill before conjuring the masters … thanks again …….
-
WSeuler
AskWoody LoungerJuly 9, 2007 at 10:30 am #1071200Can the same funcionality enabling conditional formating applied to cells be applied to bar sets or individual bars in a horizontal bar chart as shown in the attached? Specifically, the values in HSE Column Z are represented in yellow colored bars of HSE Chart as positive values. Absolute values have been used to overcome chart limitations . However, for analytic purposes, it is necessary to know where the values fall within the same ranges set for the conditional formating in HSE Column Z. i.e. it is desired to produce the same conditional color changes in the HSE Chart Bars that is achieved in HSE Column Z cells.
-
WSHansV
AskWoody LoungerJuly 9, 2007 at 10:56 am #1071203Charts don’t have conditional formatting, so you’ll need to use a macro. Try the following macro (you’ll have to run it again when the data change):
Sub FillSeries()
Dim i As Integer
Dim intColorIndex As Integer
For i = 1 To 20
Select Case Worksheets(“HSE Chart Data”).Cells(11, i + 1)
Case Is = Worksheets(” HSE”).Range(“U2”)
intColorIndex = 4 ‘ green
Case Else
intColorIndex = 6 ‘ yellow
End Select
Worksheets(“HSE Chart”).ChartObjects(1).Chart. _
SeriesCollection(“ABS(DELTA %)”).Points(i). _
Interior.ColorIndex = intColorIndex
Next i
End Sub -
WSeuler
AskWoody LoungerJuly 9, 2007 at 12:36 pm #1071228In a few quick key strokes you have exceeded my capability with Excel. Back in the days of Quattro, I may have been able to figure out how to put your work to work. However, I must now revert to standard references for: where and how to record macros; and where and how to use them ……. I haven’t a clue how to get the macro to operate on the chart …. so I have to ask for some very basic help to get this macro to function or ask for a quick reference already written to do the same thing …..
-
WSHansV
AskWoody LoungerJuly 9, 2007 at 12:43 pm #1071238This macro is highly specific, so you should store it in the workbook itself. Here are step-by-step instructions:
– In Excel, select Tools | Macro | Visual Basic Editor or press Alt+F11.
– In the Visual Basic Editor, select Insert | Module.
– Switch to your browser.
– Select the code from my previous reply (from Sub up to and including End Sub).
– Press Ctrl+C to copy the code.
– Switch back to the Visual Basic Editor.
– Press Ctrl+V to paste the code.
– One way to run the macro is to put the insertion point anywhere in the code and to press F5.
– To run the macro from Excel: select Tools | Macro | Macros…, select FillSeries from the list and click Run. -
WSeuler
AskWoody LoungerJuly 9, 2007 at 1:52 pm #1071247Ok … this works great ….. let me see if I have the syntax sorted ………… I assume that the ( ‘ ) in the line means that anything following is a comment …. so I will write what I think each line does (accordingly) in an effort to show that I can extend the logic to other situtations (umm looks like the lounge lizard out to lunch & is making me wish I could go to dinner too …… but I will finish this first):
Sub FillSeries() ‘ name of macro
Dim i As Integer ‘ establishes i’s identity
Dim intColorIndex As Integer ‘ this sets a vector called interColorIndex as an integer …… did you make up this name …….. just don’t know how this is selected or where name comes from
For i = 1 To 20 ‘ sets loop for number of data columns in chart data table
Select Case Worksheets(“HSE Chart Data”).Cells(11, i + 1) ‘ conditional routine for selecting which color to display
Case Is = Worksheets(” HSE”).Range(“U2”) ‘ sets interColorIndex vector (11,i+1) to 4 if (“HSE Chart Data”).Cells(11, i + 1) is in this range
intColorIndex = 4 ‘ green
Case Else ‘ ‘ sets interColorIndex vector (11,i+1) to 6 if (“HSE Chart Data”).Cells(11, i + 1) is in this range
intColorIndex = 6 ‘ yellow
End Select ‘ ends selction routine
Worksheets(“HSE Chart”).ChartObjects(1).Chart. _ ‘ id’s the object on which the macro acts – don’t know how to find name of objects – change tab name & object id for modification
SeriesCollection(“ABS(DELTA %)”).Points(i). _ ‘ id’s the series for changing color — in any case, only have to change series name, all else can remain the same
Interior.ColorIndex = intColorIndex ‘ must be inside knowlegde for series fill color coding …….. in any case this does not need to be modified … i think !!
Next i ‘ round and round until i = 20
End SubWill you please comment …….. the only things I am not sure about is how to ID an object name and where the name ” intColorIndex ” comes from ……. where may I find the names of objects and where may I find a list of variable names for Excel elements like intColorIndex ??
-
WSHansV
AskWoody LoungerJuly 9, 2007 at 2:13 pm #1071248The lines beginning with Dim at the beginning are declarations. They tell Visual Basic that I am going to use variables named i and intColorIndex, both of type Integer (i.e. they can contain whole numbers from -32,768 to +32,767). I chose the names i and intColorIndex, I could have named them John and Mary instead.
The lines
Worksheets(“HSE Chart”).ChartObjects(1).Chart. _
SeriesCollection(“ABS(DELTA %)”).Points(i). _
Interior.ColorIndex = intColorIndexform one instruction; the space and underscore _ at the beginning of the first two lines tell Visual Basic that the instruction isn’t finished yet, and that it will be continued on the next line.
I did this only to increase readability, it is not essential. I could also have written itWorksheets(“HSE Chart”).ChartObjects(1).Chart.SeriesCollection(“ABS(DELTA %)”).Points(i).Interior.ColorIndex = intColorIndex
It says:
– Take the sheet named HSE Chart.
– Take the first (and in this example only) chart object on the sheet.
– Take the actual chart in this chart object.
– Take the data series named ABS(DELTA %).
– Take the i-th point (bar) of this data series
– Take the interior of this bar.
– Set the ColorIndex of this bar to the value of intColorIndex, which has been set to 3, 4 or 6 higher up in the code.Click in the word ColorIndex and press F1 to get help on this keyword. ColorIndex is a number that specifies a color from Excel’s color palette:
1 = black
2 = white
3 = red
4 = green
5 = blue
6 = yellow
etc.You can also click in words such as Worksheets, ChartObjects, SeriesCollection etc. and press F1 for help. This won’t work if you click in the word intColorIndex and press F1, because intColorIndex is a name I made up.
-
WSeuler
AskWoody LoungerJuly 9, 2007 at 2:26 pm #1071249what a guy .. thanks ……. I already dummied up another sheet and chart set and got the bar colors to change as expected ….. the last time I programmed anything was with Fortran 4 and although I am a little rusty (an understatement) …. things are actually making sense ….. have a great day (night or whatever it is where you are) … I’m going to dinner …..
-
-
-
-
Viewing 1 reply thread -

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
Does Your State Reveal Who’s Been Hacked?
by
Nibbled To Death By Ducks
12 minutes ago -
A one-year extension to Windows 10 โ almost free!
by
Susan Bradley
7 minutes ago -
Windows Configuration Update (KB5062324) โ June 2025
by
Alex5723
8 minutes ago -
A federal judge sides with Anthropic in lawsuit over training AI
by
Alex5723
5 hours, 5 minutes ago -
Name of MS Word Formatting Feature
by
John Baum
6 hours, 14 minutes ago -
InControl Failure?
by
Casey H
12 hours, 10 minutes ago -
Microsoft : Free 1 year support for Windows 10 after EOL
by
Alex5723
1 hour, 30 minutes ago -
MS-DEFCON 3: Businesses must tread carefully
by
Susan Bradley
3 hours, 46 minutes ago -
McLaren Health Care says data breach impacts 743,000 patients
by
Nibbled To Death By Ducks
1 day, 4 hours ago -
WhatsApp banned on House staffers’ devices
by
Alex5723
23 hours, 7 minutes ago -
Is your device eligible?
by
Susan Bradley
1 day, 7 hours ago -
Windows 11 Insider Preview build 26200.5661 released to DEV
by
joep517
1 day, 13 hours ago -
Windows 11 Insider Preview build 26120.4452 (24H2) released to BETA
by
joep517
1 day, 13 hours ago -
Hello Windows…My Problem is Windows Hello…
by
rdleib
1 day, 14 hours ago -
New Canon Printer Wants Data Sent
by
Win7and10
1 day, 14 hours ago -
I set up passkeys for my Microsoft account
by
Lance Whitney
58 minutes ago -
AI is for everyone
by
Peter Deegan
1 day, 14 hours ago -
Terabyte update 2025
by
Will Fastie
1 day, 8 hours ago -
Migrating from Windows 10 to Windows 11
by
Susan Bradley
11 hours, 20 minutes ago -
Lost sound after the upgrade to 24H2?
by
Susan Bradley
8 hours, 44 minutes ago -
How to move 10GB of data in C:\ProgramData\Package Cache ?
by
Alex5723
17 hours, 6 minutes ago -
Plugged in 24-7
by
CWBillow
1 day, 23 hours ago -
Netflix, Apple, BofA websites hijacked with fake help-desk numbers
by
Nibbled To Death By Ducks
3 days, 2 hours ago -
Have Copilot there but not taking over the screen in Word
by
CWBillow
2 days, 23 hours ago -
Windows 11 blocks Chrome 137.0.7151.68, 137.0.7151.69
by
Alex5723
4 days, 17 hours ago -
Are Macs immune?
by
Susan Bradley
1 day, 9 hours ago -
HP Envy and the Function keys
by
CWBillow
4 days, 1 hour ago -
Microsoft : Removal of unwanted drivers from Windows Update
by
Alex5723
1 day, 18 hours ago -
MacOS 26 beta 1 dropped support for Firewire 400/800
by
Alex5723
5 days, 5 hours ago -
Unable to update to version 22h2
by
04om
2 days, 13 hours ago
Recent blog posts
Key Links
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.