Need help with "data types" and "conditions" to complete this new LAMBDA I'm working on; thank you!

Rnkhch

Well-known Member
Joined
Apr 28, 2018
Messages
578
Office Version
  1. 365
Platform
  1. Windows
Hello,

I'm working on a new LAMBDA, called TC (type-based conditions), that checks the data type (specified in two small tables at top of the attached XL2BB), specified in the first parameter, and ensures that the conditions, specified in the third parameter are applied only to the cells that have the specified type. All other cells will return FALSE/0 as the condition(s) will be n/a for them.

TC has the following format:
TC(type,reference,[conditions],[output_style])

If output_style is 0 or omitted, it returns TRUE/FALSE, and if it is 1, it returns 1/0.

The reason I got into this was situations like A1:D1>29 which returns TRUE/1 even when the range contains text values such as "book" (which is the main scenario I'm trying to solve through this LAMBDA). In another scenario, ISBLANK recognizes only real blanks, but not formula blanks, and in another scenario, ISTEXT returns TRUE/1 for formula blanks, etc.

So to avoid any confusions/mistakes, I developed this TC LAMBDA function, that appears to be working well with the exception of two scenarios that I have highlighted in red in the attached XL2BB. So far I haven't been able to figure out the right code for these two scenarios:

U17: =TC(2,$E$2:$K$6,$E$2:$K$6>10,1)
here, the cells are evaluated to be greater than 10, but the specified type is 2 for text, so all cells should appear as FALSE/0.

U45: =TC(31,$E$2:$K$6,$E$2:$K$6=FALSE,1)
here, the cells are evaluated to be FALSE, but the real blank cells gets treated as a zero/FALSE and appears as TRUE/1.

For each data type, I have included a no criteria, and a correct criteria table. I have also included two incorrect criteria meaning that the criteria are n/a relative to the specified type.

I would appreciate any input on this 🤗 Please let me know if you need further clarification/explnantion on the LAMBDA and how it works.

tc.xlsx
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAGAHAIAJ
1TCETS
2#CALC!#CALC!9087TRUE88153561number31real blank
343#DIV/0!131589 872text32formula blank
4T1F0IO698611#N/A20-31913blank41TRUE logical
5#CALC!#CALC!900214848notebook4logical42FALSE logical
63915book40FALSE748916error160-1614specific errors
7PO0
8#CALC!
9data typeno criteriacorrect criteriaincorrect criteriaincorrect criteria
1011101111110101100000000000000
111011101100010100000000000000
121110111110000100000000000000
130111110010011000000000000000
141101011000001100000000000000
15
16no criteriacorrect criteriaincorrect criteriaincorrect criteria
1720000000000000000000000000000
180000000000000000000000000000
190000000000000000000000000000
200000001000000000000010000000
210010000001000000100000000000
22
23no criteriacorrect criteriaincorrect criteriaincorrect criteria
2430000000000000000000000000000
250000010000001000000000000000
260000000000000000000000000000
271000000100000000000000000000
280000000000000000000000000000
29
30no criteriacorrect criteriaincorrect criteriaincorrect criteria
3140010000000000000000000000000
320000000000000000000000000000
330000000000000000000000000000
340000000000000000000000000000
350000100000010000000000000000
36
37no criteriacorrect criteriaincorrect criteriaincorrect criteria
38160000000000000000000000000000
390100000010000000000000000000
400001000000000000000000000000
410000000000000000000000000000
420000000000000000000000000000
43
44no criteriacorrect criteriaincorrect criteriaincorrect criteria
45310000000000000000000000000000
460000000000000000000000000000
470000000000000000000000000000
481000000100000010000000000000
490000000000000000000000000000
50
51no criteriacorrect criteriaincorrect criteriaincorrect criteria
52320000000000000000000000000000
530000010000001000000000000000
540000000000000000000000000000
550000000000000000000000000000
560000000000000000000000000000
57
58no criteriacorrect criteriaincorrect criteriaincorrect criteria
59410010000001000000000000000000
600000000000000000000000000000
610000000000000000000000000000
620000000000000000000000000000
630000000000000000000000000000
64
65no criteriacorrect criteriaincorrect criteriaincorrect criteria
66420000000000000000000000000000
670000000000000000000000000000
680000000000000000000000000000
690000000000000000000000000000
700000100000010000000000000000
71
72no criteriacorrect criteriaincorrect criteriaincorrect criteria
731620000000000000000000000000000
740100000010000000000000000000
750000000000000000000000000000
760000000000000000000000000000
770000000000000000000000000000
78
Sheet1
Cell Formulas
RangeFormula
B2B2=LAMBDA(type,reference,[conditions],[output_style],LET(o,PO0(output_style),c,IF(IO(conditions),1,IFERROR(conditions,0)),e,IF(type<160,(SWITCH(type,1,T1F0(ISNUMBER(reference)),2,LET(r,IFERROR(reference,""),T1F0((ISTEXT(r))*(NOT(r="")))),3,T1F0(IFERROR(IF(reference="",1),0)),4,T1F0(ISLOGICAL(reference)),16,T1F0(ISERROR(reference)),31,T1F0(IFERROR(ISBLANK(reference),0)),32,T1F0(IFERROR((NOT(ISBLANK(reference)))*(reference=""),0)),41,T1F0(IF(ISLOGICAL(reference),reference=TRUE)),42,T1F0(T1F0(IF(ISLOGICAL(reference),reference=FALSE)))))*(c),IF(NOT(ISERROR(MATCH(type,ErrorTypes,0))),T1F0(IFERROR(ERROR.TYPE(reference)=ETS(type),0))*(c))),SWITCH(o,0,IF(e,TRUE,FALSE),1,IF(e,1,0))))
C2C2=LAMBDA(type,SWITCH(type,160,0,161,1,162,2,163,3,164,4,165,5,166,6,167,7,168,8,169,9,1610,10,1611,11,1612,12,1613,13,1614,14))
F3F3=1/0
J3J3=IF(1,"")
H4H4=NA()
B5B5=LAMBDA(expression,IF(expression,1,0))
C5C5=LAMBDA(parameter,ISOMITTED(parameter))
B8B8=LAMBDA(parameter,IF(IO(parameter),0,parameter))
E10:K14E10=TC(1,$E$2:$K$6,,1)
M10:S14M10=TC(1,$E$2:$K$6,$E$2:$K$6>40,1)
U10:AA14U10=TC(1,$E$2:$K$6,$E$2:$K$6="book",1)
AC10:AI14AC10=TC(1,$E$2:$K$6,$E$2:$K$6="",1)
E17:K21E17=TC(2,$E$2:$K$6,,1)
M17:S21M17=TC(2,$E$2:$K$6,$E$2:$K$6="book",1)
U17:AA21U17=TC(2,$E$2:$K$6,$E$2:$K$6>10,1)
AC17:AI21AC17=TC(2,$E$2:$K$6,$E$2:$K$6="",1)
E24:K28E24=TC(3,$E$2:$K$6,,1)
M24:S28M24=TC(3,$E$2:$K$6,$E$2:$K$6="",1)
U24:AA28U24=TC(3,$E$2:$K$6,$E$2:$K$6=3,1)
AC24:AI28AC24=TC(3,$E$2:$K$6,$E$2:$K$6="g",1)
E31:K35E31=TC(4,$E$2:$K$6,,1)
M31:S35M31=TC(4,$E$2:$K$6,$E$2:$K$6=FALSE,1)
U31:AA35U31=TC(4,$E$2:$K$6,$E$2:$K$6="",1)
AC31:AI35AC31=TC(4,$E$2:$K$6,$E$2:$K$6=0,1)
E38:K42E38=TC(16,$E$2:$K$6,,1)
M38:S42M38=TC(16,$E$2:$K$6,IF(ISERROR($E$2:$K$6),ERROR.TYPE($E$2:$K$6)=2),1)
U38:AA42U38=TC(16,$E$2:$K$6,$E$2:$K$6=12,1)
AC38:AI42AC38=TC(16,$E$2:$K$6,$E$2:$K$6=FALSE,1)
E45:K49E45=TC(31,$E$2:$K$6,,1)
M45:S49M45=TC(31,$E$2:$K$6,$E$2:$K$6="",1)
U45:AA49U45=TC(31,$E$2:$K$6,$E$2:$K$6=FALSE,1)
AC45:AI49AC45=TC(31,$E$2:$K$6,$E$2:$K$6="book",1)
E52:K56E52=TC(32,$E$2:$K$6,,1)
M52:S56M52=TC(32,$E$2:$K$6,$E$2:$K$6="",1)
U52:AA56U52=TC(32,$E$2:$K$6,$E$2:$K$6="ook",1)
AC52:AI56AC52=TC(32,$E$2:$K$6,$E$2:$K$6=TRUE,1)
E59:K63E59=TC(41,$E$2:$K$6,,1)
M59:S63M59=TC(41,$E$2:$K$6,$E$2:$K$6=TRUE,1)
U59:AA63U59=TC(41,$E$2:$K$6,$E$2:$K$6=0,1)
AC59:AI63AC59=TC(41,$E$2:$K$6,$E$2:$K$6=1,1)
E66:K70E66=TC(42,$E$2:$K$6,,1)
M66:S70M66=TC(42,$E$2:$K$6,$E$2:$K$6=FALSE,1)
U66:AA70U66=TC(42,$E$2:$K$6,$E$2:$K$6=0,1)
AC66:AI70AC66=TC(42,$E$2:$K$6,$E$2:$K$6=1,1)
E73:K77E73=TC(162,$E$2:$K$6,,1)
M73:S77M73=TC(162,$E$2:$K$6,ERROR.TYPE($E$2:$K$6)=2,1)
U73:AA77U73=TC(162,$E$2:$K$6,ERROR.TYPE($E$2:$K$6)=4,1)
AC73:AI77AC73=TC(162,$E$2:$K$6,$E$2:$K$6=0,1)
Dynamic array formulas.
 
Last edited:

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
P.S.

The "ErrorTypes" name in the code refers to: {160,161,162,163,164,165,166,167,168,169,1610,1611,1612,1613,1614} which correspond to the Excel errors 0-14, respectively.
 
Upvote 0

Forum statistics

Threads
1,223,902
Messages
6,175,278
Members
452,629
Latest member
SahilPolekar

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