I have added a Format Condition on a range with some formatting using the below code.
Microsoft.Office.Interop.Excel.FormatCondition formatConditionObj = null;
formatConditionObj = (Microsoft.Office.Interop.Excel.FormatCondition)myRange
.FormatConditions.Add(Excel.XlFormatConditionType.xlExpression,
Type.Missing, true, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing);
formatConditionObj.Interior.ColorIndex = 5;
Now my range changes dynamically.I want that using the same FormatCondition object i just change the range where this formats are applied. For e.g at the first instance it might be just "$A$1" later it might be "$A$2,$D$5" or "$A$3:$A$20".
This can be done using excel directly. Contitional Formatting -> Manage Rules -> Applies To(Edit this). How can be this acheived using C#.
This works for me. I find putting the “using” line below at the top saves a good deal of effort.