Solved

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

Posted on 2001-06-25
5
2,060 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Have you ever had the experience that you had to follow 10 steps over and over again every time when you need to nicely forward an important email to your manager? Fear no more! With the help of the Quick Steps feature in Outlook 2010, your old chor…
Microsoft Office Picture Manager is not included in Office 2013. This comes as a shock to users upgrading from earlier versions of Office, such as 2007 and 2010, where Picture Manager was included as a standard application. This article explains how…
The viewer will learn how to make their project stand out over others by learning how to change colors and shapes, add spaces, change directions, and add bullets to their charts.
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…

828 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