Excel might be the obvious application for all sorts of calculations, but Word also has a calculation feature based on Field Codes that can perform simple calculations, use some functions and also format the result.
Building calculations in Word documents
Excel isn’t the only Office application that can perform calculations. Of course, you can embed an Excel object in Word, Outlook or PowerPoint but it’s important to note that embedding part of an Excel workbook in another application, whether the embedded object is created from scratch or by copying part of an existing workbook, can make the entire workbook contents available through that application. As an alternative, here we are going to look at performing calculations in Word using a Word Formula field.Generally, Word fields can be used to automate a document in some way, such as including the current date and time or entering mail merge fields that retrieve specific information from another document or file.
Just to demonstrate how a Word Formula field works, we can go to the Insert Ribbon tab, Text group, Quick Parts dropdown and choose Field… This will display a list of all the fields available in Word, with the ability to limit the list displayed to fields in certain categories by selecting from the Categories: dropdown:
We can just click on the Formula… button to create a formula field. You will be prompted to enter the formula and also to set a Number format. The Number format should be familiar if you have ever created a custom Excel number format. The # characters are place holders that allow you to specify the thousand separator character as a comma. You can choose a format from the Number format: dropdown. The format codes can also be edited, or created from scratch:
£ 6.00
It’s important to note that, unlike Excel formulas, Word formulas do not update automatically. You need to select the field, or a range of text that includes the field, and press the F9 key, or right-click and choose Update Field, to recalculate. By default, Word displays the Formula field result rather than the Field Code itself. To see the Field Code, you can right-click on the field result and choose Toggle Field Codes or you can use the Alt+F9 keyboard shortcut to switch Word from displaying field results to the field codes throughout the document.
The code for our simple formula should be:
{=2*3 \# "£#,##0.00;(£#,##0.00)"}
As you can see, the code starts with the calculation and then includes \# followed by our format code in speech marks to set the format.
So far, we haven’t achieved anything particularly useful but, if we insert a small table in Word and enter some numbers, we can create a Formula field code to add those numbers:
Functions in fields
As we have seen above, it is possible to use some functions as part of a Word formula field, although the list of available functions is very limited compared to Excel. Clicking on the Paste Function dropdown in the Formula dialog box will show the functions that can be used. Most of the available functions are aggregate functions such as SUM(), MIN() and MAX() or logical functions such as AND(), IF() and OR() but usefully the ROUND() functions is also included.Again, as we can see from our example, Word can refer to cells by position such as ABOVE and LEFT. When using these operators, the formula will take into account the range of cells up to the end of the table or up to a cell containing an invalid value:
200 |
Sales |
600 |
600.00 |
Referencing other values
Within a table, cell referencing can also be used such as =A3:
200 | |
Sales | 600 |
600 | |
600.00 |
Conclusion
You can explore several other Word techniques, and a great deal more, in the ICAEW archiveArchive and Knowledge Base
This archive of Excel Community content from the ION platform will allow you to read the content of the articles but the functionality on the pages is limited. The ION search box, tags and navigation buttons on the archived pages will not work. Pages will load more slowly than a live website. You may be able to follow links to other articles but if this does not work, please return to the archive search. You can also search our Knowledge Base for access to all articles, new and archived, organised by topic.