I am trying to add a conditional formatting using C# with 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;
Dynamically i change the range where these formats are applied using
formatConditionObj.ModifyAppliesToRange(NewRange);
Now i want to delete this format which is applied how can this be achieved.
formatConditionObj.Delete();
This doesn't work for me. This does not delete the format for all the cells where it is applied. Only the last cells formats is removed.
I also tried using
formatConditionObj.AppliesTo.Delete();
But it delete other ConditionalFormats also which are applied on that cell.
Note: Some formats are already applied on the cells where this conditinal formatting is applied for e.g some fill color. Even there are some other conditional formats applied on some of the cells. I just want to delete this particular ConditionalFormat(formatConditionObj).
Can anyone help me.