How to use the TYPE function
What is the TYPE function?
The TYPE function returns a number representing what type of data is returned by a function or formula.
Table of Contents
1. Introduction
What is a formula?
A formula in Excel is an expression that calculates a value based on the values in other cells. Formulas must start with an equals sign "=" and can contain cell references, math operators, functions, constants, arrays, etc. They are used to perform calculations in Excel.
Related TYPE functions
Excel Function | Description |
---|---|
TYPE(value) | Returns a number indicating the data type of value |
INFO(type_text) | Returns information about the current operating environment |
ERROR.TYPE(error_val) | Returns a number corresponding to the type of error in error_val |
CELL(info_type, reference) | Returns information about the formatting, location, or contents of a cell |
2. Syntax
TYPE(value)
value | Required. Any value. |
If value is | Type function returns |
---|---|
Number | 1 |
Text | 2 |
Logical value | 4 |
Error value | 16 |
Array | 64 |
What is a number?
A number in Excel refers to numeric data entered without quotation marks and are aligned to the right. Numbers can be integers, decimals, percentages, formatted numbers, results of formulas.
What is text in Excel?
Excel tries to identify inserted values automatically, text values are left-aligned. Boolean values and error values are centered in cells, and numerical values are right-aligned. You can change the alignment if you like.
Cells containing text values evaluates to TRUE by the ISTEXT function. The ISNTEXT function lets you check a value programmatically in a formula instead of visually identify values by their position in a cell.
What is an error value?
An error value is returned when something is wrong, it may be a formula that contains an error, a function with missing parameters or a misspelled function etc.
Here are a few common errors in Excel:
- #NULL error - This error occurs most often if you by mistake use a space character in a formula where it shouldn't be. Excel interprets a space character as an intersection operator. If the ranges don't intersect an #NULL error is returned. The #NULL! error occurs when a formula attempts to calculate the intersection of two ranges that do not actually intersect. This can happen when the wrong range operator is used in the formula, or when the intersection operator (represented by a space character) is used between two ranges that do not overlap. To fix this error double check that the ranges referenced in the formula that use the intersection operator actually have cells in common.
- #SPILL error - The #SPILL! error occurs only in version Excel 365 and is caused by a dynamic array being to large, meaning there are cells below and/or to the right that are not empty. This prevents the dynamic array formula expanding into new empty cells.
- #DIV/0 error - This error happens if you try to divide a number by 0 (zero) or a value that equates to zero which is not possible mathematically. Use the "Evaluate formula" tool to pinpoint the exact location in the formula where this error occurs. The "Evaluate formula" tool is located on the "Formulas" tab on the ribbon. Select the cell containing the #DIV/0 error and then press with left mouse button on the "Evaluate formula button".
- #VALUE error - The #VALUE error occurs when a formula has a value that is of the wrong data type. Such as text where a number is expected or when dates are evaluated as text.
- #REF error - The #REF error happens when a cell reference is invalid. This can happen if a cell is deleted that is referenced by a formula.
- #NAME error - The #NAME error happens if you misspelled a function or a named range.
- #NUM error - The #NUM error shows up when you try to use invalid numeric values in formulas, like square root of a negative number.
- #N/A error - The #N/A error happens when a value is not available for a formula or found in a given cell range, for example in the VLOOKUP or MATCH functions.
- #GETTING_DATA error - The #GETTING_DATA error shows while external sources are loading, this can indicate a delay in fetching the data or that the external source is unavailable right now.
What is an array in Excel?
Some functions return an array of values instead of a single value. Excel 365 handles these arrays automatically whereas previous versions need to be entered as an array formula. For example, the FREQUENCY function returns multiple values.
You can also create a formula that returns multiple values, in Excel 365 they are named dynamic array formulas and in earlier versions named array formulas. The most simple dynamic array formula I know is this: = A1:A2, it returns two values populated in cells A1 and A2.
3. Example
This example demonstrates how to use the TYPE function. The TYPE function returns a number representing what type of data is returned. Cells B3:B8 contains the function and an argument. Cells C3:C8 contains the actual formula in the corresponding adjacent cell on the same row, this makes it easier to see what each cell contains.
The first example in cell B3 demonstrates the output number corresponding to "A" which is a text string.
Formula in cell B3:
The formula in cell B3 returns 2 which represents text.
The second example in cell B4 demonstrates the output number corresponding to 1 which is a numeric value.
Formula in cell B4:
The formula in cell B4 returns 1 which represents number.
The third example in cell B5 shows the output number corresponding to 0 (zero) which is a numeric value.
Formula in cell B4:
The formula in cell B4 returns 1 which represents number.
The fourth example in cell B5 demonstrates the output number corresponding to TRUE which is a boolean value.
Formula in cell B5:
The formula in cell B4 returns 4 which represents boolean value TRUE or FALSE.
The fourth example in cell B6 demonstrates the output number corresponding to #DIV/0! which is an error value.
Formula in cell B6:
The formula in cell B4 returns 16 which represents an error value.
The fifth example in cell B7 demonstrates the output number corresponding to an array which is a multiple values.
Formula in cell B7:
The formula in cell B4 returns 64 which represents the number corresponding to an array.
You can't use the TYPE function to determine the type of value in a specific cell using a cell reference, the TYPE function will then return the type of the formula's returning value. Even if the formula returns an array the TYPE function returns only the type of the value displayed in that cell.
4. TYPE function array
This example demonstrates that the TYPE function processes the value that the formula returns and not the array. The picture above demonstrates an array entered in cell range B3:B4:
The TYPE function returns 1 and 2 which represents number type and text type, however, the output is an array and should return 64.
5. Example 3
This example shows how to process an array using the BYROW function, as well as aggregate the values and display a summary. The image above shows different values with different data types in cell range B3:B10.
Excel 365 dynamic array formula in cell D3:
This formula works only in Excel 365, it contains a few functions available only in Excel 365. The formula spills values automatically to cells below and to cells to the right as far as needed.
The formula returns an array that contains the data types in the first column (D3:D6) and their count meaning how many values of each data type are present in cell range B3:B10.
- The first data typ 1 represents "number", it has 2 instances in B3:B10 which are B4 and B8.
- The second data type is 2 which represents text. It has 4 instances in cells B3,B6,B7, and B9.
- The third data type is 4 meaning boolean values. Only one instance exists and that value is in cell B5.
- The last data typ is 16 and it represents error values. Also only one error is displayed which is in cell B10.
Here is a quick break-down of the formula:
- TYPE(a): a is a variable. TYPE returns the data type of the variable.
- LAMBDA(a, TYPE(a)): LAMBDA function is required for the BYROW function to work properly. It passes each value in the row to the TYPE function.
- BYROW(B3:B10,LAMBDA(a,TYPE(a))): The BYROW function passes each value in cells B3:B10 to the LAMBDA function.
- GROUPBY( BYROW(B3:B10,LAMBDA(a,TYPE(a))) , BYROW(B3:B10,LAMBDA(a,TYPE(a))) ,COUNTA): The GROUPBY function aggregates values,
- LET(x, BYROW(B3:B10,LAMBDA(a,TYPE(a))), GROUPBY(x,x,COUNTA)): The LET function lets you shorten formulas if repeated calculations are present.
6. Function not working
The TYPE function returns #NAME? error if you misspell the function name. It does not propagate errors, meaning that if the input contains an error (e.g., #VALUE!, #REF!), the function will return the same error.
6.1 Troubleshooting the error value
When you encounter an error value in a cell a warning symbol appears, displayed in the image above. Press with mouse on it to see a pop-up menu that lets you get more information about the error.
- The first line describes the error if you press with left mouse button on it.
- The second line opens a pane that explains the error in greater detail.
- The third line takes you to the "Evaluate Formula" tool, a dialog box appears allowing you to examine the formula in greater detail.
- This line lets you ignore the error value meaning the warning icon disappears, however, the error is still in the cell.
- The fifth line lets you edit the formula in the Formula bar.
- The sixth line opens the Excel settings so you can adjust the Error Checking Options.
Here are a few of the most common Excel errors you may encounter.
#NULL error - This error occurs most often if you by mistake use a space character in a formula where it shouldn't be. Excel interprets a space character as an intersection operator. If the ranges don't intersect an #NULL error is returned. The #NULL! error occurs when a formula attempts to calculate the intersection of two ranges that do not actually intersect. This can happen when the wrong range operator is used in the formula, or when the intersection operator (represented by a space character) is used between two ranges that do not overlap. To fix this error double check that the ranges referenced in the formula that use the intersection operator actually have cells in common.
#SPILL error - The #SPILL! error occurs only in version Excel 365 and is caused by a dynamic array being to large, meaning there are cells below and/or to the right that are not empty. This prevents the dynamic array formula expanding into new empty cells.
#DIV/0 error - This error happens if you try to divide a number by 0 (zero) or a value that equates to zero which is not possible mathematically.
#VALUE error - The #VALUE error occurs when a formula has a value that is of the wrong data type. Such as text where a number is expected or when dates are evaluated as text.
#REF error - The #REF error happens when a cell reference is invalid. This can happen if a cell is deleted that is referenced by a formula.
#NAME error - The #NAME error happens if you misspelled a function or a named range.
#NUM error - The #NUM error shows up when you try to use invalid numeric values in formulas, like square root of a negative number.
#N/A error - The #N/A error happens when a value is not available for a formula or found in a given cell range, for example in the VLOOKUP or MATCH functions.
#GETTING_DATA error - The #GETTING_DATA error shows while external sources are loading, this can indicate a delay in fetching the data or that the external source is unavailable right now.
6.2 The formula returns an unexpected value
To understand why a formula returns an unexpected value we need to examine the calculations steps in detail. Luckily, Excel has a tool that is really handy in these situations. Here is how to troubleshoot a formula:
- Select the cell containing the formula you want to examine in detail.
- Go to tab “Formulas” on the ribbon.
- Press with left mouse button on "Evaluate Formula" button. A dialog box appears.
The formula appears in a white field inside the dialog box. Underlined expressions are calculations being processed in the next step. The italicized expression is the most recent result. The buttons at the bottom of the dialog box allows you to evaluate the formula in smaller calculations which you control. - Press with left mouse button on the "Evaluate" button located at the bottom of the dialog box to process the underlined expression.
- Repeat pressing the "Evaluate" button until you have seen all calculations step by step. This allows you to examine the formula in greater detail and hopefully find the culprit.
- Press "Close" button to dismiss the dialog box.
There is also another way to debug formulas using the function key F9. F9 is especially useful if you have a feeling that a specific part of the formula is the issue, this makes it faster than the "Evaluate Formula" tool since you don't need to go through all calculations to find the issue..
- Enter Edit mode: Double-press with left mouse button on the cell or press F2 to enter Edit mode for the formula.
- Select part of the formula: Highlight the specific part of the formula you want to evaluate. You can select and evaluate any part of the formula that could work as a standalone formula.
- Press F9: This will calculate and display the result of just that selected portion.
- Evaluate step-by-step: You can select and evaluate different parts of the formula to see intermediate results.
- Check for errors: This allows you to pinpoint which part of a complex formula may be causing an error.
The image above shows cell reference B3 converted to hard-coded value using the F9 key. The TYPE function requires a correctly spelled function name which is not the case in this example. We have found what is wrong with the formula.
Tips!
- View actual values: Selecting a cell reference and pressing F9 will show the actual values in those cells.
- Exit safely: Press Esc to exit Edit mode without changing the formula. Don't press Enter, as that would replace the formula part with the calculated value.
- Full recalculation: Pressing F9 outside of Edit mode will recalculate all formulas in the workbook.
Remember to be careful not to accidentally overwrite parts of your formula when using F9. Always exit with Esc rather than Enter to preserve the original formula. However, if you make a mistake overwriting the formula it is not the end of the world. You can “undo” the action by pressing keyboard shortcut keys CTRL + z or pressing the “Undo” button
6.3 Other errors
Floating-point arithmetic may give inaccurate results in Excel - Article
Floating-point errors are usually very small, often beyond the 15th decimal place, and in most cases don't affect calculations significantly.
Functions in 'Information' category
The TYPE function function is one of 19 functions in the 'Information' category.
How to comment
How to add a formula to your comment
<code>Insert your formula here.</code>
Convert less than and larger than signs
Use html character entities instead of less than and larger than signs.
< becomes < and > becomes >
How to add VBA code to your comment
[vb 1="vbnet" language=","]
Put your VBA code here.
[/vb]
How to add a picture to your comment:
Upload picture to postimage.org or imgur
Paste image link to your comment.
Contact Oscar
You can contact me through this contact form