Please Note: This article is written for users of the following Microsoft Word versions: 2007 and 2010. If you are using an earlier version (Word 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Word, click here: Setting Table Values to Three Decimal Places.

Setting Table Values to Three Decimal Places

Written by Allen Wyatt (last updated July 29, 2021)
This tip applies to Word 2007 and 2010


5

Jacob has a table containing numeric values pulled from another program. One of the columns has numbers that might be 3.256000 in one cell and 23.200000 in another. He always needs to go through all of these numbers and make them only 3 digits to the right of the decimal point. Jacob wonders if there is a way to automatically step through all the values using a macro and make sure they have only three digits to the right of the decimal point.

This could certainly be done with a macro, but that might not be the best way to do it. The first potential solution is to look at how you are getting your original data. If it is possible, you might want to change the program that generates the data so that it uses only three decimal places. Or, change it so that the data ends up in an Excel worksheet that you can then embed within your Word document.

If that doesn't work, you might be able to modify the program so that it doesn't insert numeric values, but inserts fields that display the numeric values. This may sound confusing, but you can use fields to display only a specific number of digits of a value. This type of field formatting has been discussed in other WordTips.

If you cannot change the way that the original program generates the information that ends up in the table (and most of the time people can't change it), then you can use Find and Replace to limit your values to three decimal places. Follow these steps:

  1. If you want to limit your replace operation to a specific portion of your document (such as a table or a column within a table), select that portion of the document.
  2. Press Ctrl+H to display the Replace tab of the Find and Replace dialog box.
  3. If the More button is visible, click it so that you end up with an expanded dialog box.
  4. Make sure the Use Wildcards check box is selected.
  5. In the Find What box, enter the following: ([0-9].[0-9]{3})[0-9]{1,}
  6. In the Replace With box, enter the following: \1
  7. Click Replace All.

What these steps do is to look for any digit (0 through 9) followed by a decimal point and three digits. This is a "group" (one digit, decimal point, three digits) that must be immediately followed by at least one digit, and perhaps more. When this sequence is found, it is replaced by the first group (one digit, decimal point, three digits). The result is that everything beyond the third digit after the decimal point is chopped off.

This Find and Replace approach is quick and easy, and it doesn't involve the use of macros. It also doesn't round the information that is left in your document. If you need to have the values rounded to three digits instead of cut off at three digits, then you are best to go back to the "see if you can change the originating program" approach discussed at the beginning of this tip.

Note:

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

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (11467) applies to Microsoft Word 2007 and 2010. You can find a version of this tip for the older menu interface of Word here: Setting Table Values to Three Decimal Places.

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

Creating Custom Labels

There is a whole passel of labels pre-defined in Word. You are not limited to this passel, however; Word allows you to ...

Discover More

Removing a Macro from a Shortcut Key

Associate a macro with a shortcut key, and at some time you may want to break that association. (Perhaps so the shortcut ...

Discover More

Adjusting Row Height for a Number of Worksheets

Adjusting the height of a row or range of rows is relatively easy in Excel. How do you adjust the height of those same ...

Discover More

Learning Made Easy! Quickly teach yourself how to format, publish, and share your content using Word 2013. With Step by Step, you set the pace, building and practicing the skills you need, just when you need them! Check out Microsoft Word 2013 Step by Step today!

More WordTips (ribbon)

Converting Text Into a Table

Need a block of text to appear in a table? Word can do the conversion for you very quickly.

Discover More

Aligning Digits in a Table

Placing information in your table is only half the battle. You also need to figure out the best ways to format that ...

Discover More

Unwanted Vertical Lines in a Table

When you print a table that includes borders, those borders should be crisp and clear on the printout. If you get some ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, 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 seven minus 7?

2021-12-23 08:34:26

sushi

thank you so much, you saved me like days of work


2020-09-11 05:11:54

jeewan atwal

Easiest way is to copy table content to MS excel. There you can change decimal places easily. After changing copy and paste table to MS word again!


2015-12-28 08:10:52

ken Endacott

The search and replace truncates the numbers whereas you most likely want the numbers to be rounded and displayed to a precision of three decimal places. Thus 3.2567 should be displayed as 3.257 and 3.2 should be displayed as 3.200 and .12 should be displayed as 0.120. At the same time the cells should have decimal tabs so that the numbers in the column align on the decimal point.

A following macro will round numbers in a column of a table, display to the desired precision and will set a decimal tab in each cell. To use, select a column starting cell which can be in the first row or the row following the heading rows. If desired set a decimal tab in the starting cell otherwise the macro will set decimal tabs in the centre of the cells. With the cursor in the starting cell run the macro.

The cells should contain a number and no other text.

The macro will not work if the table contains vertically combined cells. It will work if the table contains horizontally combined cells in the heading rows provided that the starting cell is in the row following the heading(s).

Sub RoundNumbersInColumn()
Dim rowMax As Long
Dim rowStart As Long
Dim colNo As Long
Dim aCell As Cell
Dim aTable As Table
Dim tabPos As Single
Dim k As Long
Dim aValue As Single
Dim formatStr As String
Dim s As String
' set format to number of decimal places to round to
formatStr = "#0.000"

If Selection.Information(wdWithInTable) = False Then
MsgBox "Cursor is not within Table", Title:=""
Exit Sub
End If
Set aTable = Selection.Tables(1)
rowMax = aTable.Rows.Count
Set aCell = Selection.Cells(1)
rowStart = aCell.RowIndex
colNo = aCell.ColumnIndex
tabPos = -1
If aCell.Range.ParagraphFormat.TabStops.Count > 0 Then
If aCell.Range.ParagraphFormat.TabStops.Item(1).Alignment = wdAlignTabDecimal Then _
tabPos = aCell.Range.ParagraphFormat.TabStops.Item(1).Position
End If
' if no decimal tab in starting cell then set to middle
If tabPos = -1 Then tabPos = aCell.Width / 2

For k = rowStart To rowMax
Set aCell = aTable.Cell(Row:=k, Column:=colNo)
s = aCell.Range.Text
s = Left(s, Len(s) - 1)
If IsNumeric(s) Then
aValue = Val(s)
With aCell.Range.ParagraphFormat.TabStops
.ClearAll
.Add Position:=tabPos, Alignment:=wdAlignTabDecimal
End With
aCell.Range.Text = Format(Str(aValue), formatStr)
End If
Next k

End Sub


2015-12-27 17:25:45

Zainab Al-Mulla

thannnnks a lot for the article, it worked like a magic


2012-06-13 10:22:21

Appreciative

This tip was very helpful. I'm lucky that I found this web page in a Google search since using Microsoft Help didn't give me a solution to reduce the number of decimal points. I wanted only one to the right of the decimal point, but obviously that just takes one small change to the example given.

THANKS AGAIN!


This Site

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

Videos
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, 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.