MrExcel Message Board

Go Back   MrExcel Message Board > Question Forums > Excel Questions

Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only.

Reply
 
Thread Tools Display Modes
Old Feb 23rd, 2002, 02:08 PM   #1
jimi143
New Member
 
Join Date: Feb 2002
Posts: 6
Default

I have a long range of cells in which the cell text is formatted in different colors. Has anyone created a custom function that can return the number of cells in a range that the text is formatted in a certain color (red, blue, black, etc.)?

Thanks,
Jim
jimi143 is offline   Reply With Quote
Old Feb 23rd, 2002, 02:29 PM   #2
Aladin Akyurek
MrExcel MVP
 
Aladin Akyurek's Avatar
 
Join Date: Feb 2002
Location: The Hague
Posts: 50,317
Default

Quote:
On 2002-02-23 13:08, jimi143 wrote:
I have a long range of cells in which the cell text is formatted in different colors. Has anyone created a custom function that can return the number of cells in a range that the text is formatted in a certain color (red, blue, black, etc.)?

Thanks,
Jim
What condition/criterion is used to format the text in a given cell as red?

Aladin Akyurek is offline   Reply With Quote
Old Feb 23rd, 2002, 02:35 PM   #3
jimi143
New Member
 
Join Date: Feb 2002
Posts: 6
Default

The text color of the cell is user defined using the standard colors available in Excel. I would like to put a formula at the bottom of a long range of cells that counts the number of cells in the above range that have red text formatting.

Thanks,

Jim
jimi143 is offline   Reply With Quote
Old Feb 23rd, 2002, 02:40 PM   #4
Jack in the UK
Board Regular
 
Join Date: Feb 2002
Posts: 3,064
Default

Hi

I answered this heavly on the old boad with VBA to do just this:

A friend Ivan F Moala edited it to colour of text .. have a look post answet by me and then Ivan, will be in first archive, the original code was by a great friend in Western Australia Dave Hawley http://www.ozgrid.com under vba section.

Credit to he guys who did the real work, have a look at both, ill see if i can find the code as well



_________________
Good Luck
HTH

Rdgs
==========
Jack in the UK

[ This Message was edited by: Jack in the UK on 2002-02-24 14:27 ]
Jack in the UK is offline   Reply With Quote
Old Feb 23rd, 2002, 02:46 PM   #5
Aladin Akyurek
MrExcel MVP
 
Aladin Akyurek's Avatar
 
Join Date: Feb 2002
Location: The Hague
Posts: 50,317
Default

Quote:
On 2002-02-23 13:35, jimi143 wrote:
The text color of the cell is user defined using the standard colors available in Excel. I would like to put a formula at the bottom of a long range of cells that counts the number of cells in the above range that have red text formatting.

Thanks,

Jim
User-defined, meaning: user makes the text red without using any known/explicit criterion?

Jim: If so, you'll need VBA-code to obtain desired counts. The Archives of the board has some code for similar situations.

Aladin



[ This Message was edited by: Aladin Akyurek on 2002-02-23 13:55 ]
Aladin Akyurek is offline   Reply With Quote
Old Feb 23rd, 2002, 02:53 PM   #6
NateO
Legend
 
NateO's Avatar
 
Join Date: Feb 2002
Location: Minneapolis, Mn, USA
Posts: 9,704
Default

Jimi,

If you bury this in a normal module in your visual basic editor:

Function SumByColor(InputRange As Range, ColorRange As Range) As Double
Dim cl As Range, TempSum As Double, ColorIndex As Integer
ColorIndex = ColorRange.Cells(1, 1).Font.ColorIndex
TempSum = 0
On Error Resume Next
For Each cl In InputRange.Cells
If cl.Font.ColorIndex = ColorIndex Then TempSum = TempSum + cl.Value
Next cl
On Error GoTo 0
Set cl = Nothing
SumByColor = TempSum
End Function

And use the following formula:

=SumByColor(A3:A9,A1)

