Multiple criteria for conditional formatting in Excel

12 Ansichten (letzte 30 Tage)
Keshnee Moodley
Keshnee Moodley am 13 Mai 2019
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;

Antworten (0)

Kategorien

Mehr zu Data Import from MATLAB finden Sie in Help Center und File Exchange

Produkte


Version

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by