Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2001-06-25
5
Medium Priority
?
2,112 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 80 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

This article helps those who get the 0xc004d307 error when trying to rearm (reset the license) Office 2013 in a Virtual Desktop Infrastructure (VDI) and/or those trying to prep the master image for Microsoft Key Management (KMS) activation. (i.e.- C…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

609 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