There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
access audio avg avg 8 bios blue screen boot bsod computer connection cpu crash css dell desktop dma driver drivers dvd email error excel explorer firefox firefox 3 freeze gimp graphics hard drive hardware hijackthis hjt install internet internet explorer itunes keyboard laptop macro malware monitor motherboard network networking outlook outlook 2003 outlook 2007 outlook express pio problem problems router seo server slow sound sp3 spyware trojan usb video virtumonde virus vista vundo windows windows vista windows xp winxp wireless
Business Applications
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Software & Hardware > Business Applications >
Solved: Conditional Formatting Dependant On Cell Background Colour In Microsoft Excel


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

 
Thread Tools
blujein's Avatar
Member with 84 posts.
 
Join Date: May 2008
Location: Australia
Experience: Intermediate
24-Jul-2008, 12:15 AM #1
Question Solved: Conditional Formatting Dependant On Cell Background Colour In Microsoft Excel
Hello,

I have another conditional formatting issue in Microsoft Excel!

In a spreadsheet I'm working on at the moment I have a range of cells that I will, at times, manually give a green background. This is simply a visual aid. These cells also contain a value (a dollar amount). So, in one row, there might be three green cells and four normal cells (with no background), and at the end of that row there would be a cell that needs to calculate the total dollar amount of the cells in the row with a green background.

Can anyone provide me with instructions and information on how to accomplish this?
Aj_old's Avatar
Computer Specs
Senior Member with 604 posts.
 
Join Date: Sep 2007
Location: Moldova
Experience: Intermediate
24-Jul-2008, 02:00 AM #2
2 Questions:
What MS office are you using 2003 or 2007?
Cells get colored in green, based on some conditions, or it can be randomly? (You chose what cell to color and it don't depend on it's value)
The Villan's Avatar
Senior Member with 1,076 posts.
 
Join Date: Feb 2006
Location: Market Rasen, Lincolnshire UK
Experience: Advanced at times
24-Jul-2008, 03:06 AM #3
Using your example above Blujein.

The four normal cells - do they also contain values or are the cells blank?
blujein's Avatar
Member with 84 posts.
 
Join Date: May 2008
Location: Australia
Experience: Intermediate
24-Jul-2008, 04:28 AM #4
The four cells without a background do have a value, yes.

Also, I'm running Microsoft Excel 2003 and the cells with the green background are not getting the green background via a conditional format; they're manually made green as it is purely a visual cue.
Aj_old's Avatar
Computer Specs
Senior Member with 604 posts.
 
Join Date: Sep 2007
Location: Moldova
Experience: Intermediate
24-Jul-2008, 05:44 AM #5
Quote:
Originally Posted by blujein View Post
the cells with the green background are not getting the green background via a conditional format; they're manually made green as it is purely a visual cue.
I understood this, but based on what are you coloring then?
blujein's Avatar
Member with 84 posts.
 
Join Date: May 2008
Location: Australia
Experience: Intermediate
24-Jul-2008, 08:16 AM #6
I'm not sure that I understand what you mean - are you asking why I am making them have a green background? If so, it's because the spreadsheet contains financial information, and the cells with a green background show an amount that is scheduled for payment but not yet finalised. Once it has been finalised, I would remove the green background.
Aj_old's Avatar
Computer Specs
Senior Member with 604 posts.
 
Join Date: Sep 2007
Location: Moldova
Experience: Intermediate
24-Jul-2008, 08:35 AM #7
In this case you need a macro or an User Defined Function to do this!
blujein's Avatar
Member with 84 posts.
 
Join Date: May 2008
Location: Australia
Experience: Intermediate
24-Jul-2008, 08:42 AM #8
Are you able to provide me with some instruction on how to do this?
Aj_old's Avatar
Computer Specs
Senior Member with 604 posts.
 
Join Date: Sep 2007
Location: Moldova
Experience: Intermediate
24-Jul-2008, 09:19 AM #9
put this in a standard module of the workbook you are working with:
Code:
Function Count_by_InteriorColor(ByRef rgRange As Range, ByRef ColorCriteria)
    Dim cel As Range
    Counter = 0
    colorID = ColorCriteria.Interior.ColorIndex
    For Each cel In rgRange
        If Not (IsEmpty(cel)) And cel.Interior.ColorIndex = colorID Then Counter = Counter + 1
    Next
    Count_by_InteriorColor = Counter
