CFMATH

CFMATH(Func_Num,Cell_Ref,Range_Ref,Value1_k,Value2)
Func_Num
Required. 1☛Max, 2☛Min, 3☛Small, 4☛Large, 5☛Greater Than, 6☛Less Than, 7☛Greater/Equal, 8☛Less/Equal, 9☛Between (Exclusive), 10☛Between (Inclusive), 11☛Equal, 12☛Not Equal, 13☛Mode, 14☛Duplicates, 15☛Count_Greater/Equal, 16☛Count_Less/Equal
Cell_Ref
Required. Upper left most cell of conditional formatting range. Must be relative or mixed reference.
Range_Ref
Required for Numbers 1,2,3,4,13,14,15,16. Range to check against. Must be absolute or mixed reference.
Value1_k
Required for Numbers 3,4,5,6,7,8,9,10,11,12,15,16. Value to compare against. Hardcoded or absolute reference.
Value2
Required for Numbers 9,10. Upper value to compare against. Hardcoded or absolute reference.

CFMATH is used for Conditional Formatting and returns TRUE or FALSE given a function number (1-16) related to math and a cell reference.

schardt679

Board Regular
Joined
Mar 27, 2021
Messages
58
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
  2. Mobile
  3. Web
CFMATH is used for Conditional Formatting and returns TRUE or FALSE given a function number (1-16) related to math and a cell reference.

Excludes blanks but not 0's. Functions are 1☛Max, 2☛Min, 3☛Large, 4☛Small, 5☛Greater Than, 6☛Less Than, 7☛Greater/Equal, 8☛Less/Equal, 9☛Between (Exclusive), 10☛Between (Inclusive), 11☛Equal, 12☛Not Equal, 13☛Mode, 14☛Duplicates, 15☛Count_Greater/Equal, 16☛Count_Less/Equal
LARGE, SMALL, & EQUAL handle arrays of values. MODE handles multi-mode ranges.

Excel Formula:
'=LAMBDA(Func_Num,Cell_Ref,Range_Ref,Value1_k,Value2,
      LET(Func, Func_Num,    Ref, Cell_Ref,
             Range, Range_Ref,    Val_1, Value1_k,    Val_2, Value2,
             RangeUni, UNIQUE(Range),    RefCt, COUNTIF(Range, Ref),
             MX, Ref=MAX(Range),    MN, Ref=MIN(Range),
             LG, OR(Ref=LARGE(RangeUni, Val_1)),
             SM, OR(Ref=SMALL(RangeUni, Val_1)),
             GT, Ref>Val_1,    GEQ, Ref>=Val_1,
             LT_1, Ref<Val_1,    LEQ_1, Ref<=Val_1,
             LT_2, Ref<Val_2,    LEQ_2, Ref<=Val_2,
             BT_Ex, AND(GT, LT_2),    BT_In, AND(GEQ, LEQ_2),
             EQ, OR(Ref=Val_1),     EQ_N, NOT(EQ),
             MD, OR(IFERROR(Ref=MODE.MULT(Range), 0)),
             Dup, RefCt>1,    CT_GEQ, RefCt>=Val_1,    CT_LEQ, RefCt<=Val_1,
             F1_8, SWITCH(Func,  1, MX,  2, MN,  3, LG,  4, SM,  5, GT,  6, LT_1,  7, GEQ,  8, LEQ_1,  0),
             F9_16, SWITCH(Func,  9, BT_Ex,  10, BT_In,  11, EQ,  12, EQ_N,  13, MD,  14, Dup,  15, CT_GEQ,  16, CT_LEQ,  0),
             Result, IF(--(F1_8)=1, F1_8, F9_16),
             Return, IF(Ref="", 0, Result),
             Return
      )
  )

LAMBDA Examples.xlsx
ABCDEFGHIJK
1CFMATH
2
3Sample DataConditional Formatting Colors
4MaxMinLargeSmallFunc_NumFunctionValue1_ k
5919191911Max (MX)
6595959592Min (MN)
7727272723Large (LG)23
8979797974Small (SM)2
980808080
1060606060
1182828282
12
13
14Sample DataConditional Formatting Colors
15Greater ThanLess ThanBetween (Exclusive)Func_NumFunctionValue1_kValue2
169191915Greater Than (GT)85
178585856Less Than (LT)75
187275729Between (Exclusive) (BTW_Ex)8089
19979797
20808080
21606060
22828282
23
24
25Sample DataConditional Formatting Colors
26Greater/EqualLess/EqualBetween (Inclusive)Func_NumFunctionValue1_kValue2
279191917Greater/Equal (GEQ)85
288585858Less/Equal (LEQ)75
2972757210Between (Inclusive) (BTW_In)8089
30979797
31808080
32606060
33828282
34
35
36Sample DataConditional Formatting Colors
37EqualNot EqualFunc_NumFunctionValue1_k
3810010011Equal (EQ)90100
39787812Not Equal (EQ_N)90
408282
419090
427777
439090
448585
45
46
47Sample DataConditional Formatting Colors
48ModeDuplicatesFunc_NumFunction
49808013Mode (MD)
50919114Duplicates (DUP)
51100100
528080
537777
548080
55100100
56
57
58Sample DataConditional Formatting Colors
59Count, Great/EqualCount, Less/EqualFunc_NumFunctionValue1_k
60808015Count, Great/Equal (CT_GEQ)3
61909016Count, Less/Equal (CT_LEQ)1
62100100
638080
64100100
658080
667070
67
CFMATH
Cell Formulas
RangeFormula
I7:J7I7={2,3}
I38:J38I38={90,100}
Dynamic array formulas.
Cells with Conditional Formatting
CellConditionCell FormatStop If True
B5:B11Expression=CFMATH(1, B5, B$5:B$11,,)textNO
C5:C11Expression=CFMATH(2, C5,C$5:C$11,,)textNO
D5:D11Expression=CFMATH(3, D5, D$5:D$11, $I$7#,)textNO
E5:E11Expression=CFMATH(4, E5, E$5:E$11, $I$8,)textNO
B16:B22Expression=CFMATH(5, B16, B$16:B$22, $I$16,)textNO
C16:C22Expression=CFMATH(6, C16,C$16:C$22, $I$17,)textNO
B27:B33Expression=CFMATH(7, B27, B$27:B$33, $I$27,)textNO
C27:C33Expression=CFMATH(8, C27,C$27:C$33, $I$28,)textNO
D16:D22Expression=CFMATH(9, D16, D$16:D$22, $I$18, $J$18)textNO
D27:D33Expression=CFMATH(10, D27, D$27:D$33, $I$29, $J$29)textNO
B38:B44Expression=CFMATH(11, B38,, $I$38#,)textNO
C38:C44Expression=CFMATH(12, C38,, $I$39,)textNO
B49:B55Expression=CFMATH(13, B49, B$49:B$55,,)textNO
C49:C55Expression=CFMATH(14, C49, C$49:C$55,,)textNO
B60:B66Expression=CFMATH(15, B60, B$60:B$66, $I$60,)textNO
C60:C66Expression=CFMATH(16, C60, C$60:C$66, $I$61,)textNO
 
Upvote 0
Value1_k and Value2 can be relative or mixed references too depending on the situation.
 

Forum statistics

Threads
1,223,604
Messages
6,173,315
Members
452,510
Latest member
RCan29

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top