Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, and 2013. 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

by Allen Wyatt
(last updated June 28, 2014)

9

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 and Excel 2013 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)

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (8886) applies to Microsoft Excel 2007, 2010, and 2013. 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

Removing All File Properties

Want to get rid of any properties you've created for a document? You can do so by using the short macro described in this ...

Discover More

Trimming Spaces from Strings

Need to get rid of extraneous spaces before or after the text in a string? VBA provides three different functions you can use ...

Discover More

Speeding Up Mail Merges

The Mail Merge tool in Word is a great way to create new, customized documents. If you are doing a lot of merging, you may ...

Discover More

Program Successfully in Excel! John Walkenbach's name is synonymous with excellence in deciphering complex technical topics. With this comprehensive guide, "Mr. Spreadsheet" shows how to maximize your Excel experience using professional spreadsheet application development tips from his own personal bookshelf. Check out Excel 2013 Power Programming with VBA today!

More ExcelTips (ribbon)

Applying Table Formats

Want to format your data tables in a hurry? It's easy to do if you use the built-in table formatter provided in Excel.

Discover More

Losing Formatting

When you save a workbook, you expect Excel to remember the formatting you applied in the worksheets in that workbook. If ...

Discover More

Understanding Monospace Fonts

Information in a worksheet needs to be displayed using fonts. If you understand the two different types of fonts available on ...

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}] 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 four less than 9?

2014-07-02 14:55:14

Brenda

Thank you Glenn & Ashley for pointing out why my formula wasn't working. Makes sense now!


2014-07-02 11:27:53

Pete

Many thanks Ashley, that is working a treat.
Much appreciate everyone's interest and help


2014-07-01 10:41:32

Ashley

Pete, this works perfectly for me:
="Last updated on "&TEXT(B2,"MMM-DD-YYYY")

If you were relying on the number format of the date cell, that won't work because the value of the cell is still just a number. The TEXT function converts that number into a string that can then be appended to other data just like any other string.

Incidentally, Brenda, your formula should have resulted in an error because you can't perform arithmetic on strings. Since the result of the TEXT function is always a string, adding it to a number should have given you the #VALUE! error.

Hope this helped. Cheers!


2014-07-01 10:21:09

Pete

Many thanks for everyone’s contribution but unfortunately I am unable to make any of the formulas work.

I have a long list of articles that fall into various categories and the prices for each category changes at different times. In cell column C I have a list of categories with the current price date in column D.

For this illustration; cell D2 shows the date in the format 28-Jun-14. In cell M12 I want to concatenate to get the result ‘Last updated on 28-Jun-14’ the formula =”Last updated on ” & D2 obviously results in Last updated on 41818

I am working around this by using two cells M12 ‘Last updated on’ and M13 (formatted for date) and copying the date entry at D2. This works of course but it would make life so much easier if I could get the result in just one cell

Brenda appears to be looking for the same solution


2014-06-30 13:28:07

Glenn Case

Brenda:

Try =TEXT(C2+B2,"mmmm dd, yyyy").

Your formula was adding the number to the text result of the formula, which was interpreted as a date, and then the default date format was applied to the result. The formula above doees the addition, and then formats it as text.


2014-06-30 13:06:35

Brenda

Why is the formatting lost when I use this formula (B2 has a whole number in it & C2 has a date in it)? =SUM(B2+TEXT(C2,"MMMM dd, yyyy"))

Thanks,


2014-06-30 09:28:57

Don

To add to Wim's comment, and you probably know this, the formula for the format you want is TEXT(B1,"mmmm dd yyyy") or TEXT(B1,"mmmm d yyyy"). The first will zero fill tne day, "09", and the second leaves out the "0".

You can also add the comma between the day and year, TEXT(B1,"mmmm d, yyyy").


2014-06-30 03:18:11

Wim Torfs

Use this formula
TEXT(B1;"d-mm-yy")


2014-06-28 07:37:20

Pete

Hey - thanks a lot for this tip, I've asked about this very problem before but not received a reply.
However, what would the formula be if cell B1 held a date? I have need to include a date as part of merged cells but can only get the Excel date number i.e. June 28 2014 in cell B1 gives me 41818 in the merged cell (C1 in the tip)


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.