Solved

MS Excel - How to detect the color of the text/cell ?

Posted on 2001-06-25
5
2,049 Views
Last Modified: 2007-11-27
As a normal practice, our users fill in BLUE and YELLOW colored text to mark their input (they just change text color)... Now, it's impossible to sort the list based on the colors.... Is there any other way to resolve this problem (unfortunately I can't ask them to insert there input separately, so I have to live with the way they report us)

Thanks in advance...
0
Comment
Question by:tparvaiz
5 Comments
 
LVL 2

Accepted Solution

by:
sergeTD earned 20 total points
ID: 6225396
Hi Tparvaiz,
I don't get the solution to sort a range by color but here is a function which give the sum depending of the font color:
-----------------------------------------------------------
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 ' ignore cells without values
    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
-----------------------------------------------------------
First open VBA by typing ALT+F11.In the PROJECT window, click on the "+" in front of the file NAME then on the "+"
in front of MODULS.Copy the text above and paste it inside
Modul 1.
To use this function, type at the bottom of column: =SumByColor(range to select, reference cell to select)
For example,=SumByColor(a2..a8,a2).
Hope this helps
serge TD
0
 
LVL 13

Expert Comment

by:cri
ID: 6225417
SergeTD, you could modify your macro to write the colorindex or something similar into an auxiliary column. Then tparvaiz can sort it by this auxiliary numbers/chars whatever.
0
 

Expert Comment

by:dfghjk
ID: 6225442
tparvaiz!

Another option is to create this little macrofunction in a VBA-module like this:

Function TextColor(rCell As Range)
    TextColor = rCell.Font.ColorIndex
End Function

Then use it like this (just as an typical example):
in the range "A2:A1000" you have your text with different colors.
In the range "B2:B1000" use this function as a regular Excel formula, write in cell B2 "=TextColor(A2)", and copy it down to B1000.

Then you will have the colornumber in column B for each row in column A. And you will be able to sort by textcolor by using column B as primary sort order.

If you want help with making a VBA macro of the code above, just tell, and I can help with a ditailed description of how to do that.

Hope that can help you!
dfghjk
0
 

Expert Comment

by:costello
ID: 6415544
If no objections are made in the next 5 days, I will force accept the contribution by SergeTD.

costello
Community Support Moderator @ Experts-Exchange

P.S. This post is made as part of the general effort to clean up this topic area, meaning, looping through all the open questions with no activity since 21 days.
0
 

Expert Comment

by:ComTech
ID: 6690976
Answer accepted by:

ComTech
Community Support Moderator
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

This article will show you how to use shortcut menus in the Access run-time environment.
Outlook Free & Paid Tools
This video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now