Google Answers Logo
View Question
 
Q: conditional formatting of cells in excel ( No Answer,   5 Comments )
Question  
Subject: conditional formatting of cells in excel
Category: Computers > Software
Asked by: googa-ga
List Price: $5.00
Posted: 20 Sep 2002 09:38 PDT
Expires: 20 Oct 2002 09:38 PDT
Question ID: 67275
Is there a way to format a cell in an excel 2000 spreadsheet to add up
the values in all the cells on a spreadsheet (or part thereof) given a
particular background colour? I'm using background colour to highlight
cells that pertain
to the same thing, and they are not necessarily in a neat row or
column.
Answer  
There is no answer at this time.

Comments  
Subject: Re: conditional formatting of cells in excel
From: mwalcoff-ga on 20 Sep 2002 10:23 PDT
 
There might be, but here is what I would do.

Create a new column next to the one you're seeking information on.
Assign a number for each color you're using to sort the data and put
that number in the new column. Then sort your data by the new column.
Now you can add up each of the types of data easily simply by
selecting the cells of a given type and looking at the sum in the
bottom-right. When you're done writing down those totals, undo the
sort and hide the new column.
Subject: Re: conditional formatting of cells in excel
From: calebu2-ga on 20 Sep 2002 10:25 PDT
 
googa,

I don't have the experience to give you the full answer but here's
what I know :

You can't write an equation that references the colors of cells
(something like =sum(colorof(A1:G23)). There isn't any direct way of
referencing the formatting of a cell from within an excel equation.

However there is probably a way that you can write a macro/module that
uses the Worksheets.Range.Interior.ColorIndex property in visual basic
to add up the colors in the cells. Unfortunately I can't go into it
more otherwise I'd give you an answer rather than a comment - but
hopefully this comment will help a different researcher give you the
solution you need.

calebu2-ga
Subject: Re: conditional formatting of cells in excel
From: rac-ga on 21 Sep 2002 00:43 PDT
 
Hi googa,
          Please correct me If I understand the question correctly.
"You want a function which will total all the cells in a range which
have the same background color."

As I know Excel don't have such a built in function. But you can
easily create
your own function having that functionality. The following code will
do the trick. Yes, It is based on calebu2-ga as suggested in his
comments.
----------
Function CFmt(RangeInQuotes, ColorIndex)

Dim Total As Double
Set Acell = Range(RangeInQuotes)
'Loop each cell in the range and if cell background eq to color index
sum it
For Each cell In Acell
    If cell.Interior.ColorIndex = ColorIndex Then
          Total = Total + cell.Value
    End If
Next

CFmt = Total
---------------------

In the work book from the Tools menu Select Macro-->VisualBasicEditor.
If Code window is not displayed select Code from the VisualBasicEditor
Viewmenu.

Copy the above code from Function to End Function in the excel
workbook.
Save it.
Now this function will come as part of excel built in function with
name CFmt

Here is a exmaple which tells How to use the function.
If you want to add all cells in the range of "A1:D50" with a
background color
Blue(Color index = 5) and put the total value in cell "F5".

Then select the cell F5
Select fx( Function) from the Toolbar or "Function" from the insert
menu
Select All from the functin Category List
Select CFmt from the Function Name List
Fill the parameters requested
1.RangeInQuotes - Give including quote "A1:D50"
2.ColorIndex - In excel each background color is internally
represented by a number.Give the color index value for blue = 5 (If
you don't know the color index for a background color, easy way is
record a macro while selecting a color and then view(edit) the
recorded macro to get the color Index)
your result will be displayed in the F5 cell.

In this way the function is available only with that workbook.

If you want the function to be available whenever you use Microsoft
Excel,
store the function in the Personal Macro Workbook in the XLStart
folder.
In your folder If a personal workbook is not already there create a
new work book and save as Personal.xls in the XLStart folder.

You can hide the personal.xls by selecting the Hide from the window
menu

Hope this will solve your problem.

Regards,
RAC
Subject: Re: conditional formatting of cells in excel
From: rac-ga on 21 Sep 2002 00:55 PDT
 
Hi 
Please note the code
'Loop each cell in the range and if cell background eq to color index
sum it
should be in a single line. When i posted it got word wraped to the second line.

Regards,
RAC
Subject: Re: conditional formatting of cells in excel
From: webadept-ga on 05 Oct 2002 22:07 PDT
 
Hi, Did any of these comments answer your question? If so could you
please let us know or close it, we would like to make sure that your
quesion is answered, but don't want to offer a Researcher answer if
you no longer need the research done.

Thanks, 

webadept-ga

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy