title: Find duplicate values in excel worksheet using conditional formatting programmatically
body: <p>i need to find duplicate values in excel worksheet using conditional formating programmatically. </p>
  
  <p>Tried this way, but in 6 line of code i've got COM exception </p>
  
  <blockquote>
    <p>cannot cast to Excel.FormatCondition</p>
  </blockquote>
  
  <p>Here's my code</p>
  
  <pre><code>Excel.Workbook xlWB = Application.ActiveWorkbook;
  Excel.Worksheet xlWS = xlWB.ActiveSheet;
  xlWS.Range["B2:B9"].Select();
  Excel.Range xlS = Application.Selection;
  xlS.FormatConditions.AddUniqueValues();
  Excel.FormatCondition xlFC = 
      (Excel.FormatCondition)xlS.FormatConditions[xlS.FormatConditions.Count];
  xlFC.SetFirstPriority();
  Excel.FormatCondition xlFC1 = (Excel.FormatCondition)xlS.FormatConditions[1];
  xlFC1.Interior.Pattern = Excel.XlPattern.xlPatternAutomatic;
  xlFC1.Interior.TintAndShade = 0;
  xlFC1.Interior.Color = ColorTranslator.FromOle(13551615);
  </code></pre>