TYPE function
The TYPE function in Excel returns a number that corresponds to the type of data in a given value or expression. This function helps identify the type of content in a cell, such as whether it contains a number, text, logical value, error, etc.
Syntax:
TYPE(value)
Arguments:
- value: The value or reference to a cell that you want to check. This could be a number, text, logical value, error, or formula.
Return Values:
The TYPE function returns a numeric code based on the type of data:
1— Number: The value is a number.2— Text: The value is text (a string).4— Logical value: The value is a logical value (TRUEorFALSE).16— Error value: The value is an error (e.g.,#DIV/0!,#VALUE!, etc.).64— Array: The value is an array (usually occurs when referencing an array formula).
Example:
Example 1: Checking the type of a number
- Data in A1:
100 - Formula:
=TYPE(A1) - Result:
1(since A1 contains a number).
Example 2: Checking the type of text
- Data in B1:
"Hello" - Formula:
=TYPE(B1) - Result:
2(since B1 contains text).
Example 3: Checking the type of a logical value
- Data in C1:
TRUE - Formula:
=TYPE(C1) - Result:
4(since C1 contains a logical value).
Example 4: Checking the type of an error
- Data in D1:
#DIV/0!(division by zero error) - Formula:
=TYPE(D1) - Result:
16(since D1 contains an error value).
Example 5: Checking the type of an array (e.g., an array formula result)
- Array Formula in E1:
{=A1:A3*B1:B3} - Formula:
=TYPE(E1) - Result:
64(since E1 contains an array value).
Key Points:
- Data Type Identification: TYPE is useful for identifying the type of data in a cell or expression, which can be useful in debugging or when you need to handle different types of data in a formula.
- Numeric Codes: The function returns numeric codes representing the data type, which can be interpreted based on the list above.
- Error Handling: When you have mixed data types in a range and need to determine the exact type of each value, TYPE helps differentiate them.
Use Cases:
- Data Validation: Use TYPE to verify the type of data in a cell before performing calculations or operations.
=IF(TYPE(A1) = 1, A1 * 2, "Not a number") - Handling Different Data Types: Use TYPE to dynamically adjust your formulas based on the type of data present.
=IF(TYPE(A1) = 2, "It's text", "It's not text") - Error Checking: Use TYPE to check if a cell contains an error or logical value and handle it accordingly in formulas.