This tutorial explains the specificities of the Excel TEXT function and shows some clever ways to use Text formulas in Excel. Show
Microsoft Excel is all about numbers, and in your worksheets, you are likely to deal with numbers most of the time. However, there are situations when you need to convert numbers to text, and it is where the TEXT function steps in. Excel TEXT function - syntax and basic usesIn its pure essence, TEXT in Excel is used to convert a numeric value to a text string in a specific format. The syntax for the Excel TEXT function is as follows: Where:
The TEXT function is available in all versions of Excel 365, Excel 2021, Excel 2019, Excel 2016, Excel 2013, Excel 2010, Excel 2007, and lower. Generally, an Excel TEXT formula is used in the following situations:
For example, if you want to pull the date from cell A2 and show it in another cell in the traditional date format like "January 1, 2016", you use the following Excel TEXT formula: =TEXT(A2, "mmmm d, yyyy") The result will look similar to this:
Important note! The TEXT function in Excel converts a numeric value to a text strings. Consequently, you won't be able to use the result of your Text formula in other calculations. If there's such a need, you can keep the original values (hidden or kept out of sight), and use them in other formulas. Excel TEXT function format codesAs you have just seen, the syntax of the Excel TEXT function is very straightforward, a tricky part is supplying a proper format code that will output your number the way you want. Essentially, the TEXT function accepts most of the format codes used in Excel number formats. The table below lists the most common and frequently used ones.
Additionally, you can include any of the following characters in the format code, and they will be displayed exactly as entered.
The following spreadsheet shows how you can use a Text formula in Excel to apply different formatting types to the same value.
When using the Excel TEXT function with dates and times, you can use any of the following format codes.
The following spreadsheet shows a few Excel Text formulas for dates:
How to use TEXT function in Excel - formula examplesSo far, you might have an impression that the use of the Excel TEXT function is quite limited (because a value's display can easily be changed using the Format Cells dialog available via a cell's context menu or Ctrl+1 shortcut). The situation changes as soon as you start using TEXT in combination with other Excel functions. The below examples will give you a few inspirational ideas. Concatenate text and number (or date) in a custom formatWhen creating summary sheets or reports, you may often want not only calculate totals, percentages and the like, but also explain to your users what this or that number means. To do this, use the CONCATENATE function to join text and numbers, and the TEXT function to display the number (or date) like you want it. Example 1. Format numbers inside a text stringSupposing you calculate the total amount based on the unit price in cell A2, quantity in B2, and discount percentage in C2 using this calculation: =A2*B2*(1-C2). For your users to know exactly what the output number means, you wish to display it together with some explanatory text like "Your price is". Additionally, you want to show the currency symbol, thousands separator and two decimal places. To have it done, supply the above calculation in the 1st argument of the TEXT function, include the corresponding format code in the 2nd argument, and concatenate the Text formula with a string using either the ampersand operator or CONCATENATE function: ="Your price is "&TEXT(A2*B2*(1-C2), "$###,###.00") or = CONCATENATE("Your price is ",TEXT(A2*B2*(1-C2), "$###,###.00")) The following screenshot demonstrates the result: Example 2. Combine text and date in the desired formatWhen you return the current date using TODAY() or NOW() function, you may also want to display it in combination with some text so that no one has any doubt what day this date refers to. However, if you try to concatenate a text and date in the usual way: =CONCATENATE("Today is ", TODAY()) Excel will return a very odd result, something like "Today is 42198". The point is that in the internal Excel system, dates are stored as numbers, and that number appears in a concatenated text string. To fix this, use the TEXT function to display the date the way you want. For example, embedding the TODAY function in the Text formula with the format code "dddd d mmm, yyyy" will return a string similar to this: "Today is Monday 12 Dec, 2016". The complete formula goes as follows: =CONCATENATE("Today is ", TEXT(TODAY(), "dddd d mmm, yyyy")) or ="Today is " & TEXT(TODAY(), "dddd d mmm, yyyy") A few more formula examples can be found here: Concatenate numbers and dates in various formats. Add leading zeros to numbers with variable lengthsAs you know, Microsoft Excel automatically removes leading zeros typed before a number in a cell, which works fine in most situations. But what if you want to keep the preceding zeros? The Excel TEXT function can be an easy solution to pad numbers with leading zeros in a column, even if the original values are not the same length. Simply use the format code containing only zero placeholders like "0000000", where the number of zeros corresponds to the number of digits you want to display. For example, to display 7-digit numbers with leading zeros, use this formula (where A2 is the original number): =TEXT(A2,"0000000") As you can see in the screenshot below, our Excel Text formula adds as many leading zeros as necessary to make a 7-character long string (please remember, the result of the TEXT function in Excel is always a text string, even if it looks like a number). Convert values to phone numbers in a specific formatTurning a column of numeric values into telephone numbers may sound like a tricky task, but only until you remember that the Excel TEXT function allows using dashes and parentheses in format codes. So, to display a number in A2 in a traditional US local 7-digit phone format like 123-456, use this formula: =TEXT(A2, "###-####") If some of the original values may contain a domestic prefix (i.e. there can be both 7-digit or 10-digit numbers), include the following conditional format code to display 10-digit numbers in the (123) 456-789 format: =TEXT(A2,"[<=9999999]###-####;(###) ###-####") The screenshot below shows this Excel Text formula in action: Excel TEXT function not working - reasons and solutionsCompared to other Excel functions, TEXT is very simple and painless, and you are unlikely to have any difficulties when using it in your spreadsheets. If, against all expectations, a Text formula is not working for you, in most cases it's because of an incorrect format code input in the format_text argument. Here are two most typical issues:
For example, the formula =TEXT(A2, "mm/dd/yy") that works fine for English users may return the #VALUE error in other locales. In particular, in Germany, you'd need to use the following format codes: "t" instead of "d" and "j" instead of "y" because "day" in German is "tag" and year is "jahr"; "m"(month) is fine because in German it also begins with "m" (monat). So, in German Excel, the above formula will read as follows: =TEXT(A2; "mm/tt/jj"). In France, you'd use the "mm/jj/aa" format code because "day" is "jour", "month" is "mois", and "year" is "an". Also, please pay attention that in European countries, the List Separator is usually set to semicolon, not comma, and therefore ";" should be used to separate the formula's arguments. This is how you use TEXT in Excel. If someone wants to have a closer look at the formulas discussed in this tutorial, you are welcome to download the Sample Excel TEXT function worksheet. Other Excel Text functionsApart from TEXT, there are a handful of other functions to work with text values in Excel. Some of them are designed to convert text into numbers and the other way round, while others are used for manipulating text strings themselves. Below you will find formula examples of both types. |