Solved

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

Posted on 2001-06-25
5
2,077 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
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 use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…

719 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