title: How to check the background color of an excel cell
body: <p>In my program, I set the background color of an excel cell using:</p>
  
  <pre><code>sheet.cells(row, column).interior.color = System.Drawing.Color.Red
  </code></pre>
  
  <p>In another part of my program, I want to see if the color is red, but this code:</p>
  
  <pre><code>If(sheet.cells(row, column).interior.color = System.Drawing.Color.Red) Then
      'Do something
  End If
  </code></pre>
  
  <p>It returns an 'Type cast invalid' exception.</p>
  
  <p>If the color is checked by:</p>
  
  <pre><code>If(sheet.cells(row, column).style.interior.color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Red))
      'Do something
  End If
  </code></pre>
  
  <p>The colors are said to be not equal (even though the cell is red), because the interior color is 16777215 and the color translator returns 255.</p>
  
  <p>How can I compare the color the right way?</p>