I have a VSTO c# application and I am trying to apply conditional formatting so when the value in Column V is set to No make the whole row grey. headercount variable is my last column number
Microsoft.Office.Interop.Excel.FormatCondition format7 = (Microsoft.Office.Interop.Excel.FormatCondition)(uiWorksheet.get_Range("B7:Z" + headercount,
Type.Missing).FormatConditions.Add(Microsoft.Office.Interop.Excel.XlFormatConditionType.xlExpression, Microsoft.Office.Interop.Excel.XlFormatConditionOperator.xlEqual,
"V=No", Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing));
format7.Interior.Color = true;
I tried the below but it doesnt work - any ideas?
I was able to get this to work using Excel's INDIRECT
function with the conditional formatting triggered by the Application.SheetChange
event. Please note that the internal quotation marks for the formula need to be escaped.
Microsoft.Office.Interop.Excel.FormatCondition format7 = (Microsoft.Office.Interop.Excel.FormatCondition)(uiWorksheet.get_Range("B7:Z" + headercount,
Type.Missing).FormatConditions.Add(Microsoft.Office.Interop.Excel.XlFormatConditionType.xlExpression, Microsoft.Office.Interop.Excel.XlFormatConditionOperator.xlEqual,
"=INDIRECT(\"V\"&ROW())=\"No\"", Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing));
format7.Interior.Color = System.Drawing.Color.Gray;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.