Function to return text color index

PATSYS

Well-known Member
Joined
Mar 12, 2006
Messages
1,749
Hi,

Can somebody show me the code for a UDF that shows the color index number of a cell value in excel?

Thanks
 

Some videos you may like

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result

MarkAndrews

Well-known Member
Joined
May 2, 2006
Messages
1,963
Hi,

Can somebody show me the code for a UDF that shows the color index number of a cell value in excel?

Thanks

ASAP utilities has this built in function - you could find the freeware add in on the internet?
 

Richard Schollar

MrExcel MVP
Joined
Apr 19, 2005
Messages
23,707
Here's the code:

Code:
Function ColorIndex(rCell As Range,Optional FontOrInterior As Integer = 0) As Integer
If FontOrInterior Then
    ColorIndex = rCell.Interior.ColorIndex
Else
    ColorIndex = rCell.Font.ColorIndex
End If
End Function

Use:

=ColorIndex(A1)

for the font colorindex. Or:

=ColorIndex(A1,1)

for the fill colorindex.

Richard
 

Watch MrExcel Video

Forum statistics

Threads
1,112,885
Messages
5,543,033
Members
410,583
Latest member
gazz57
Top