XERROR(error_type)
error_type
Required. Specifies the type of output error and takes integers from 0 to 14

XERROR allows for conveniently generating most of the Excel errors as output to functions

Rnkhch

Well-known Member
Joined
Apr 28, 2018
Messages
578
Office Version
  1. 365
Platform
  1. Windows
XERROR allows for conveniently generating most of the Excel errors as output to functions

With XERROR, it is very easy to generate all but four of the Excel errors as output to functions. Error types 0, 1, 2, 3, 4, 5, 6, 7, 8, 13, and 14 (i.e. #EXTERNAL!, #NULL!, #DIV/0!, #VALUE!, #REF!, #NAME?, #NUM!, #N/A, #GETTING_DATA, #FIELD!, and #CALC!, respectively) are currently supported. For error types 9, 10, 11, and 12 (i.e. #SPILL!, #CONNECT!, #BLOCKED!, and #UNKNOWN!, respectively), XERROR returns the "Error not supported!" message. For any other invalid error number, XERROR returns the "Invalid error number!" message.

Excel Formula:
=LAMBDA(error_type,
   LET(e,error_type+1,
      IF(OR(e<1,e>15,MOD(e,1)<>0),
         "Invalid error number!",
         IF(ISERROR(MATCH(e,{1,2,3,4,5,6,7,8,9,14,15},0)),
            "Error not supported!",
            CHOOSE(e,#EXTERNAL!,#NULL!,#DIV/0!,#VALUE!,#REF!,#NAME?,#NUM!,#N/A,#GETTING_DATA,,,,,INDIRECT("").a,LAMBDA(""))
         )
      )
   )
)

Cell Formulas
RangeFormula
C2C2=LAMBDA(error_type,LET(e,error_type+1,IF(OR(e<1,e>15,MOD(e,1)<>0),"Invalid error number!",IF(ISERROR(MATCH(e,{1,2,3,4,5,6,7,8,9,14,15},0)),"Error not supported!",CHOOSE(e,#EXTERNAL!,#NULL!,#DIV/0!,#VALUE!,Sheet1!#REF!,#NAME?,#NUM!,#N/A,#GETTING_DATA,,,,,INDIRECT("").a,LAMBDA(""))))))
C4C4=XERROR(0)
D4:D22D4=TYPE(C4)
C5C5=XERROR(1)
C6C6=XERROR(2)
C7C7=XERROR(3)
C8C8=XERROR(4)
C9C9=XERROR(5)
C10C10=XERROR(6)
C11C11=XERROR(7)
C12C12=XERROR(8)
C13C13=XERROR(9)
C14C14=XERROR(10)
C15C15=XERROR(11)
C16C16=XERROR(12)
C17C17=XERROR(13)
C18C18=XERROR(14)
C19C19=XERROR(-1)
C20C20=XERROR(2.2)
C21C21=XERROR(17)
C22C22=XERROR(17.3)



If anyone can come up with tricks to add support for the remaining four errors, please feel free to post an update here.

This work is based on the discussion at the following thread:
 
Upvote 0
Updated code:
1) fixes the issue where selecting a blank cell for input led to displaying the #EXTERNAL! error
2) fixes the #REF! error issue where the code would change to include the sheet name (such as Sheet1!#REF!)
3) enables spill support

XERROR
VBA Code:
=LAMBDA(error_type,
   IF(
      MAP(IF(ISNUMBER(error_type),error_type),LAMBDA(a,ISERROR(MATCH(a,ErrorNs,0)))),
      "Invalid error number!",
      IF(
         ISERROR(MATCH(error_type,{9,10,11,12},0)),
         LET(e,error_type+1,CHOOSE(e,#EXTERNAL!,#NULL!,#DIV/0!,#VALUE!,INDEX("",2),#NAME?,#NUM!,#N/A,#GETTING_DATA,,,,,INDIRECT("").a,LAMBDA(""))),
         "Error not supported!"
         )
      )
)

ErrorNs
VBA Code:
={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14}

XERROR.xlsx
ABCDEFGHIJKLM
1
2#CALC!
3
4parameteroutput
5no parameter#VALUE!
6blank parameterInvalid error number!
7blank cell parameterInvalid error number!
8
9error numbers from cellserror numbers input directlyerror numbers input directly as array
10error numberoutputdata typespill outputdata typeoutputdata typeoutputdata type
110#EXTERNAL!16#EXTERNAL!16#EXTERNAL!16#EXTERNAL!16
121#NULL!16#NULL!16#NULL!16#NULL!16
132#DIV/0!16#DIV/0!16#DIV/0!16#DIV/0!16
143#VALUE!16#VALUE!16#VALUE!16#VALUE!16
154#REF!16#REF!16#REF!16#REF!16
165#NAME?16#NAME?16#NAME?16#NAME?16
176#NUM!16#NUM!16#NUM!16#NUM!16
187#N/A16#N/A16#N/A16#N/A16
198#GETTING_DATA16#GETTING_DATA16#GETTING_DATA16#GETTING_DATA16
209Error not supported!2Error not supported!2Error not supported!2Error not supported!2
2110Error not supported!2Error not supported!2Error not supported!2Error not supported!2
2211Error not supported!2Error not supported!2Error not supported!2Error not supported!2
2312Error not supported!2Error not supported!2Error not supported!2Error not supported!2
2413#FIELD!16#FIELD!16#FIELD!16#FIELD!16
2514#CALC!16#CALC!16#CALC!16#CALC!16
2615Invalid error number!2Invalid error number!2Invalid error number!2Invalid error number!2
2717.5Invalid error number!2Invalid error number!2Invalid error number!2Invalid error number!2
28-32Invalid error number!2Invalid error number!2Invalid error number!2Invalid error number!2
29TRUEInvalid error number!2Invalid error number!2Invalid error number!2Invalid error number!2
30FALSEInvalid error number!2Invalid error number!2Invalid error number!2Invalid error number!2
31#DIV/0!Invalid error number!2Invalid error number!2Invalid error number!2Invalid error number!2
32
Sheet1
Cell Formulas
RangeFormula
B2B2=LAMBDA(error_type,IF(MAP(IF(ISNUMBER(error_type),error_type),LAMBDA(a,ISERROR(MATCH(a,ErrorNs,0)))),"Invalid error number!",IF(ISERROR(MATCH(error_type,{9,10,11,12},0)),LET(e,error_type+1,CHOOSE(e,#EXTERNAL!,#NULL!,#DIV/0!,#VALUE!,INDEX("",2),#NAME?,#NUM!,#N/A,#GETTING_DATA,,,,,INDIRECT("").a,LAMBDA(""))),"Error not supported!")))
C5C5=XERROR()
C6C6=XERROR("")
C7,C11:C31C7=XERROR(B7)
L11:L31,F11:F31,D11:D31,I11:I31D11=TYPE(C11)
E11:E31E11=XERROR(B11:B31)
H11H11=XERROR(0)
H12H12=XERROR(1)
H13H13=XERROR(2)
H14H14=XERROR(3)
H15H15=XERROR(4)
H16H16=XERROR(5)
H17H17=XERROR(6)
H18H18=XERROR(7)
H19H19=XERROR(8)
H20H20=XERROR(9)
H21H21=XERROR(10)
H22H22=XERROR(11)
H23H23=XERROR(12)
H24H24=XERROR(13)
H25H25=XERROR(14)
H26H26=XERROR(15)
H27H27=XERROR(17.5)
H28H28=XERROR(-32)
H29H29=XERROR(TRUE)
H30H30=XERROR(FALSE)
H31H31=XERROR(#DIV/0!)
K11:K31K11=XERROR({0;1;2;3;4;5;6;7;8;9;10;11;12;13;14;15;17.5;-32;TRUE;FALSE;#DIV/0!})
Dynamic array formulas.
 
Updated code: addresses the recent changes in the error types and their associated numbers

XERROR
Excel Formula:
=LAMBDA(error_type,
   IF(
      MAP(IF(ISNUMBER(error_type),error_type),LAMBDA(a,ISERROR(MATCH(a,ErrorNs,0)))),
      "Invalid error number!",
      IF(
         ISERROR(MATCH(error_type,{9,10,11,12,19},0)),
         LET(e,error_type,CHOOSE(e,#NULL!,#DIV/0!,#VALUE!,INDEX("",2),#NAME?,#NUM!,#N/A,#GETTING_DATA,,,,,INDIRECT("").a,LAMBDA(""))),
         "Error not supported!"
         )
      )
)

ErrorNs
Excel Formula:
={1,2,3,4,5,6,7,8,9,10,11,12,13,14,19}


XERROR2.xlsx
ABCDEFGHIJKLMNOP
1
2#CALC!basic types
31dt:NUMBER
4error numbers from cellserror numbers input directlyerror numbers input directly as array2dt:TEXT
5error numberoutputdata typespill outputdata typeoutputdata typeoutputdata type3dt:BLANK
61#NULL!16#NULL!16#NULL!16#NULL!164dt:LOGICAL
72#DIV/0!16#DIV/0!16#DIV/0!16#DIV/0!1616dt:ERROR
83#VALUE!16#VALUE!16#VALUE!16#VALUE!16
94#REF!16#REF!16#REF!16#REF!16advanced types
105#NAME?16#NAME?16#NAME?16#NAME?161dt:NUMBER
116#NUM!16#NUM!16#NUM!16#NUM!162dt:TEXT
127#N/A16#N/A16#N/A16#N/A1631dt:BLANK_REAL
138#GETTING_DATA16#GETTING_DATA16#GETTING_DATA16#GETTING_DATA1632dt:BLANK_FORMULA
149Error not supported!2Error not supported!2Error not supported!2Error not supported!233dt:BLANK_SPACE
1510Error not supported!2Error not supported!2Error not supported!2Error not supported!234dt:BLANK_PASTED
1611Error not supported!2Error not supported!2Error not supported!2Error not supported!241dt:LOGICAL_TRUE
1712Error not supported!2Error not supported!2Error not supported!2Error not supported!242dt:LOGICAL_FALSE
1813#FIELD!16#FIELD!16#FIELD!16#FIELD!16161dt:ERROR_NULL!
1914#CALC!16#CALC!16#CALC!16#CALC!16162dt:ERROR_DIV/0!
2019Error not supported!2Error not supported!2Error not supported!2Invalid error number!2163dt:ERROR_VALUE!
2115Invalid error number!2Invalid error number!2Invalid error number!2Error not supported!2164dt:ERROR_REF!
2217.5Invalid error number!2Invalid error number!2Invalid error number!2Invalid error number!2165dt:ERROR_NAME?
23-32Invalid error number!2Invalid error number!2Invalid error number!2Invalid error number!2166dt:ERROR_NUM!
24bookInvalid error number!2Invalid error number!2Invalid error number!2Invalid error number!2167dt:ERROR_N/A
25TRUEInvalid error number!2Invalid error number!2Invalid error number!2Invalid error number!2168dt:ERROR_GETTING_DATA
26FALSEInvalid error number!2Invalid error number!2Invalid error number!2Invalid error number!2169dt:ERROR_SPILL!
27#DIV/0!Invalid error number!2Invalid error number!2Invalid error number!2Invalid error number!21610dt:ERROR_CONNECT!
28Invalid error number!21611dt:ERROR_BLOCKED!
291612dt:ERROR_UNKNOWN!
30parameteroutputblank parameterstypeoutput1613dt:ERROR_FIELD!
31no parameter#VALUE!31Invalid error number!1614dt:ERROR_CALC!
32blank parameterInvalid error number! 32Invalid error number!1619dt:ERROR_PYTHON!
33blank cell parameterInvalid error number! 33Invalid error number!
3434Invalid error number!
35
XERROR
Cell Formulas
RangeFormula
B2B2=LAMBDA(error_type,IF(MAP(IF(ISNUMBER(error_type),error_type),LAMBDA(a,ISERROR(MATCH(a,ErrorNs,0)))),"Invalid error number!",IF(ISERROR(MATCH(error_type,{9,10,11,12,19},0)),LET(e,error_type,CHOOSE(e,#NULL!,#DIV/0!,#VALUE!,INDEX("",2),#NAME?,#NUM!,#N/A,#GETTING_DATA,,,,,INDIRECT("").a,LAMBDA(""))),"Error not supported!")))
C6:C27C6=XERROR(B6)
L6:L27,F6:F27,D6:D27,I6:I28D6=TYPE(C6)
E6:E27E6=XERROR(B6:B27)
H6H6=XERROR(1)
H7H7=XERROR(2)
H8H8=XERROR(3)
H9H9=XERROR(4)
H10H10=XERROR(5)
H11H11=XERROR(6)
H12H12=XERROR(7)
H13H13=XERROR(8)
H14H14=XERROR(9)
H15H15=XERROR(10)
H16H16=XERROR(11)
H17H17=XERROR(12)
H18H18=XERROR(13)
H19H19=XERROR(14)
H20H20=XERROR(19)
H21H21=XERROR(15)
H22H22=XERROR(17.5)
H23H23=XERROR(-32)
H24H24=XERROR("book")
H25H25=XERROR(TRUE)
H26H26=XERROR(FALSE)
H27H27=XERROR(#DIV/0!)
H28H28=XERROR(book)
K6:K27K6=XERROR({1;2;3;4;5;6;7;8;9;10;11;12;13;14;15;19;17.5;-32;"book";TRUE;FALSE;#DIV/0!})
E32E32=IF(1,"")
C31C31=XERROR()
C32C32=XERROR("")
C33C33=XERROR(B29)
G31:G34G31=XERROR(E31)
Dynamic array formulas.
 

Forum statistics

Threads
1,223,885
Messages
6,175,186
Members
452,615
Latest member
bogeys2birdies

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