Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() I'm wanting to detect if the font colour in the selected cell is black or yellow. Been playing with target. and the drop down items but can't see anything (yet). Any help appreciated. Thanks - Kirk |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
If the cell interior is filled by standard format method, then:
Private Sub Worksheet_Change(ByVal Target As Range) Set myRange = Sheets(1).Range("A1") If Target = myRange Then MsgBox myRange.Interior.ColorIndex End If End Sub This next one is a little tricky. It basically does the same thing but it only returns the setting for the conditional format and does not tell you if the condition is met. That means that if the condition is not met, the cell will not be color coded. Private Sub Worksheet_Change(ByVal Target As Range) Set myRange = Sheets(1).Range("A1") If Target = myRange Then MsgBox myRange.FormatConditions(1).Interior.ColorIndex End If End Sub "kirkm" wrote: I'm wanting to detect if the font colour in the selected cell is black or yellow. Been playing with target. and the drop down items but can't see anything (yet). Any help appreciated. Thanks - Kirk |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
P.S. The code goes behind the worksheet. Right click the sheet tab and click
View Code in the drop down menu. Then paste it in. "kirkm" wrote: I'm wanting to detect if the font colour in the selected cell is black or yellow. Been playing with target. and the drop down items but can't see anything (yet). Any help appreciated. Thanks - Kirk |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
You can do this a few ways depending on what you prefer.
1.) Put this code in Worksheet Module or the worksheet you wish to test. I think this may get a bit annoying but it will do the trick. Private Sub Worksheet_SelectionChange(ByVal Target As Range) Select Case Target.Font.ColorIndex Case Is = 1 MsgBox "The Font ColorIndex = 1 or Black" Case Is = 6 MsgBox "The Font ColorIndex = 6 or Yellow" End Select End Sub 2.) You can call a user defined function from a cell, which will return Black or Yellow. Public Function DetectFontColor(CellToDetect As Range) As String Select Case CellToDetect.Font.ColorIndex Case Is = 1 DetectFontColor = "Black" Case Is = 6 DetectFontColor = "Yellow" End Select End Function 3.) You could use the immediate window in the VB Editor. Just select a cell, then in VBE select ViewImmediate Window then type this: ?ActiveCell.Font.ColorIndex This will give you the colorindex number. I hope one of these helped! If so, please let me know and click "YES" below. -- Cheers, Ryan "kirkm" wrote: I'm wanting to detect if the font colour in the selected cell is black or yellow. Been playing with target. and the drop down items but can't see anything (yet). Any help appreciated. Thanks - Kirk |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
different colour font in same cel | Excel Worksheet Functions | |||
textBox font colour the same as cell font colour???????? | Excel Discussion (Misc queries) | |||
Using Font Colour | Excel Programming | |||
can the fill colour of a bar be tied to the data font colour data | Charts and Charting in Excel | |||
need a formula for setting colour target cells | Excel Worksheet Functions |