How to use the T function
What is the T function?
The T function returns a text value if the argument is a text value.
The T function in Excel is rarely needed to convert values in formulas. Excel automatically handles conversion of numbers, text, logical values, and error values as required. T is provided for compatibility with other spreadsheet applications. In most cases, Excel will format values correctly without requiring the T function.
Only use T if you find Excel is not properly converting a value to text in a specific formula. In general, you can avoid using it entirely since Excel auto-converts types seamlessly in most situations.
Table of Contents
1. Introduction
How does Excel handle values?
Excel changes the position of the value in a cell based on the value type. For example:
- Cells B2 and B8 contain text values that are aligned left.
- Cell B3 contains a number that is right aligned in the cell.
- Cell B4 contains a date, which Excel handles as a number. The date is right aligned.
- Cells B5 and B6 contain boolean values, which are automatically centered in the cell.
- Cell B7 contains an error value, which is also centered.
Note, the user may have changed the cell formatting making these guidelines useless. To revert back to default settings check that the align buttons are not selected:
- Align left
- Center
- Align right
What is the difference between the T and N function?
The T function deletes numbers and dates, the N function removes text values.
What other functions let you identify/format/convert values?
ISTEXT function | TEXT function | VALUETOTEXT function
2. Syntax
T(value)
value | Required. The value you want to evaluate. |
3. Example 1
The image above demonstrates the T function in cells C3:C8, the source data is in cells B3:B8. Column D shows the formulas in C3:C8. The T function returns a text value if the argument is a text value, all other values are ignored except error values.
The T function in cell C3 contains a cell reference to cell B2. B2 contains a number, the T function returns "" which is nothing.
Formula in cell C3:
Cell B4 contains a date and Excel dates are actually numbers and the T function returns the "" (nothing). Excel represents dates as serial numbers, where each date is assigned a unique number starting from January 1, 1900, which is represented as the serial number 1 and 43466 represents 1/1/2019. The serial number representation of dates allows you to perform various calculations with dates in Excel. Adding or subtracting a number to a date serial number will result in a new date serial number, which can then be formatted as a date.
Cells B5 and B6 are TRUE and FALSE respectively, the T function returns "" (nothing) for both these boolean values.
Cells B7 and B8 contain an error value and a text value, the T function returns both values. In summary, the T function returns a value if it is text or an error and nothing if the value is a number, date or boolean value.
4. Example 2
Can I use the T function in an array formula?
It depends on the Excel version you are using, the T function in Excel 365 is able to process an an array. Earlier versions are not, as far as I know, see the image below.
Formula in cell C3:
This formula uses the BYROW and LAMBDA functions which are part of the Excel 365 dynamic array formulas. Here's a breakdown of what the formula does:
- BYROW(B3:B8,...): This function applies a calculation to each row of the range B3:B8.
- LAMBDA(a,T(a)): This is a lambda function which is required in the BYROW function. In this case, the lambda function takes a single argument a which is a single value from B3:B8, row by row. It returns the result of the T function using variable a.
- The T function is a text function that converts its argument to text. So, in this case, the lambda function is essentially converting each value in the range B3:B8 to text.
When you put it all together, the formula makes it possible for the T function to process an array.
In earlier Excel versions, the T function returns only the first value in an array. The example above demonstrates that the T function returns an empty text string ("") because the first value in the cell range B3:B8 is 23. Since 23 is a number, the T function converts it to an empty text string.
5. Example 3
This example demonstrates the T function filtering out all characters except letters. In other words, the formula in cell C5 extracts the text characters from the string in cell C3. Cell C3 contains: ABC123CDG4VX
Formula in cell C3:
We get ABCCDGVX If we remove the numbers from the string filtering out 123 and 4. Here is how the formula works:
- LEN(C3): The LEN function calculates the number of characters n in cell C3.
- SEQUENCE(LEN(C3)): The SEQUENCE function creates a sequence from 1 to n.
- MID(C3, SEQUENCE(LEN(C3)), 1): The MID function extracts each character and returns an array of characters.
- VALUE(MID(C3, SEQUENCE(LEN(C3)), 1): Value function converts a text string that represents a number to a number.
- IFERROR(VALUE(MID(C3, SEQUENCE(LEN(C3)), 1)),MID(C3, SEQUENCE(LEN(C3)), 1)): Replaces errors with text characters.
- T(IFERROR(VALUE(MID(C3, SEQUENCE(LEN(C3)), 1)), MID(C3, SEQUENCE(LEN(C3)), 1))): Extract letters and returns nothing for all remaining characters.
- TEXTJOIN(,TRUE,T(IFERROR(VALUE(MID(C3, SEQUENCE(LEN(C3)), 1)),MID(C3, SEQUENCE(LEN(C3)), 1)))): Joins the text characters and returns a text string.
6. T function not working
The above image shows that the T function returns numbers, dates and boolean values, why does that happen? Select these cells to evaluate the values in the formula bar.
The apostrophe character converts numbers, dates and boolean values to text values, there is no way to tell unless you select one of the values and examine the formula bar.
Other errors
The #NAME error appears if the function name is misspelled.
Other errors may have their origin in the source data. Check the source data for errors.
Useful links
T Function - Microsoft support
T Function
Functions in 'Text' category
The T function function is one of 29 functions in the 'Text' 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