title: Powershell : Highlight excel cell Interior using condition
body: <p>I want to highlight an excel cell interior using powershell , am able to change color of font , but not entire cell color</p>
  <p><a href="https://i.stack.imgur.com/YJ9w6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YJ9w6.png" alt="Excel Sheet" /></a></p>
  <p>So this is how my excel sheet is , it checks whether the cell has &quot;Matching&quot; and changes color according to that</p>
  <pre><code>$excel = New-Object -ComObject Excel.Application
  $excel.Visible = $false
  $excel.DisplayAlerts = $False
  $workbook = $excel.Workbooks.Open(&quot;C:\Users\test4.xls&quot;)
  $sheet = $workbook.ActiveSheet
  
  $xlCellTypeLastCell = 11
  
  $used = $sheet.usedRange 
  $lastCell = $used.SpecialCells($xlCellTypeLastCell) 
  $row = $lastCell.row # goes to the last used row in the worksheet
  $column = $lastCell.Column; 
  $i = 0 
  for ($J = 2; $J -le $column; $j++) {
       $sheet.Cells.Item($i,$j).Interior.ColorIndex = 48
       $sheet.Cells.Item($i,$j).Font.Bold=$True
  }
  for ($i = 2; $i -le $row; $i++) {
      for($j = 5 ; $j -le $column ; $j++){
          if (($sheet.cells.Item($i,$j).Value()) -like &quot;*Matching&quot;) {
              $sheet.Cells.Item($i,$j).Font.ColorIndex = 10
              $sheet.Cells.Item($i,$j).Font.Bold = $true
          }
          if(($sheet.cells.Item($i,$j).Value()) -like &quot;*Not Matching&quot;){
              $sheet.Cells.Item($i,$j).Font.ColorIndex = 3
              $sheet.Cells.Item($i,$j).Font.Bold = $true
          }
      }
  }
  
  $workbook.SaveAs(&quot;C:\Users\output.xls&quot;)
  $workbook.Close()
  </code></pre>
  <p>this is code , Only problem is when i give</p>
  <pre><code>$sheet.Cells.Item($i,$j).Interior.ColorIndex = 48
  </code></pre>
  <p>It's giving me an exception</p>
  <pre><code>Exception from HRESULT: 0x800A03EC
  </code></pre>
  <p>I want my table to look like this ,
  <a href="https://i.stack.imgur.com/BVsDH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BVsDH.png" alt="Output Excel Template" /></a></p>