Multiple criteria for conditional formatting in Excel

11 ビュー (過去 30 日間)
Keshnee Moodley
Keshnee Moodley 2019 年 5 月 13 日
I want to apply three conditional formats on a cell in Excel. The the first two work, but the third does not. While the condition is in Excel (i.e. there are three conditions), no formatting rules have been applied to the last condition - the colour overwrites one of the first two criteria. How do I add a third conditional format condition? The code is provided below:
% Conditional formatting, only able to put two criteria
hExcel = actxserver('Excel.Application');
hWorkbook = hExcel.Workbooks.Open(filename);
hRange = hExcel.Range(FormatRange);
hRange.FormatConditions.Delete();
xlExpression = 2;
hRange.FormatConditions.Add(xlExpression, [], sprintf('=IF(ABS(%s)>=%d,IF(ABS(%s)<%d,1,0),0)', FormatRange,Crit*0.75,FormatRange,Crit));
hRange.FormatConditions.Item(1).SetFirstPriority();
hRange.FormatConditions.Item(1).Interior.ColorIndex = 45;
hRange.FormatConditions.Add(xlExpression, [], sprintf('=IF(ABS(%s)>=%d,1,0)',FormatRange,Crit));
hRange.FormatConditions.Item(1).SetLastPriority();
hRange.FormatConditions.Item(1).Interior.ColorIndex = 3;
hRange.FormatConditions.Add(xlExpression, [], sprintf('=IF(ABS(%s)<%d,1,0)', FormatRange,Crit*0.75));
hRange.FormatConditions.Item(1).SetLastPriority();
hRange.FormatConditions.Item(1).Interior.ColorIndex = 43;

回答 (0 件)

カテゴリ

Help Center および File ExchangeData Import from MATLAB についてさらに検索

製品


リリース

R2017a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by