Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Matching Formatting when Concatenating.

Matching Formatting when Concatenating

Written by Allen Wyatt (last updated August 31, 2023)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365


3

When using a formula to merge the contents of multiple cells into one cell, Kris is having trouble getting Excel to preserve the formatting of the original cells. For example, assume that cells A1 and B1 contain 1 and 0.33, respectively. In cell C1, he enters the following formula:

=A1 & " : " & B1

The result in cell C1 looks like this:

1:0.3333333333

The reason that the resulting C1 doesn't match what is shown in B1 (0.33) is because the value in B1 isn't really 0.33. Internally, Excel maintains values to 15 digits, so that if cell B1 contains a formula such as =1/3, internally this is maintained as 0.33333333333333. What you see in cell B1, however, depends on how the cell is formatted. In this case, the formatting probably is set to display only two digits beyond the decimal point.

There are several ways you can get the desired results in cell C1, however. One method is to simply modify your formula a bit so that the values pulled from cells A1 and B1 are formatted. For instance, the following example uses the TEXT function to do the formatting:

=TEXT(A1,"0") & " : " & TEXT(B1,"0.00")

In this case, A1 is formatted to display only whole numbers and B1 is formatted to display only two decimal places. You could also use the ROUND function to achieve a similar result:

=ROUND(A1,0) & " : " & ROUND(B1,2)

Another possible solution is to change how Excel deals with precision in the workbook. Follow these steps:

  1. Display the Excel Options dialog box. (In Excel 2007 click the Office button and then click Excel Options. In Excel 2010 or a later version, display the File tab of the ribbon and then click Options.)
  2. Click the Advanced option at the left of the dialog box.
  3. Scroll through the available options until you see the When Calculating This Workbook section. (See Figure 1.)
  4. Figure 1. The Advanced options of the Excel Option dialog box.

  5. Ensure that the Set Precision As Displayed check box is selected.
  6. Click OK.

Now, Excel uses the precision shown on the screen in all of its calculations and concatenations instead of doing calculations at the full 15-digit precision it normally maintains. While this approach may be acceptable for some users, for others it will present more problems than it solves. You will need to determine if you can live with the lower precision in order to get the output formatted the way you expect.

Still another approach is to create your own user-defined function that will return what is displayed for the target cell, rather than what is stored there. The following macro will work great in this regard:

Function FmtText(rng As Range)
    Application.Volatile
    FmtText = rng.Cells(1).Text
End Function

To use this macro, you would use a formula like this in your worksheet:

=FmtText(A1) & " : " & FmtText(B1)

Note:

If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (8886) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365. You can find a version of this tip for the older menu interface of Excel here: Matching Formatting when Concatenating.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Using Unique Document Serial Numbers

If you need to include serial numbers in your printed matter (labels, letters, documents, etc.), the best way is through ...

Discover More

Understanding the Gutter Margin

Most everyone knows that Word allows you to set top, bottom, left, and right margins for your document. There is another ...

Discover More

Turning Off Spell Checking

For some documents, you may not want spell checking turned on. There are two ways that you can turn it off, depending on ...

Discover More

Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!

More ExcelTips (ribbon)

Changing Currency Formatting for a Single Workbook

Currency is formatted differently in different corners of the world. Most formatting uses periods and commas to indicate ...

Discover More

Saving a Custom Table Style

When you format your data as a table, Excel allows you to apply a style to that table. You can even create your own table ...

Discover More

Preventing Changes to Formatting and Page Size

When you create workbooks for others to use, you might want to make sure that they can't change the formatting and paper ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 2 + 2?

2023-09-02 10:28:29

J. Woolley

After further consideration of my last comment below, with or without Application.Volatile FmtText(A1) will not update if A1 is simply reformatted; in this case, however, FmtText(A1) will update the next time any cell on the worksheet is recalculated if and only if Application.Volatile is included.


2023-09-01 15:33:43

J. Woolley

@Mike J
You are correct. Application.Volatile is unnecessary because the UDF will automatically recalculate whenever its argument changes. It should be noted that the argument must refer to a range of one or more cells like A1 or A1:D4 but only the first cell (A1) applies. If the argument is a formula like A1+B1, the result is a #VALUE! error. However, a formula that returns a range like OFFSET(B1,0,-1) is okay.


2023-08-31 05:34:27

Mike J

Why does the UDF require Application.Volatile? It seems an unnecessary overhead.


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.