Where the first paramter is the range to sum and the second is the range that has the font color you want to evaluate against.

Hope this helps. Cheers,

Nate


__________________
Regards,
Nate Oliver
Microsoft Excel MVP
Nate's Excel Blog
NateO is offline   Reply With Quote
Old Feb 23rd, 2002, 03:01 PM   #7
Mudface
MrExcel MVP
 
Join Date: Feb 2002
Location: Sunny, spring-like Hull
Posts: 3,339
Default

Put this into a normal module. Call the function by typing =TURNED(yourrange) where yourrange is say A1:A10. You could bundle this up as an Add-In, too, so it's available on to all Excel files on your machine. Shout out if you want to know how to do this.

Public Function Turned(MyRng As Range) As String

For Each c In MyRng
If c.Font.ColorIndex = 3 And c.Value <> "" Then Red = Red + 1
If c.Font.ColorIndex = 32 And c.Value <> "" Then blue = blue + 1
If c.Font.ColorIndex = xlColorIndexAutomatic And c.Value <> "" Then black = black + 1
Next c

Turned = Red & " red " & blue & " blue " & black & " black"

End Function


Edit- Sorry, Nate, didn't realise you'd already answered this, the above is my first ever function and my beer-sodden brain took a while to get around it

[ This Message was edited by: Mudface on 2002-02-23 14:12 ]
Mudface is offline   Reply With Quote
Old Feb 23rd, 2002, 03:05 PM   #8
NateO
Legend
 
NateO's Avatar
 
Join Date: Feb 2002
Location: Minneapolis, Mn, USA
Posts: 9,704
Default

I suppose it would be more helpful if I answered the question, sorry about that. Same deal, put the following in a normal module:

Function CountByColor(InputRange As Range, ColorRange As Range) As Double
Dim cl As Range, TempCount As Double, ColorIndex As Integer
ColorIndex = ColorRange.Cells(1, 1).Font.ColorIndex
TempCount = 0
On Error Resume Next
For Each cl In InputRange.Cells
If cl.Font.ColorIndex = ColorIndex Then TempCount = TempCount + 1
Next cl
On Error GoTo 0
Set cl = Nothing
CountByColor = TempCount
End Function

Now use the following formula:

=CountByColor(A3:A9,A1)

Where the first paramter is the range to count and cell a1 has the font criteria to evaluate against (this cell must have a value).

HTH. Cheers, Nate
__________________
Regards,
Nate Oliver
Microsoft Excel MVP
Nate's Excel Blog
NateO is offline   Reply With Quote
Old Feb 23rd, 2002, 03:50 PM   #9
jimi143
New Member
 
Join Date: Feb 2002
Posts: 6
Default

THANKS NATE!

I have added one little piece to the code to disregard empty cells. I have one more question that you might be able to help me with.

The formula works great the first time you run it, but if a cell text color is changed from red to another color after that, the result does not change. Is there an additional step that I put into my code that checks for changes to the cells prompts it to recount?

Function CountByColor(InputRange As Range, ColorRange As Range) As Double
Dim cl As Range, TempCount As Double, ColorIndex As Integer
ColorIndex = ColorRange.Cells(1, 1).Font.ColorIndex
TempCount = 0
On Error Resume Next
For Each cl In InputRange.Cells
If cl.Value <> "" And cl.Font.ColorIndex = ColorIndex Then TempCount = TempCount + 1
Next cl
On Error GoTo 0
Set cl = Nothing
CountByColor = TempCount
End Function

Thanks again,

Jim
jimi143 is offline   Reply With Quote
Old Feb 23rd, 2002, 05:44 PM   #10
NateO
Legend
 
NateO's Avatar
 
Join Date: Feb 2002
Location: Minneapolis, Mn, USA
Posts: 9,704
Default

I'm having some trouble with this as well. This formula's not too keen with even a manual re-calc.

I wonder if there's an event procedure you would do that would rewrite the formula to the appropriate cell, like workbook_close or sheetdeactive or selectionchange where:

