Category Archives: Not quite so simple

Word and numbering 2 – outline numbering

In the first part of this short series we looked at simple numbered lists in Word. In this concluding part we will look at some of the important issues surrounding the use of Outline Numbering.

First of all, some information on the general uses of Word outlines. Word outlines involve allocating paragraphs to different levels. So a main heading might be level 1, the sub-heading level 2, sub-subheading level 3 and so on to level 9. Standard paragraphs of text would not have a level, but would be ‘body’ text. Once these levels are established, they can be used to quickly re-arrange a document or to automatically create a table of contents. In addition, and with particular relevance to our numbering issue, they can be used to automatically create and maintain numbering throughout an entire document.

Outline example

Continue reading

Advertisements

Excel, the LBW law, range names, form controls and logical formulae

Nearly two years ago I was running an advanced Excel course and needed to create an example of the use of Excel’s logical functions. Given that most of the people we train work in accountancy, our examples are usually based around financial data but, since it was the middle of the 2005 Ashes tour, the cricket LBW (leg before wicket) law sprang to mind. I’ve extended the example to look at the use of range names in making formulae easier to understand, and also to incorporate the use of a simple interactive form control.

Excel and the cricket lbw law

Continue reading

Excel Indirect() function – save hours

Excel’s Indirect function allows the creation of a formula by referring to the contents of a cell, rather than the cell reference itself. Of all the functions covered in our Excel courses, it is often Indirect() that attendees haven’t come across but find an immediate use for, often saving a great deal of time and effort in the process.

Indirect used to include references to the sheet named in cell A1

If you have several sheets, each with information for a single department for example, you may want to set up a summary sheet. Rather than creating separate formulae to refer to each sheet, Indirect() can allow you to create a single set of formulae all of which use a reference to a sheet name held in a cell – hopefully an example will make this clearer.

To refer to cell A2 on a sheet named ‘Cuddly Toys’ we would use a formula like this:

=’Cuddly toys’!A2

However, sometimes it would be useful to be able to change a whole series of references to, for example, a different sheet.

We could type the sheet name into a cell on our main sheet, say A1. We could then write a formula to refer to cell A2 on the sheet typed into cell A1.

If we simply type:

=A1!A2

Excel, not unreasonably, looks for a sheet named A1 and fails to find it.

However, we can use the Indirect function instead. Here is the screen from the Paste Function dialog for Indirect:

Indirect 1

& $A$1 & ‘!A2

Our Ref_text entry is a little confusing, so we have highlighted the pairs of speech marks in different colours. We have two items of text, and sandwiched in between them, an absolute reference to the contents of cell A1 – as you can see this correctly returns the contents of that cell – Cuddly toys. The ampersands are used to join the 3 elements of our Ref_Text together. The first text section simply holds a single apostrophe – this is necessary because, if our sheet name contains a space, it must be surrounded by apostrophes to be correctly identified. The second section contains an absolute reference to cell A1 – the cell where we type the name of our sheet. The third text section contains the closing apostrophe for the sheet name, together with the exclamation mark that separates sheet name from cell reference, and the cell reference itself – A2.

This works well to return the contents of cell A2 on our cuddly toys sheet, and if we were to type in ‘Boardgames’ for example, it would automatically return the contents of cell A2 on a sheet named ‘Boardgames’.

However we do have a problem left to solve. We need to refer to many cells on the price list sheets, but if we copy our Indirect cell, the reference to A2 doesn’t change, because it is just text. We can solve this by using a row/column style reference instead of A2:

Indirect 2

& $A$1 & ‘!RC

Note that we have to set the ‘A1’ argument of the function to ‘False’ to use this reference. RC will return the current row and column – so a formula in cell A2 will refer to A2 on cuddly toys, A3 to A3 and so on. If we need to refer to a different cell we would add numbers in square brackets after R and C. So R[1]C[1] would look at the cell one row down and one column right for example.

Using Excel text functions – part 2

Now let’s consider a slightly more difficult situation. In the following example we have a description and an amount in the same cell, but the two are always separated by a hyphen:

Excel text functions - search, len and value

Because neither the length of the text or the figure are necessarily consistent, we can’t use Left, Right or Mid. However, we can instead use the hyphen to work out where the description ends and the number begins. To do this we must first identify how many characters from the left there are before the hyphen.

To do this we use the ‘Search’ function. Here is the function screen for Search:

Search function

Note again that we can just type the hyphen into the ‘Find_text’ box and Excel will automatically add the speech marks. Note also that there is the option to specify the character position at which you want to start the search. This is useful if you need to locate more than one similar character – once you have found the first, you can start the next search from one character position higher. Our example is a simple one that doesn’t use the ‘Start_num’ argument and, as you can see, it returns the position of the hyphen as character 6.

=SEARCH(“-“,A13)

We can now ‘nest’ the Search function within the ‘Left’ function to retrieve the description:

=LEFT(A13,SEARCH(“-“,A13)-1)

In order to exclude the hyphen itself we have subtracted 1 from the result of search. If we copy this formula down our list we can see that it achieves the desired result:

Excel text functions - search

Now to deal with the amount. Whilst we can use Search to find the starting position, we don’t yet know how long the amount is. We can work this out using the ‘Len’ function. ‘Len’ is a very simple function with just one argument – the text string, or cell containing the text string, that we wish to find the length of:

=LEN(A13)

This tells us how long the text is in total, and we have already used Search once to find the position of the hyphen. By combining Len and Search we can calculate how many characters follow the hyphen:

=LEN(A13)-(SEARCH(“-“,A13))

In the case of “Sales-10000” Len will return 11, the hyphen is at position 6, so 11-6 = 5, the number of characters in the amount.

