Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88066

Conditional Formatting C# AND Statement Blank not working

$
0
0

I'm trying to add conditional formatting to my VSTO Excel C# Application. I want to set the cell background colour to red if the column value in AH is the same as the column value in X and if X is not blank. However it complains at the below code saying

Syntax error ',' expected.

This formula works fine when I manually put it in excel.

This is my formula: =AND(X7=AH7,X7<>"")

And here's my C# code:

FormatCondition format7 =
    (FormatCondition)(uiWorksheet.get_Range("AH7:AH" + lastUsedRow, Type.Missing)
        .FormatConditions.Add(XlFormatConditionType.xlExpression,
            XlFormatConditionOperator.xlEqual, "=AND(X7=AH7,X7<>"")",
           Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing));

format7.Interior.Color = System.Drawing.Color.Red;

Viewing all articles
Browse latest Browse all 88066

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>