I want to add conditional formatting on a range depending on some condition.
I want to to format the Color, Size , Bold etc properties. I am able to modify Color, Bold properties but when i try to modify Size property it throws an exception “Unable to set the Size property of the Font class”.
Can anyone help how can i set the Size property of Conditional Formatting object.
It is not possible to set subscript or superscript property also.
Note : These properties are not Read-Only also.
FormatCondition format =(FormatCondition)( targetSheet.get_Range("A1:A10",
Type.Missing).FormatConditions.Add(XlFormatConditionType.xlExpression, XlFormatConditionOperator.xlGreater,
"100", Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing));
format.Font.Bold = true;
format.Font.Color = 0x000000FF;
format.Font.Size = 14;
format.Font.Subscript = true;
To make clear the actual usecase lets take an example where i have data of 10*10 in excel. This 10*10 is a single Range with its own format. For E.g A1 to J10. Now if i select any cell of this range then its corresponding Rows and Columns should get a Conditional Formating and it would have its own formats. This includes different fill color, different font size, change in border etc. Such as if i select cell D4 then Range A4:J4 and D1:D10 will have conditional formats applied.This can be done by applying formats on these both range and choosing type as Expression and its formula as true. Now if i select any other cell then the formats of A4:J4 and D1:D10 cells should be reverted back and the rows and colummn for the currently selected cell should be highlighted.
We can change the format such as only the Color or pattern. But its not possible to set the Size. Can anyone explain me why is it so.
Changing the size from User Interface is possible. i.e using the Format option of conditional formatting. Using that the font size,color etc of the cells which satisfies the condition can be changed.
Things which are possible from UI should be possible from code also.
Have share an image to get a view: https://i.stack.imgur.com/0g1qq.jpg
Try the following (you can change the color values and add additional properties for font size, color, etc.):