ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Font (https://www.excelbanter.com/excel-discussion-misc-queries/137037-font.html)

sgdav

Font
 
How do I write a macro or if-then statement to examine the font colour in a
cell and then return a value dependant on the colour?

Mike

Font
 
I,m not sure what you mean by return a value dependant on font colour but
determining the colour is easy enough. The code below returns the colourindex
number of the active cell.

Sub FontColor()
MsgBox "The Font Color Index is " & ActiveCell.Font.ColorIndex
End Sub

Mike

"sgdav" wrote:

How do I write a macro or if-then statement to examine the font colour in a
cell and then return a value dependant on the colour?


Stefi

Font
 
This function returns colorindices of the cell given as first argument,
depending on the second argument. If it's TRUE, then returns font colorindex,
if FALSE, returns background colorindex.

Function WhatColor(cella As Range, fontbackgr As Boolean)
Application.Volatile
If fontbackgr Then
WhatColor = cella.Font.ColorIndex
Else
WhatColor = cella.Interior.ColorIndex
End If
End Function

Regards,
Stefi

sgdav ezt *rta:

How do I write a macro or if-then statement to examine the font colour in a
cell and then return a value dependant on the colour?



All times are GMT +1. The time now is 11:46 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com