Sub topic 15
Formatting values inside text with TEXT
This chapter assumes you can write basic formulas, join text with &, and apply number and date formats through Format Cells. You should also know that a format changes how a value looks, not what is stored. Here you will use the TEXT function to apply a format inside a formula. You will also learn what that costs you.
Why concatenation needs TEXT
When you join a number to a string with &, Excel uses the stored value. It does not use the cell's displayed format. Suppose A1 holds 1234.5 and is formatted as #,##0.00, so it displays as 1,234.50. The next formula still produces a label with the raw number:
="Total: "&A1The result is Total: 1234.5. Dates are worse. A date cell holds a serial number, so the same pattern gives a label such as Due 45292. TEXT solves this by converting a value to text using a format code that you supply.
Syntax
=TEXT(value, format_text)valueis a number, a date or time serial, or a reference or formula that returns one.format_textis a format code written as a text string, so it must be in double quotes. It uses the same codes as a custom format in Format Cells.
The function returns text. It does not return a number with a format attached.
flowchart LRThe diagram below shows the data flow.
Common patterns
Most uses are labels that combine fixed text with a formatted value:
="Total: "&TEXT(A1,"#,##0.00")This gives Total: 1,234.50. A date label works the same way:
="Due "&TEXT(B1,"dddd, mmmm d, yyyy")If B1 holds the serial 45292, the result is Due Monday, January 1, 2024.
The table shows more codes and what they return.
| Value | Format code | Result |
|---|---|---|
| 0.256 | `0.0%` | 25.6% |
| 42 | `00000` | 00042 |
| 1234.5 | `#,##0.00` | 1,234.50 |
| 1234567 | `0.0,,"M"` | 1.2M |
| 45292 | `mmm d, yyyy` | Jan 1, 2024 |
| 45292 | `yyyy-mm-dd` | 2024-01-01 |
| 1.2604167 | `[h]:mm` | 30:15 |
The value 1.2604167 is 30 hours and 15 minutes expressed in days. You can build it with =30.25/24. The square brackets let the hour count pass 24, as in the earlier elapsed-time format.
Quotes inside the format code
The format code is itself inside quotes, so any literal text in the code needs doubled quotes. The scaling example from earlier shows this:
=TEXT(1234567,"0.0,,""M""")The outer pair of quotes delimits the argument. Inside it, ""M"" produces the literal "M" that the format code sees. This gives 1.2M.
You can often avoid doubling quotes by moving the literal text outside the function:
=TEXT(1234567,"0.0,,")&"M"Both formulas return 1.2M. The second is easier to read and edit.
What TEXT cannot do
The result is text
A TEXT result is a string, so it behaves like one:
- It aligns left by default.
SUMignores it.- Arithmetic on it may work through implicit conversion, but only when the text looks like a plain number.
"1,234.50"may convert, while"1.2M"returns#VALUE!.
Keep the original numeric value in its own cell. Use TEXT only in the cell that produces the label or export string. Never use it for values that other formulas must calculate with.
Colors and styles are ignored
Sections and conditions work, but color codes do not display. This format is valid as a custom format:
=TEXT(A1,"#,##0.00;[Red]-#,##0.00;0.00;@")In a cell format, the negative section would show in red. Here you get the correct text, such as -1,234.50, in the cell's normal font color. If you need color, apply a custom format or conditional formatting to the cell instead.
Rounding happens in the text
TEXT(2.345,"0.00") rounds for display like any format, and the underlying number is unchanged. The output text is fixed, however. If you later convert that text back to a number, you carry the rounded value forward. Use ROUND when you need a rounded number rather than a rounded label.
Date and time code traps
mmmeans two things. Excel readsmmas minutes when it followshor precedesss, and as months otherwise.TEXT(A1,"hh:mm")gives hours and minutes.TEXT(A1,"yyyy-mm")gives year and month.- Case does not matter for most codes.
YYYYandyyyybehave the same. The exceptions aremversusM, which are not distinguished in Excel, andAM/PM. - Text dates fail.
TEXT("2026-11-27","dddd")may return the string unchanged, because the first argument is text rather than a serial. Convert it first:
=TEXT(DATEVALUE("2026-11-27"),"dddd")The result is Friday.
- Timestamps carry a fraction. A value such as 45292.75 includes a time.
TEXT(A1,"yyyy-mm-dd")drops the time from the label but does not change the cell.
Language and locale dependence
The codes in format_text are interpreted using the language and regional settings of the Excel installation that evaluates the formula. This has two effects.
- Date letters differ by language. In English, years are
y. A German installation expectsJJJJandTT.MM.JJJJ, and a French one expectsaaaa. A workbook that usesTEXT(A1,"yyyy")can returnyyyyas literal text when opened on a German machine. - Separators follow regional settings. The characters
,and.in a code mean thousands and decimal separators in English-language setups. Other locales may swap them.
The practical advice for shared workbooks is to avoid locale-specific date codes where you can. For example, build ISO dates from YEAR, MONTH, and DAY with TEXT(x,"00") for padding, or format the cell itself, because cell formats are stored in a locale-independent way and translate automatically.
Choosing between TEXT and cell formatting
| Need | Better choice |
|---|---|
| Number stays usable in calculations | Cell format |
| Number or date embedded in a sentence or label | `TEXT` |
| Fixed-width ID such as 00042 for export | `TEXT` or a text-formatted cell |
| Red negatives or color rules | Cell format or conditional formatting |
| Workbook opened in several languages | Cell format |
Troubleshooting checklist
- If the result shows the raw number, check that the format is in quotes and spelled correctly.
- If the result shows letters like
yyyy, a locale mismatch or a typo is likely. - If a later formula returns
#VALUE!, it is probably reading aTEXTresult. Point it at the original value instead. - If a date label shows the wrong month or minutes, check how you used
mm.
Exercise
Cell A1 holds the serial 45292 (1 January 2024) and B1 holds 0.256. Write one formula that returns the text "Monday 2024-01-01: 25.6%". Then say why the formula's result cannot be summed with other results of the same kind.
Show answer
Use =TEXT(A1,"dddd yyyy-mm-dd")&": "&TEXT(B1,"0.0%"). The first TEXT call returns "Monday 2024-01-01" and the second returns "25.6%". The whole result is a text string that combines a date and a percentage, so SUM ignores it and arithmetic on it returns #VALUE!. Keep B1 as the numeric source for any calculation.
Exercise
A colleague with a German-language Excel opens your workbook and the formula =TEXT(A1,"yyyy-mm-dd") shows the literal text "yyyy-01-01" instead of the year. Why, and what is a safer approach?
Show answer
The German installation reads year as J, so it does not recognize y and treats it as literal text. A safer approach is to format the cell itself with a date format, which Excel translates for each locale. If you must use TEXT, build the string from YEAR(A1), TEXT(MONTH(A1),"00"), and TEXT(DAY(A1),"00") joined with "-".