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. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
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
-
4 Strange Facts About Тостер За Сандвичи (Awaiting moderation)
by
rosalinepettey6
5 hours, 6 minutes ago -
Windows 11 blocks Chrome 137.0.7151.68, 137.0.7151.69
by
Alex5723
13 hours, 29 minutes ago -
Are Macs immune?
by
Susan Bradley
10 hours, 53 minutes ago -
HP Envy and the Function keys
by
CWBillow
16 hours, 35 minutes ago -
Microsoft : Removal of unwanted drivers from Windows Update
by
Alex5723
1 day ago -
MacOS 26 beta 1 dropped support for Firewire 400/800
by
Alex5723
1 day, 1 hour ago -
Unable to update to version 22h2
by
04om
11 hours, 46 minutes ago -
Windows 11 Insider Preview Build 26100.4482 (24H2) released to Release Preview
by
joep517
1 day, 8 hours ago -
Windows 11 Insider Preview build 27881 released to Canary
by
joep517
1 day, 8 hours ago -
Very Quarrelsome Taskbar!
by
CWBillow
18 hours, 24 minutes ago -
Move OneNote Notebook OFF OneDrive and make it local
by
CWBillow
1 day, 21 hours ago -
Microsoft 365 to block file access via legacy auth protocols by default
by
Alex5723
1 day, 10 hours ago -
Is your battery draining?
by
Susan Bradley
8 hours, 12 minutes ago -
The 16-billion-record data breach that no one’s ever heard of
by
Alex5723
8 hours, 35 minutes ago -
Weasel Words Rule Too Many Data Breach Notifications
by
Nibbled To Death By Ducks
2 days, 1 hour ago -
Windows Command Prompt and Powershell will not open as Administrator
by
Gordski
1 day, 9 hours ago -
Intel Management Engine (Intel ME) Security Issue
by
PL1
1 day, 9 hours ago -
Old Geek Forced to Update. Buy a Win 11 PC? Yikes! How do I cope?
by
RonE22
1 day, 2 hours ago -
National scam day
by
Susan Bradley
8 hours, 45 minutes ago -
macOS Tahoe 26 the end of the road for Intel Macs, OCLP, Hackintosh
by
Alex5723
1 day, 5 hours ago -
Cyberattack on some Washington Post journalists’ email accounts
by
Bob99
3 days, 2 hours ago -
Tools to support internet discussions
by
Kathy Stevens
1 day, 15 hours ago -
How get Group Policy to allow specific Driver to download?
by
Tex265
2 days, 17 hours ago -
AI is good sometimes
by
Susan Bradley
3 days, 9 hours ago -
Mozilla quietly tests Perplexity AI as a New Firefox Search Option
by
Alex5723
2 days, 23 hours ago -
Perplexity Pro free for 12 mos for Samsung Galaxy phones
by
Patricia Grace
4 days, 9 hours ago -
June KB5060842 update broke DHCP server service
by
Alex5723
4 days, 8 hours ago -
AMD Ryzen™ Chipset Driver Release Notes 7.06.02.123
by
Alex5723
4 days, 12 hours ago -
Excessive security alerts
by
WSSebastian42
3 days, 3 hours ago -
* CrystalDiskMark may shorten SSD/USB Memory life
by
Alex5723
4 days, 21 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.