How does one obtain the color index of a conditional format with VBA?
I don't believe it is the same as formatting a cell's interior color index. Example: Range("A1").Interior.ColorIndex = 19
Conditional Format Color
-
- GoldLounger
- Posts: 2628
- Joined: 26 Jan 2010, 16:31
- Location: Southern California
Conditional Format Color
Regards,
John
John
-
- Administrator
- Posts: 78443
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Conditional Format Color
If you mean the color index the cell currently has, you can use the DisplayFormat property:
Code: Select all
Debug.Print Range("A1").DisplayFormat.Interior.ColorIndex
Best wishes,
Hans
Hans
-
- GoldLounger
- Posts: 2628
- Joined: 26 Jan 2010, 16:31
- Location: Southern California
Re: Conditional Format Color
Hans,
I was able to obtain the correct DisplayFormat.Interior.ColorIndex with this bit of code and would like to convert it to a function
Function Code =CFInteriorColor(tblMyTable[Status])
Any suggestions would be appreciated. I'm going to add code to the Function once the ColorIndex works.
I was able to obtain the correct DisplayFormat.Interior.ColorIndex with this bit of code and would like to convert it to a function
Code: Select all
Sub GetCFInteriorColorIndex()
Dim rng As Range
For Each rng In Range("tblMyTable[Status]")
Debug.Print rng & " " & rng.DisplayFormat.Interior.ColorIndex
Next rng
End Sub
Code: Select all
Function CFInteriorColor(InRange As Range)
Dim rng As Range
Application.Volatile True
For Each rng In InRange.Cells
Debug.Print rng & " " & rng.DisplayFormat.Interior.ColorIndex 'Does not work do to colorindex
Next rng
End Function
Regards,
John
John
-
- Administrator
- Posts: 78443
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Conditional Format Color
As you have found, DisplayFormat does not work in a UDF (User-Defined Function). This is documented by Microsoft - see Range.DisplayFormat property (Excel).
Fortunately, there is a workaround - see Using DisplayFormat in a UDF. Let me know if you have trouble modifying that for your purpose.
Fortunately, there is a workaround - see Using DisplayFormat in a UDF. Let me know if you have trouble modifying that for your purpose.
Best wishes,
Hans
Hans
-
- GoldLounger
- Posts: 2628
- Joined: 26 Jan 2010, 16:31
- Location: Southern California
Re: Conditional Format Color
Hans,
Thank you for the workaround suggestion. I got it to work.
Thank you for the workaround suggestion. I got it to work.
Regards,
John
John