range(YourRange) = "=CountByColor(A3:A9,A1)"

or call the function in the sub and return the value:

range("a40") = CountByColor(range("a3:9"),range("a1"))

Could do a workbook_open and ontime procedure combination to have the result refresh every few seconds....

Not perfect....

Cheers, Nate

[ This Message was edited by: NateO on 2002-02-25 08:44 ]
NateO is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

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 On

Forum Jump


All times are GMT -4. The time now is 01:52 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
All contents Copyright 1998-2012 by MrExcel Consulting.
diabetic desserts recipes recipes Diabetic Soups Holiday Pizza Recipes Popcorn Recipes Recipes For Microwave Pasta Recipes Casserole Recipes Chili Recipes Curry Recipes Crockpot Recipes Apples Recipes Bread Recipes Vegetarian Recipes Vegetable recipes Desserts Recipes Appetizers Ethnic Recipes Meat Dishes Barbecue Recipes Sauces Recipes Marinade Recipes Low Fat Recipes Frugal Gourmet Kitchen Classics Recipes On The Grill Cook Books Seafood Recipes Cajun Recipes Breads Low Fat Low Fat Breads Bread Machine Recipes Yeast Breads Quick Breads Fat Free Vegetarian Salad Recipes Eggplant Recipes Radish Recipes Tomato Recipes Jalapeno Recipes Potato Recipes Lettuce Recipes Cabbage Recipes Beans Ambrosia Recipes Biscotti Recipes Desserts Low Fat Cookie Recipes Cheesecake Recipes Cake Recipes Pie Recipes Muffin Recipes Custard Recipes Best Appetizers Appetizers Low Fat Salsa Recipes Dip Recipes International Recipes Afghan Recipes Alaska Recipes French Recipes German Recipes Greek Recipes Italian Recipes Spanish Recipes Thai Recipes Korean Recipes Chinese Recipes Mexican Recipes Indian Recipes Beef Recipes Pork Pork & Ham Pork Butts Pork Chop Recipes Pork Ribs Rulled Pork Poultry Recipes Stews Recipes Ground Beef Barbecue Grill Barbecue Smoker All Purpose Sauce BBQ Sauce Barbecue Sauce Carolina BBQ Sauce Pickle Recipes Marinades Smoking Low Fat Appetizers & Dips Low Fat Breakfast Low Fat Cakes Low Fat Cheesecakes Low Fat Cookies Low Fat Desserts Low Fat Fish & Seafood Low Fat Meats Low Fat Pasta Low Fat Pies Low Fat Salads Low Fat Sandwiches Low Fat Sauces & Condiments Low Fat Sides Low Fat Soups Low Fat Vegetarian Baker's Dozen Taste of Home Recipe Book Bon Appetit Cookbook Blacktie Cookbook Buster Cook Book Cookbook USA Cook Book Cook Book Sara's Cookbook Sara's Cookbook Appetizers and Dips Poultry recipes Diabetic recipes Holiday recipes Miscellaneous recipes 110 recipes 1986 Usenet cookbook 2900 recipes Cyberrealm recipes Great sysops of world Specialty recipes Ceideburg recipes Cheese recipes Chili recipes Fruits recipes Garlic recipes Great chefs of NY Londontowne recipes Raisins recipes Recipes for kids US Food Vegetarian recipes Bread recipes Drinks Meat Dishes Brisket recipes Caribou recipes Chicken recipes Filet mignons recipes Pork recipes Swordfish recipes Turkey recipes Pasta recipes Uncategorized recipes Ethnic recipes Canada recipes English recipes Ethiopia recipes Germany recipes Greece recipes Mexican recipes Philippines recipes Welsh recipes Microwave recipes Soups recipes Vegetable recipes Asparagus recipes Barley recipes Brown rice recipes Lentil recipes Mushrooms recipes Salads recipes Wild rice Desserts recipes Cakes recipes Chocolate recipes Cookies recipes Ice cream recipes