title: VBA Change font color based on backgroud color in pivot table
body: <p>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.</p>
  
  <p><a href="https://i.stack.imgur.com/XMZT8.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XMZT8.jpg" alt="enter image description here"></a></p>
  
  <p>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.<br>
  Simple <code>.Font.Color = .Interior.ColorIndex</code> doesn't work...</p>
  
  <pre><code>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
  </code></pre>
  
  <p>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.</p>
  
  <pre><code>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
  </code></pre>
  
  <p>Thank you for any help!</p>