Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Some time ago I was asked to create a VBA function that would calculate a check digit for an input number, using the following procedure: First, sum up all the individual digits in the number If that sum value has more than one digit, then sum up …
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
This video shows where to find the word count, how to display it, and what it breaks down to in Microsoft Word.
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.

863 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