We can use this with the ‘Right’ function to pick out the amount:

=RIGHT(A13,LEN(A13)-(SEARCH(“-“,A13)))

Again we can copy this formula down the list:

Excel text functions - search and len

As you can see above, whilst we have indeed separated out the amount characters, Excel is still treating our text as text and if we used Sum to total column C we would get zero:

We need to convert the text ‘amounts’ into proper numbers. To do this we use the function Value. We will use the value function to convert the three items in our list to numbers. Here is the formula for cell D13:

=VALUE(C13)

We can now copy this down our list and use Sum again to total our new column:

Excel text functions - value

As you can see, the text values are now treated as numbers and Sum works correctly.

These two functions can be used to remove unwanted characters from text. Sometimes, if you import text from other sources, you may end up with non-printing characters, such as carriage returns – Clean will remove these. Trim can be used to get rid of extraneous spaces:

In the following example we have part of an address that includes multiple spaces between ‘High’ and ‘Street’ and a carriage return character to separate the lines of the address.

In column B we have used Trim to get rid of the extra spaces:

=TRIM(A19)

and then in column C we have used Clean on the result to remove the carriage return:

=CLEAN(B19)

Excel text functions - trim and clean

Note that the Trim function leaves a single space between High and Street, but that the Clean function removes the carriage return entirely.

Automatic continued in Word

Excellent question from one of my clients working on a Word template for their letters, how could the word ‘continued…’ be included automatically on page one of each letter, but only if the letter was longer than a single page?

A more standard question is how to include space for the headers and footers of preprinted letterhead stationery on page 1 only. This can be done by ensuring that in the Layout section of File, Page Setup, the ‘Different first page’ option is selected. This allows you to set up empty headers and footers on page one of the right size to allow for the letterhead but, because of the ‘Different first page’ option, they will not appear on subsequent pages.

The ‘continued…’ question is not so straightforward. The headers and footers for the letterhead are required on page one, whether there is one page or many pages, but as we have said, the ‘continued…’ should only be included when a second page is needed. After a fair amount of thought, the following solution came to mind. Set up the ‘Different first page’ option as before, and this time, in the appropriate position of the header or footer insert a Word ‘IF’ field. The IF should check whether the number of pages in the document is greater than 1 and if so, include ‘continued…’, and if not omit the word.

The Word field should look something like this:

Word IF field code

Be very careful when entering the Word field – forgetting a space or getting the syntax wrong in any other way will probably stop it working properly.

If you are not very familiar with using Word fields, the best method of inserting an IF field is probably to use the Insert, Field option in two stages.

First use Insert, Field to insert the IF field. Don’t worry about calculating the number of pages at this stage, but instead just type in a placeholder – for example the word ‘pages’:

i.e.

IF pages > 1 “continued….” “”

The IF field compares two ‘expressions’ and then prints one item of text if the comparison is evaluated as ‘true’ or a different item of text if it is ‘false’.

In fact, in this case because we don’t need anything printed if the result is false we could omit the ‘FalseText’ altogether:

IF pages > 1 “continued….”

Word IF field

Then right click on the resulting field result, and choose Toggle Field Codes to show the underlying code. Double Click on the word ‘pages’ to select it, then go to Insert, Field again and this time use the field DocProperty, Pages:
Word pages property field

Now select the entire field, right click, and choose Toggle Field Codes again to toggle back to displaying the result of the field.

Finally, to make sure the field result is recalculated every time the document is printed, set the ‘Update field’ option in the Tool, Options, Print screen:

Update fields option

It’s your round

Rounding can often be a problem in a spreadsheet. We’ll start with some relatively simple background stuff then move on to some lesser-known aspects of rounding and displaying rounded values.

What you see isn’t what you calculate – mostly!

The first thing to grasp is that the way Excel displays the contents of a cell generally has no effect on the actual contents of that cell as used in calculations. So a value of 100.05678 will remain as 100.05678 even if the format of the cell is set to display no decimals. There is one important exception to this. There is an option in the ‘Calculations’ tab of the Tools, Options screen that forces Excel to change the contents of the cell to match the ‘precision’ of the format. So if the cell is formatted to display no decimal places, the contents will be permanently rounded to no decimal places – our 100.05678 would become 100.00000:

Before turning on ‘Precision as displayed’

Before precision as displayed

and after:

After precision as displayed

This is an option to be used with great care. It applies to the entire workbook and as soon as it is turned on potentially decreases the accuracy of any figure displayed to fewer decimal places than it actually contains.

Round function

A less drastic method of avoiding rounding errors is to use Excel’s ROUND() function. This allows you to round a number to a specific number of decimal places for use in calculations, without changing the original number. Round takes two arguments – the number to be rounded and the number of decimal places to round to. In this case we have used =ROUND(A2,0) to round to round pounds:

Rounding example

The ‘sum’ formula in cell C5 sums the rounded numbers in C2 to C4, so returns 99 rather than 100. If you need the total to be a particular figure, for example if the 100 was a profit share, then you could set the final rounded figure to be the total minus the sum of the other rounded figures. In this case we have entered a figure of 100 in cell E5, then rounded the calculation of the two shares in E2 andE3, with E4 being =E5-SUM(E2:E3)

Rounding profit shares

More fun with rounding

As well as 0 for no decimal places or a positive number for that number of decimal places, you can also enter a negative number as the decimal place argument of the Round function. For example you could enter -3 to round to thousands:

Rounding to thousands

To change the format to display numbers rounded to thousands you would use the following custom format:

#,###,

for 1,235k

#,###,k

for millions

#,###,,

for 1m

#,###,,”m”

The speech marks are necessary for the m, but not the k, because m is used in formatting to signify a month format.