XTYPE outputs the precise data type of a cell/range or the elements of an array beyond the resolution of Excel's TYPE() or CELL("type",)
XTYPE was designed to provide detailed and high-resolution information about the data type that a cell or cells of a range/array contain. Thus, it is spill-compatible as well. It has two parameters: reference (required) and analysis_type (optional, which specifies the mode/type of data analysis). XTYPE operates in the following modes:
A) analysis_type omitted or 1: In this "basic" mode, it outputs one of the following five types of data for the selected reference:
dt:NUMBER
dt:TEXT
dt:BLANK
dt:LOGICAL
dt:ERROR
B) analysis_type 1: In this advanced mode, it provides more detailed information on the BLANK, LOGICAL, and ERROR types and outputs one of the following data types for the selected reference:
dt:NUMBER
dt:TEXT
dt:BLANK_REAL or dt:BLANK_FORMULA
dt:LOGICAL_TRUE or dt:LOGICAL_FALSE
dt:ERROR_EXTERNAL! or dt:ERROR_NULL! or dt:ERROR_DIV/0! or dt:ERROR_VALUE! or dt:ERROR_REF! or dt:ERROR_NAME? or dt:ERROR_NUM! or dt:ERROR_N/A or dt:ERROR_GETTING_DATA or "dt:ERROR_SPILL! or dt:ERROR_CONNECT! or dt:ERROR_BLOCKED! or dt:ERROR_UNKNOWN! or dt:ERROR_FIELD! or dt:ERROR_CALC!
C) analysis_type 2: it acts exactly as the Excel's TYPE() function
D) analysis_type 3: it acts as the Excel's TYPE() function, but outputs the data type in the XTYPE style. (This demonstrates the utility of XTYPE over TYPE, as TYPE outputs "1 or number" for real blanks and "2 or text" for formula blanks; see attached XL2BB.)
E) analysis_type 4: it acts exactly as the Excel's CELL("type",) function with the added bonus that it is spill-compatible, (while CELL("type",) on its own is not spill-compatible).
Please feel free to share any thoughts or suggestions.
XTYPE was designed to provide detailed and high-resolution information about the data type that a cell or cells of a range/array contain. Thus, it is spill-compatible as well. It has two parameters: reference (required) and analysis_type (optional, which specifies the mode/type of data analysis). XTYPE operates in the following modes:
A) analysis_type omitted or 1: In this "basic" mode, it outputs one of the following five types of data for the selected reference:
dt:NUMBER
dt:TEXT
dt:BLANK
dt:LOGICAL
dt:ERROR
B) analysis_type 1: In this advanced mode, it provides more detailed information on the BLANK, LOGICAL, and ERROR types and outputs one of the following data types for the selected reference:
dt:NUMBER
dt:TEXT
dt:BLANK_REAL or dt:BLANK_FORMULA
dt:LOGICAL_TRUE or dt:LOGICAL_FALSE
dt:ERROR_EXTERNAL! or dt:ERROR_NULL! or dt:ERROR_DIV/0! or dt:ERROR_VALUE! or dt:ERROR_REF! or dt:ERROR_NAME? or dt:ERROR_NUM! or dt:ERROR_N/A or dt:ERROR_GETTING_DATA or "dt:ERROR_SPILL! or dt:ERROR_CONNECT! or dt:ERROR_BLOCKED! or dt:ERROR_UNKNOWN! or dt:ERROR_FIELD! or dt:ERROR_CALC!
C) analysis_type 2: it acts exactly as the Excel's TYPE() function
D) analysis_type 3: it acts as the Excel's TYPE() function, but outputs the data type in the XTYPE style. (This demonstrates the utility of XTYPE over TYPE, as TYPE outputs "1 or number" for real blanks and "2 or text" for formula blanks; see attached XL2BB.)
E) analysis_type 4: it acts exactly as the Excel's CELL("type",) function with the added bonus that it is spill-compatible, (while CELL("type",) on its own is not spill-compatible).
Excel Formula:
=LAMBDA(reference,[analysis_type],
LET(at,analysis_type,
IF(ISERROR(MATCH(at,{0,1,2,3,4},0)),
UNIQUE(NA()),
LET(ref,reference,
IF(OR(at="",at=0),
IF(ISERROR(ref),"dt:ERROR",IF(ref="","dt:BLANK",IF(ISNUMBER(ref),"dt:NUMBER",IF(ISTEXT(ref),"dt:TEXT",IF(OR(TEXT(IFERROR(ref,""),10)="TRUE",TEXT(IFERROR(ref,""),10)="FALSE"),"dt:LOGICAL","dt:OTHER"))))),
IF(at=1,
IF(ISERROR(ref),SWITCH(ERROR.TYPE(ref),0,"dt:ERROR_EXTERNAL!",1,"dt:ERROR_NULL!",2,"dt:ERROR_DIV/0!",3,"dt:ERROR_VALUE!",4,"dt:ERROR_REF!",5,"dt:ERROR_NAME?",6,"dt:ERROR_NUM!",7,"dt:ERROR_N/A",8,"dt:ERROR_GETTING_DATA",9,"dt:ERROR_SPILL!",10,"dt:ERROR_CONNECT!",11,"dt:ERROR_BLOCKED!",12,"dt:ERROR_UNKNOWN!",13,"dt:ERROR_FIELD!",14,"dt:ERROR_CALC!"),IF(ref="",IF(ISBLANK(ref),"dt:BLANK_REAL","dt:BLANK_Formula"),IF(ISNUMBER(ref),"dt:NUMBER",IF(ISTEXT(ref),"dt:TEXT",LET(x,TEXT(IFERROR(ref,""),10)="TRUE",y,TEXT(IFERROR(ref,""),10)="FALSE",IF(OR(x,y),IF(x,"dt:LOGICAL_TRUE",IF(y,"dt:LOGICAL_FALSE")),"dt:OTHER")))))),
LET(res,MAP(ref,LAMBDA(mref,IF(OR(at=2,at=3),TYPE(mref),CELL("type",mref)))),SWITCH(at,2,res,3,SWITCH(res,1,"dt:NUMBER",2,"dt:TEXT",4,"dt:LOGICAL",16,"dt:ERROR"),4,res))
)
)
)
)
)
)
xtype.xlsx | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | H | I | J | K | L | |||
1 | ||||||||||||||
2 | #CALC! | |||||||||||||
3 | type: | number | text | error | (real) blank | logical (false) | (formula) blank | logical (true) | text | error | ||||
4 | cell: | 2 | b | #N/A | FALSE | TRUE | * | #DIV/0! | ||||||
5 | parameters | |||||||||||||
6 | individual cells | |||||||||||||
7 | none | dt:NUMBER | dt:TEXT | dt:ERROR | dt:BLANK | dt:LOGICAL | dt:BLANK | dt:LOGICAL | dt:TEXT | dt:ERROR | ||||
8 | 0 | dt:NUMBER | dt:TEXT | dt:ERROR | dt:BLANK | dt:LOGICAL | dt:BLANK | dt:LOGICAL | dt:TEXT | dt:ERROR | ||||
9 | 1 | dt:NUMBER | dt:TEXT | dt:ERROR_N/A | dt:BLANK_REAL | dt:LOGICAL_FALSE | dt:BLANK_Formula | dt:LOGICAL_TRUE | dt:TEXT | dt:ERROR_DIV/0! | ||||
10 | 2 | 1 | 2 | 16 | 1 | 4 | 2 | 4 | 2 | 16 | ||||
11 | 3 | dt:NUMBER | dt:TEXT | dt:ERROR | dt:NUMBER | dt:LOGICAL | dt:TEXT | dt:LOGICAL | dt:TEXT | dt:ERROR | ||||
12 | 4 | v | l | v | b | v | l | v | l | v | ||||
13 | spills | |||||||||||||
14 | none | dt:NUMBER | dt:TEXT | dt:ERROR | dt:BLANK | dt:LOGICAL | dt:BLANK | dt:LOGICAL | dt:TEXT | dt:ERROR | ||||
15 | 0 | dt:NUMBER | dt:TEXT | dt:ERROR | dt:BLANK | dt:LOGICAL | dt:BLANK | dt:LOGICAL | dt:TEXT | dt:ERROR | ||||
16 | 1 | dt:NUMBER | dt:TEXT | dt:ERROR_N/A | dt:BLANK_REAL | dt:LOGICAL_FALSE | dt:BLANK_Formula | dt:LOGICAL_TRUE | dt:TEXT | dt:ERROR_DIV/0! | ||||
17 | 2 | 1 | 2 | 16 | 1 | 4 | 2 | 4 | 2 | 16 | ||||
18 | 3 | dt:NUMBER | dt:TEXT | dt:ERROR | dt:NUMBER | dt:LOGICAL | dt:TEXT | dt:LOGICAL | dt:TEXT | dt:ERROR | ||||
19 | 4 | v | l | v | b | v | l | v | l | v | ||||
20 | no cells for input | |||||||||||||
21 | none | dt:BLANK | ||||||||||||
22 | 0 | dt:BLANK | ||||||||||||
23 | 1 | dt:BLANK_REAL | ||||||||||||
24 | 2 | #VALUE! | ||||||||||||
25 | 3 | #VALUE! | ||||||||||||
26 | 4 | #VALUE! | ||||||||||||
27 | no parameters | #VALUE! | ||||||||||||
28 | wrong parameter | #N/A | ||||||||||||
29 | ||||||||||||||
Sheet3 |
Cell Formulas | ||
---|---|---|
Range | Formula | |
B2 | B2 | =LAMBDA(reference,[analysis_type],LET(at,analysis_type,IF(ISERROR(MATCH(at,{0,1,2,3,4},0)),UNIQUE(NA()),LET(ref,reference,IF(OR(at="",at=0),IF(ISERROR(ref),"dt:ERROR",IF(ref="","dt:BLANK",IF(ISNUMBER(ref),"dt:NUMBER",IF(ISTEXT(ref),"dt:TEXT",IF(OR(TEXT(IFERROR(ref,""),10)="TRUE",TEXT(IFERROR(ref,""),10)="FALSE"),"dt:LOGICAL","dt:OTHER"))))),IF(at=1,IF(ISERROR(ref),SWITCH(ERROR.TYPE(ref),0,"dt:ERROR_EXTERNAL!",1,"dt:ERROR_NULL!",2,"dt:ERROR_DIV/0!",3,"dt:ERROR_VALUE!",4,"dt:ERROR_REF!",5,"dt:ERROR_NAME?",6,"dt:ERROR_NUM!",7,"dt:ERROR_N/A",8,"dt:ERROR_GETTING_DATA",9,"dt:ERROR_SPILL!",10,"dt:ERROR_CONNECT!",11,"dt:ERROR_BLOCKED!",12,"dt:ERROR_UNKNOWN!",13,"dt:ERROR_FIELD!",14,"dt:ERROR_CALC!"),IF(ref="",IF(ISBLANK(ref),"dt:BLANK_REAL","dt:BLANK_Formula"),IF(ISNUMBER(ref),"dt:NUMBER",IF(ISTEXT(ref),"dt:TEXT",LET(x,TEXT(IFERROR(ref,""),10)="TRUE",y,TEXT(IFERROR(ref,""),10)="FALSE",IF(OR(x,y),IF(x,"dt:LOGICAL_TRUE",IF(y,"dt:LOGICAL_FALSE")),"dt:OTHER")))))),LET(res,MAP(ref,LAMBDA(mref,IF(OR(at=2,at=3),TYPE(mref),CELL("type",mref)))),SWITCH(at,2,res,3,SWITCH(res,1,"dt:NUMBER",2,"dt:TEXT",4,"dt:LOGICAL",16,"dt:ERROR"),4,res)))))))) |
E4 | E4 | =LOOKUP(C2,D2:E2) |
H4 | H4 | =IF(P4>2,1,"") |
K4 | K4 | =1/0 |
C7:K7 | C7 | =XTYPE(C4) |
C8:K8 | C8 | =XTYPE(C4,0) |
C9:K9 | C9 | =XTYPE(C4,1) |
C10:K10 | C10 | =XTYPE(C4,2) |
C11:K11 | C11 | =XTYPE(C4,3) |
C12:K12 | C12 | =XTYPE(C4,4) |
C14:K14 | C14 | =XTYPE(C4:K4) |
C15:K15 | C15 | =XTYPE(C4:K4,0) |
C16:K16 | C16 | =XTYPE(C4:K4,1) |
C17:K17 | C17 | =XTYPE(C4:K4,2) |
C18:K18 | C18 | =XTYPE(C4:K4,3) |
C19:K19 | C19 | =XTYPE(C4:K4,4) |
C21 | C21 | =XTYPE(,) |
C22 | C22 | =XTYPE(,0) |
C23 | C23 | =XTYPE(,1) |
C24 | C24 | =XTYPE(,2) |
C25 | C25 | =XTYPE(,3) |
C26 | C26 | =XTYPE(,4) |
C27 | C27 | =XTYPE() |
C28 | C28 | =XTYPE(C4:K4,5) |
Dynamic array formulas. |
Please feel free to share any thoughts or suggestions.
Upvote
0