End Function
Got to excel, press the function sign and select the User Defined Category, select the function with name "Count_by_InteriorColor" select the range you wanna to count, and in second field ColorCriteria, select a cell that have the same background as the cells you need to be counted, and hit enter

To be able to use this in other workbooks to, paste the code, into a standard module in the personal.xls
the rest is the same, just function name will have personal.xls in front
__________________
The BestS
AJ
slurpee55's Avatar
Computer Specs
Distinguished Member with 3,843 posts.
 
Join Date: Oct 2004
Location: Southwest Iowa....
Experience: Currently stupid...
24-Jul-2008, 09:58 AM #10
bluejin, AJ, once again, has come through. I might suggest that you get a free add-in for Excel called ASAP Utilities from http://www.asap-utilities.com/ .
It will do many of the things you are wanting - for instance, it has a function called CountShades that will count all cells that are colored. If you only want to count certain colors. Many of it's abilities are buried as UDFs, so be sure to investigate those thoroughly once you install it.
__________________
Iowa? I could have sworn this was heaven.
Well, I think I can answer this question most successfully in mime.

My theme song...
blujein's Avatar
Member with 84 posts.
 
Join Date: May 2008
Location: Australia
Experience: Intermediate
24-Jul-2008, 07:11 PM #11
Quote:
Originally Posted by Aj_old View Post
put this in a standard module of the workbook you are working with:
Code:
Function Count_by_InteriorColor(ByRef rgRange As Range, ByRef ColorCriteria)
    Dim cel As Range
    Counter = 0
    colorID = ColorCriteria.Interior.ColorIndex
    For Each cel In rgRange
        If Not (IsEmpty(cel)) And cel.Interior.ColorIndex = colorID Then Counter = Counter + 1
    Next
    Count_by_InteriorColor = Counter
End Function
Got to excel, press the function sign and select the User Defined Category, select the function with name "Count_by_InteriorColor" select the range you wanna to count, and in second field ColorCriteria, select a cell that have the same background as the cells you need to be counted, and hit enter

To be able to use this in other workbooks to, paste the code, into a standard module in the personal.xls
the rest is the same, just function name will have personal.xls in front
This here is great! The only other question I have is whether we can make it count the values in the green cells rather than just count how many green cells there are? For example, if there are dollar values in the green cells, the end cell with the above user defined function would provide the total of the values.
Aj_old's Avatar
Computer Specs
Senior Member with 604 posts.
 
Join Date: Sep 2007
Location: Moldova
Experience: Intermediate
25-Jul-2008, 01:11 AM #12
Quote:
Originally Posted by blujein View Post
This here is great! The only other question I have is whether we can make it count the values in the green cells rather than just count how many green cells there are? For example, if there are dollar values in the green cells, the end cell with the above user defined function would provide the total of the values.
Try this:
Code:
Function Sum_by_InteriorColor(ByRef rgRange As Range, ByRef ColorCriteria)
    Dim cel As Range
    Summ= 0
    colorID = ColorCriteria.Interior.ColorIndex
    For Each cel In rgRange
        If Not (IsEmpty(cel)) And cel.Interior.ColorIndex = colorID Then Summ= summ+ cel.value
    Next
    Sum_by_InteriorColor = Summ
End Function
blujein's Avatar
Member with 84 posts.
 
Join Date: May 2008
Location: Australia
Experience: Intermediate
27-Jul-2008, 07:14 PM #13
That's perfect, however there is still one problem. When I remove the green background (which will happen when the amount is considered paid), the total doesn't reflect it by subtracting that amount - it stays with the total as if the cell still had a green background. What can be done to work around this?
Aj_old's Avatar
Computer Specs
Senior Member with 604 posts.
 
Join Date: Sep 2007
Location: Moldova
Experience: Intermediate
28-Jul-2008, 01:12 AM #14
Quote:
Originally Posted by blujein View Post
That's perfect, however there is still one problem. When I remove the green background (which will happen when the amount is considered paid), the total doesn't reflect it by subtracting that amount - it stays with the total as if the cell still had a green background. What can be done to work around this?
It's because the result is not updated automatically! You need to recalculate the sheet!
blujein's Avatar
Member with 84 posts.
 
Join Date: May 2008
Location: Australia
Experience: Intermediate
28-Jul-2008, 01:47 AM #15
Oh okay - sorry, but how is that done?
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are Off
Refbacks are Off

You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 11:26 PM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.