I'm trying to write a VBA code to change a font color of a cell based on a background color of that cell. Generally, to "hide" record names in two columns ("ID" and "Name"). Cells are colored using conditional formatting.
I managed to find a way to change a font using only 1 color but don't know how dynamically get background color of a cell and use it as a font color.
Simple .Font.Color = .Interior.ColorIndex
doesn't work...
Sub Color_text_black()
Dim c As Range
With ActiveSheet.PivotTables("PivotTable2")
With Intersect(.PivotFields("Name").DataRange.Cells, .TableRange1)
.Font.Bold = False
.Font.Color = 1 '.Font.Color = .Interior.ColorIndex doesn't work
End With
End With
End Sub
Also maybe there should be another way to get the background color, I tried to use For loop but it always sends me an error.
Sub Color_text()
Dim c As Range
With ActiveSheet.PivotTables("PivotTable1")
For Each c In .PivotFields("Name").DataRange.Cells
.Font.Bold = False
.Font.Color = .Interior.ColorIndex
Next
End With
End Sub
Thank you for any help!