Professional Documents
Culture Documents
techniques for
accountants
While great care has been taken in the preparation of this material, the author and the publishers assume no
responsibility for errors or omissions, or for the uses made of the material contained herein or the decisions
based on such use. No warranties are made, express or implied, with regard to the contents of this work, its
merchantability, or fitness for a particular purpose. The author shall not be liable for direct, indirect, special,
incidental, or consequential damage arising out of the use or inability to use the contents of this publication.
Trademark acknowledgements
Windows, PowerPoint and Excel are registered trademarks of Microsoft inc.
Screen shots reprinted by permission from Microsoft Corporation.
1.8.2.2 Function................................................................................................................................................................................................18
1.8.2.3 Text and numbers.................................................................................................................................................................................18
Animations – click on the screen shots outlined in green to see an animation of the
feature. Left mouse clicks are highlighted in red and right mouse clicks in blue.
Office 2007 instructions are shown in orange text
WMV
Gif
Give this table the name ‘Categories’ by selecting G1 to H7 and choosing Insert, Name, Define (Formulas
ribbon, Defined Name group, Define Name) or by just typing the name into the 'Name Box' to the left of the
formula bar and pressing Enter:
Note that in Excel 2007 you can define the 'Scope' of the name by choosing 'Workbook' or the name of an
individual sheet to limit the scope to that sheet alone.
We are going to use Column D to show the category of each of our codes, so we type Category as the
heading, and click on cell D2.
You will notice that as you select each function a brief description appears towards the bottom of the Insert
Function screen. Once we have found the function that we want to use we click OK:
Insert Function then allows us to enter the various ‘arguments’ that our particular function requires:
1.1.1 Lookup_value
We want to include the category description for the nominal code in column A, so for row 2 we select the
Lookup_value text box and click on cell A2. You will see the current value in A2 appears to the right of the
text box.
1.1.2 Table_array
Here we define the area of the table that we will be looking up our categories from. We defined the name
‘Categories’ for this table of data, so we can just type in that name, again you will see that the contents of the
Categories range appear to the right.
1.1.4 Range_lookup
This is an optional argument and can be recognised as such because, unlike the other argument
descriptions, it is not shown in bold. If we leave it empty, or enter a value of ‘True’ the lookup will find the
match equal to or greater than the value being looked up, but less than the next item in the table – i.e. 270
will use 200 from the lookup table because 270 is greater than 200 and less than 300. The lookup table
needs to be sorted or entered in ascending order for the function to work correctly. If we set this argument to
‘False’ the function will look for an exact match and return #N/A if it can’t find it.
We want the nearest match so we leave this argument blank.
That’s all the arguments and you can see the value ‘Sales’ displayed to the bottom of the Insert Function
screen so that we know the function is producing the anticipated answer. We press the OK button to enter
the formula into cell D2.
Again we can double click the fill handle at the bottom right hand corner of D2 to copy the formula down to
the end of our table:
As you can see, each of the codes now has a category added to it – we could use this in a Pivot Table for
example to group the codes and values, or in conjunction with the SUMIF() function to create individual
summary totals of each category.
First we will enter the heading ‘Total’ in cell I1, and then select cell I2:
We then choose Tools, Wizard (Formulas ribbon, Solutions group, Conditional Sum) and, if we installed our
Add-In correctly, we should find we have the option ‘Conditional Sum Wizard’
In the first step we define the range of cells to be used to calculate the totals, in our case cells A1 to B41 –
note that we need to include the column headings. Now on to step 2:
1.2.2 Step 2
Now the complicated bit! First of all we have to decide which column to sum – as you can see the column
heading are used here, and we obviously wish to use the Amount column.
We then have to define the range of codes for which we want to calculate the sum. We are entering the
formula in cell I2, which is the Sales cell in our categories table, so we need to define the range of codes that
make up sales. In our case this is codes 0 to 99. So we enter our first condition as Code >= (greater than or
equal to) 0. We then click the Add Condition button to add this condition:
As you can see, it appears in the conditions box:
1.2.3 Step 3
On this screen we choose whether to just enter our formula in a cell, or also to enter the conditional values. It
is one of the important concepts of spreadsheet design that you shouldn’t mix data and logic in a cell, so we
will copy the conditional values as well, and then our formula will contain references to the cells, rather than
© The Knowledge Base www.tkb.co.uk Page 7
the values themselves. This will also make it easier to copy the formula to the other rows. So we choose
‘Copy the formula and conditional values’ and click the Next button:
1.2.4 Step 4
We are going to use the existing categories table, which already holds the code ranges we need to use, so
the lower limit will go to G2 as above, Because there is already a value in G2 we will be asked to confirm that
we wish to overwrite it. Hopefully we are overwriting 0 with 0 so we will click the ‘Yes’ button.
1.2.5 Step 5
Now we enter the cell to contain the upper limit, again this is already part of our table in cell G3, and we
should be overwriting 100 with 100, so we can click yes again:
Finally we enter the formula itself in cell I2, and click Finish:
Once more we can double click the fill handle to copy the formula to the end of the table:
1.3 OFFSET()
OFFSET() is used to return the contents of a cell a given number of rows and/or columns from another
designated cell. In the example below OFFSET() has been used to set the contents of the summary in
column B to the figures for a particular month.
Here we have a small set of values analysed by department. In cell E2 we have used the SUMIF() function to
total the values for department A. SUMIF() has three arguments:
• Range: the range of cells that we are going to compare against the criteria. In our case we want to
use the cells containing the department references – $A$2:$A$11. Because we want to copy the
formula to other cells, we have made the references in Range absolute – note that it would make the
formula easier to enter and to understand if we were to define names for the ranges A2:A11 and
B2:B11 and use those names in the formula;
• Criteria: the value or expression to be compared with each cell value in Range. We have pointed our
criteria to cell D2, so whichever value we enter in D2 will be used in the comparison – as you can
see this is currently 'A';
• Sum_Range: the range of cells to sum. The Sum_Range must correspond in shape to Range – so
that where the criteria is matched by a cell in Range, SUMIF() will include the cell value on the same
row in the Sum_Range area. If you don't specify a Sum_Range then the cells in Range will be
summed – obviously not what we want to do in this case. Again we have used absolute references
to $B$2:$B$11.
In our example we have copied our SUMIF() formula down to the next two cells so that we can enter other
department criteria in D3 and D4 and produce the totals for those departments.
If you examine the text to the right of the Range and Sum_Range text boxes you will notice that it contains
the contents of the specified range of cells, separated by semi-colons and surrounded by curly brackets or
braces. These braces are significant as they are used whenever Excel needs to work with an array of several
different cells or values.
1.6 Array
So, our SUMIF() function actually works with arrays of cells in the Range and Sum_Range arguments, but
mercifully protects us from needing to worry about the complexities of working with arrays. Let's see if we
can achieve the same result as using SUMIF() but by using an array formula rather than a function. This is
the suggested formula:
=SUM($B$2:$B$11*($A$2:$A$11=D2))
Let's look at our formula in more detail. The important bit is:
$B$2:$B$11*($A$2:$A$11=D2)
As part of an array formula, this will look at each of cells B2 to B11 in turn and multiply the value by whether
the corresponding cell in A2 to A11 is equal to whatever department criteria we enter in D2. If there is a
match the value will be multiplied by 1, if there is no match it will be multiplied by zero and therefore, of
course, not included. Note that the ($A$2:$A$11=D2) bit is surrounded by brackets. In order to total the
range of matching cells we need to put the whole of this formula within a SUM() function and save it as an
array formula as described above.
This simple, and probably fairly useless, example can demonstrate a few important features of array
formulae. Firstly, when we referred to an array within a formula we had to type in the curly brackets {}, but
the curly brackets at the start and end of an array formula are not typed in, but created automatically, when
you press Ctrl+Shift+Return. Secondly, if you edit an array formula and then save it by pressing Return
rather then Ctrl+Shift+Return, the formula will revert to an ordinary formula, without the beginning and ending
curly brackets, and it will no longer operate as an array formula. Thirdly, if you try and edit just one of the
cells, Excel will tell you that you can't change one part of an array:
We can create a two dimensional array by combining the commas and semi-colons:
1.7.3 So what?
So, all very interesting, but how can arrays be used in practice? Let's consider the following example of two
sets of figures that we need to compare:
More elegantly, we could use an array formula to compare the six values, and sum the number that aren't
equal, in a single cell. To do this, we replace the individual comparison in the IF() statement with the vertical
arrays, so:
=IF(A1=B1,0,1)
Becomes:
=IF(A1:A6=B1:B6,0,1)
We need to sum the resulting values:
=SUM(IF(A1:A6=B1:B6,0,1))
and then use Ctrl+Shift+Return to save it as an array formula:
The effect of this array formula is to compare each item in the first array with its corresponding item from the
second array – if they are equal the IF() statement returns 0, if they are not equal it returns 1. The result of
the six individual calculations is then totalled by the SUM() function to give us our total of 2 differences.
Here we are contrasting the use of LEN() and AND() in array formulae. In an array, LEN() which returns the
length of a text string, creates an array with an entry for each cell in the source range. However, AND()
returns just a single value based on an overall evaluation of each cell in the range. Here we see both entered
in all four cells. LEN() returns the values for each cell in turn, whilst AND() returns the overall FALSE
whichever cell it is entered into.
We can make it a bit easier to understand by naming our areas – A2:A11 as department and B2:B11 as
value. Our array formula now becomes:
{=SUM(Value*(Department=D2))}
Whilst this works, it was more straightforward just to use the SUMIF() function:
=SUMIF(Department,D2,Value)
So far, so good for SUMIF(), but as we have seen, if we make our example a bit more complex then SUMIF()
won't be able to cope. Here we have added an 'Office' category to our table of data:
If we now need to sum the values based on a combination of department and office, then we can't use
SUMIF() which can only cope with a single criteria. We can extend our array formula by adding a second
condition – once again we have given names to the different ranges:
{=SUM(Value*(Department=E2)*(Office=F2))}
1.7.6 SUMPRODUCT()
Although we can't use SUMIF(), there is another of the SUM() family that will work – SUMPRODUCT(). This
function multiplies its arguments together and sums the result. The arguments can be arrays, as long as they
all have the same dimensions, which is why we can use this function in this case:
=SUMPRODUCT(Value*(Department=E2)*(Office=F2))
You may be wondering why we couldn't enter the three elements as different arguments rather than
multiplying them together manually since SUMPRODUCT() is meant to do the multiplication for us.
SUMPRODUCT(), like the other SUM() functions, doesn't 'coerce' non-numeric values to allow them to be
evaluated as numbers, so our statements are treated as TRUE and FALSE rather than 1 and 0. We could
rewrite the SUMPRODUCT() function with separate arguments by coercing the FALSES and TRUES by
adding 0 or multiplying by 1:
We have combined the two coercion methods in the following example:
=SUMPRODUCT(Value,(Department=E2)+0,(Office=F2)*1)
1.7.7 SUMIFS()
Excel 2007 has introduced a new member of the SUM() family – SUMIFS(). This works in the same way as
SUMIF() but allows the entry of multiple criteria as a series of pairs of ranges and corresponding criteria:
© The Knowledge Base www.tkb.co.uk Page 17
=SUMIFS(Value,Department,E2,Office,F2)
Of course, to use SUMIFS() not only do you need to be using Excel 2007, but so does anyone else that you
might send your spreadsheet to.
In our example we have typed three items of text in columns A, B and C. In cell D1 we have entered the
following formula to combine all three into a single cell:
1.8.2.2 Function
Alternatively, there is an Excel function that concatenates text in this way. Unsurprisingly it is the
‘Concatenate’ function.
In the following screen shot we have used ‘Insert Function’ to enter the required details. Note that in order to
include spaces between the items of text, we have included “ “ between each pair of cells. Using the Insert
Function screen, you just need to enter a space in the appropriate text box – Excel will add the speech
marks for you:
Note that you can also use named ranges. So if we name cell B3 as ‘profit’ we could write the formula as:
As you can see there are lots of text functions, we will look at a few in detail, but if you want to explore all of
them, just scroll through the list using the down arrow key. As you select each function in turn you will see a
brief description of what it does towards the bottom of the screen. For more details, click on the ‘Help on this
function’ link:
First of all we will use the Left function to list the first two characters in the company column. We can either
use Insert, Function or just type the function in directly if we know the required syntax:
=LEFT(A7,2)
Now let’s use Right in a similar way to sort out the four characters from the end of the code:
=RIGHT(A7,4)
If we now copy the three formulae down to the end of our list, we can see how our text string has been split
into the three different sections:
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:
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))
1.8.3.4 Value
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 the Amount column we would get zero:
We need to convert the text ‘amounts’ into proper numbers. To do this we use the function Value. We will
create a new column called ‘Amount2’ and enter a 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:
As you can see, the text values are now treated as numbers and Sum works correctly.
=TRIM(A19)
and then in column C we have used Clean on the result to remove the carriage return:
=CLEAN(B19)
© The Knowledge Base www.tkb.co.uk Page 23
Note that the Trim function leaves a single space between High and Street, but that the Clean function
removes the carriage return entirely.
1.9 Rounding
1.9.1 Rounding
In this example of the use of the ‘Round’ function, we will use ‘Round’ to help with the issue of profit share
allocation..
Here is the typical problem, £100 divided three ways, with figures formatted to show no decimal places.
Normal £
Share 1 1/3 33
Share 2 1/3 33
Share 3 1/3 33
100
Here, the shares are calculated simply by multiplying the total by the share:
=$C$2*B3
Using 'Round' £
Share 1 1/3 33
Share 2 1/3 33
Share 3 1/3 34
100
=ROUND($D$2*B3,0)
The last share is simply the total less the other shares:
=D2-SUM(D3:D4)
This number can be negative. = Round(A1,-3) will round the figure in cell A1 to thousands. Remember to set
the custom number format to something like:
#,###,_);[Red](#,###,);-??
Application.Volatile
End Function
To use the function enter =ValCond(A5,”loss”,”profit”) in a cell in the spreadsheet - the text profit or loss
should be returned depending on the value in cell A5. The 'Application.Volatile' line ensures that the function
will be recalculated automatically when the underlying data is changed.
You will find that VALCOND() is also included in the 'User-defined' section of the Insert Function screen.
The first screen we see let’s us choose the type of data file we want to connect to. The options you see will
depend on the version of Excel that you are using, your original set-up choices, and any data sources you, or
software installations, have installed. We want to connect to a text file, so we choose the Text Files option.
Note that if we had already created a query to extract the information we required we could access this by
clicking the Queries tab. In later versions of Excel there is also a tab for OLAP Cubes but we will keep the
tutorial reasonably simple by sticking with our Text files data source on the Databases tab, and clicking the
OK button. This will launch the Query Wizard.
You can see that our accounts files have been found successfully – we will use accounts.csv.
So, assuming we have found our files, we can now choose our columns of data. In fact in our case we need
both the columns in accounts.csv, so we could just click on ‘accounts.csv’ and press the > button to include
both the columns in our query. If we had wanted to choose particular columns, then we would click the plus
sign to the left of accounts.csv to display the columns, and then select each one you want in turn and press
the > button.
Here is the screen with both columns included. We have also selected the ‘Amount’ column and pressed the
‘Preview Now’ button to enable us to preview the data in the column:
Now we press the next button to move onto the next step of the wizard:
On this screen we could set up a series of criteria to limit the data we link to. For example if our file included
profit and loss and balance sheet codes, we could restrict the lines we use to those with profit and loss
account codes in them.
Here is an example, but in our case there is no need to set a filter as we have only included the profit and
loss codes in the file:
We can choose to sort the data including sorts within sorts. We will sort by code:
On the last stage of the wizard we can choose to send our data directly to our Excel spreadsheet, look at the
data in Microsoft Query, and from Excel 2000 onwards, Create an OLAP cube. In addition we could save the
query to make it easier to retrieve the same data on a future occasion.
We will save the query as Accounts:
As our data is very simple, we will also just choose to Return Data to Microsoft Excel, so we leave this option
selected and press Finish:
We are asked where to put our data – we will choose to put it into the Existing worksheet in cell A1:
Note that the Code is being treated as a number. An External Data toolbar may automatically be displayed.
You can click the 'Properties' button on this toolbar, or right click in the data area and choose 'Data Range
Properties'.
We will change the Name to Accounts. This will make it easier to refer to the table of data in future formulae.
We won’t look at all the other options in detail, but will pick out some important ones:
To demonstrate the fill down formulas option, and show how to refresh our data, we are going to add a
column to the right of the External data range, and add a row to our data file.
Firstly we will type in ‘Department’ in cell C1. We will then assume that the rightmost digit of the code defines
the Department. So in C2 we will enter =RIGHT(A2). This will return the rightmost character in cell A2 – in
this case 0:
From the object menu we will choose Open With, and choose the Notepad Option:
but if you look at the bottom of the data table, you should find that there are now 41 rows, and your column C
formula has been copied down to row 41:
We paste the required web address into the ‘Address’ text box, and click ‘Go’. The web page is displayed in
the dialog box, and each available table of information is marked. We click on the data that we want.
The selected data will be highlighted and ‘ticked’ with a green tick. We click on the Import button, and Excel
prompts us as to where we want to enter the data, we choose A1:
When we click the OK button our data is returned from the Internet to our spreadsheet:
As you can see, the Data Range Properties include a section for ‘Refresh control’. You can choose to refresh
the data every so many minutes, and to ‘Refresh data on file open’ – this is the option that we have chosen.
Whenever the spreadsheet file is opened, it will retrieve the up-to-date information from the Internet. As
always there is a potential security issue here, and you may see the following message when such a
spreadsheet is opened:
Obviously, depending on your knowledge of the spreadsheet in question you would choose whether to
‘enable’ Excel to retrieve the information from the Internet.
2.3.3 Warning
Whilst this technique can be very useful, you do have to bear in mind that, if you are linking to an external
web page, you will be dependent on the design of the page remaining constant. If the location of your table
of data changes or is removed altogether, you will have to redo your link.
We want to insert the value from our Excel spreadsheet between the ‘to’ and the full stop.
First we go to our Excel sheet, click on cell B2 and choose Insert, Name, Define (Formulas, Defined Names
group, Define Name) Type in ‘EastSales’ and Add this to our list of names or just type the name into the
'Name Box' to the left of the formula bar and press Enter:
Note that in Excel 2007 you can define the 'Scope' of the name by choosing 'Workbook' or the name of an
individual sheet to limit the scope to that sheet alone.
It is always advisable to link to a named cell rather than using the cell reference, as the link should still pick
up the correct cell if changes to the spreadsheet move the cell’s absolute position.
We click on OK, right click the cell and choose Copy. Now we go back to the Word document, position the
cursor in front of the full stop and choose Edit, Paste Special. We select Paste Link and Unformatted Text:
Again we can change the figure in Excel, and see the change in our Word document. Notice how we have
changed the font size and typeface in Word, updated our figure in Excel to 120, and, because we chose
‘Unformatted Text’ in the Paste Special screen the new figure is included in the chosen font:
But this screen also explains why we can edit locked cells: locking doesn't take effect until we protect our
worksheet. Consequently, the first stage of setting up protection is to unlock the data cells. It's also a good
idea to change the background colour of the data cells to help users understand what they can change and
what is locked.
3.1.2 But…
We used to think that was it. Setting up protection in this way certainly prevents many of the problems that
users can inflict on your spreadsheet, however, as became apparent recently, not all. How do you stop users
cutting and pasting between unlocked data cells? The effect of this is to potentially mess up the references
to the data cells affected even in the protected cells. Of course it would be possible to write VB code to
prevent this, or to use form fields or some other method of data entry, but is there a simpler way? As we
have seen, in Excel XP and later, the protection capabilities have been substantially enhanced and allow
choice as to what a user can and cannot do. In addition, there is the ability to 'Allow users to edit ranges'.
To allow users to edit certain locked cells, click on the 'New' button. This lets you enter a title for each
range/permissions set, and define the cells that it refers to. Here we have entered a title of 'DataRange' and
selected cells A1 and C1.
We should now find that we can click in any of the cells in the block, and the dropdown list will include the
items from the options section at the top of that column:
First of all, we'll look at the data validation settings for cells K11 and K12.
In K11 we want to list our category headings from cells M4 to O4. In order to keep the structure as flexible as
possible, we will set up some range names so that we can add additional information without needing to
change the formulae used in our data validation settings. We will set up three names. M4 to O4 will be
named 'Categories', L5 to L8 will be 'Titles' and finally M4 to O8 will be 'Options'.
So far it's all been relatively straightforward, but now we need to construct a rather more complicated set of
formulae to ensure that our 'Titles' range displays the set of options that correspond to the 'Category' that we
choose in K11.
We will need to use the 'HLOOKUP' function to lookup the individual items in the 'Options' area by comparing
the value in K11 to the value in the top row of the 'Options' range. So if we select 'Films' in the dropdown list,
we want our function to find the column headed 'Films' and show the value from each row in turn. We also
want to construct the function arguments so that we can copy it down from L5 to L8. To do this, we will need
to make the 'Row_index_num' argument include a number that is 'relative' to the position of the formula cell.
Let's look at the formula in the Insert Function screen:
3.2.5.2 Table_array
Options
A straightforward reference to the 'Options' range – in this case no "=" is necessary.
3.2.5.3 Row_index_num
ROW(L5)-3
This is the complicated bit. The 'Row_index_num field needs a number that indicates how many rows down
the range we need to look to return our value. 1 would return the top row containing the category name. For
cell L5 we need the value 2, which corresponds to the same row as L5. If we just entered the number 2, then
we would have to change this to 3,4 and 5 for the other cells in the range. To save having to do this, we will
instead embed another function – the 'ROW' function.
'ROW' returns the row number of the cell used as the argument. So ROW(L5) will return 5. 5-3=2 which is
the answer we need. Of course, because the reference to L5 is relative, as we copy the formula down the
column, the argument will return the reference to the correct row each time. Here is an example of our
charades spreadsheet in action:
We are adding the data validation to cell A1, so we will set the formula as:
=LEN(A1)=4
As you can see, this formula must return a True or False. If True the value entered will be accepted, if False
the Error Alert will be triggered.
3.3.3.2 Letters
Letters are not quite so easy to deal with. The ISTEXT() function looks quite tempting and will successfully
identify a whole cell as containing text rather than a number, but will not work with parts of a string. Using
LEFT(), RIGHT() or MID() returns text, even if the characters are numbers. VALUE() has to be used to
convert number characters to 'actual' numbers, but if we use VALUE() on a letter character we get an error
message which ISTEXT() reports as false.
One possible answer is simply to reverse the effect of ISNUMBER() by using it with the logical function:
NOT():
=NOT(ISNUMBER(VALUE((LEFT(A1,1)))))
Although this formula would successfully reject numbers, it would accept any characters apart from numbers
– such as brackets or other symbols.
It is possible to set up a very specific data validation formula using Excel's ability to convert a character to a
code number – the CODE() function. This number could then be compared with the required range of codes.
For example, A is ASCII character 65, and Z is 90. To find out the ASCII code of a character, you can use
the CODE() function to return the value of the first character in a cell:
You could use the following formula to check whether the entered value is an uppercase letter:
=AND(CODE(LEFT(A1,1))>=65,CODE(LEFT(A1,1))<=90)
This formula uses AND() to make sure that several separate criteria all have to be met.
The problem with this formula is that it gets prohibitively long with more than two characters. The Data
Validation formula editor makes it very difficult to work with formulae of more than about 60 characters.
3.3.4 AND()
Having established the three criteria that must be met:
• The length of the value entered
• Whether the last three characters are numbers
• Whether the first character is an uppercase letter
We need to add them together within the AND() function to create the following rather complex formula:
=AND(CODE(LEFT(A1,1))>=65,CODE(LEFT(A1,1))<=90,LEN(A1)=4,ISNUMBER(VALUE((RIGHT(A1,3)))))
If you actually try and enter this in the Data Validation formula box, you will run out of room:
The real problem occurs if we make a mistake and try and use the cursor keys to go back – this is
interpreted as inserting a cell reference, so getting to any part of the formula that is not displayed can be a bit
of a struggle.
It is much easier to enter the formula in a normal Excel cell. This will also give you the ability to check the
result with all the available permutations. If the formula returns TRUE then a similar data validation formula
will accept the entry. You can then refer to that cell via the data validation formula. Better still, name the cell
something like 'InputCheck' and then refer to the name in the validation formula:
3.3.5 But
This method will only work if we are dealing with a single input cell. Because the formula refers to a particular
cell, if we try and copy the data validation to another cell it will not validate that cell, but instead look at the
contents of the original cell. If we needed to validate a group of cells, we could include the formula next to
each cell, perhaps in a hidden column. Then we would need to select the cells to be validated and set our
Custom formula to look at the first of the cells as a relative formula. This would then set each cell to look to
the cell immediately to its right for the validation formula:
In fact, we could go even further and use the column headings to hold the values that the conditions are
based upon, making it easier to change those conditions. Because of the individual cell approach, it would
also be easy to insert an additional column to extend the validation criteria. Here we have inserted a new
column E that checks that the number portion is not 000. Note the use of the ISERROR() function to return
FALSE if there is a letter in the 3 number positions, rather than a #VALUE error message:
Page 52 © The Knowledge Base www.tkb.co.uk
E2: =IF(ISERROR(VALUE(RIGHT(A2,3))),FALSE,(VALUE((RIGHT(A2,3))))>0)
The default option ‘All’ is the same as a normal paste. Here is a brief description of the other available
options:
3.4.1 Formulas
Pastes text, numbers and formulas, but not the formatting of the cells, this will remain the same as the
formatting of the destination cells. It is therefore pretty much the opposite of ‘Formats’ below:
3.4.2 Values
Converts any formulas to the results of those formulas thus ‘fixing’ the values as they were at the time the
operation was carried out. You can use this to convert an area from formulas to values by copying it and then
pasting it as ‘Values’ to the same location.
3.4.3 Formats
As mentioned for ‘Formulas’, ‘Formats’ and ‘Formulas’ are a matching pair. ‘Formats’ pastes just the formats
of the copied cells, not the contents.
3.4.4 Comments
Just pastes the comments from the selected cell, or any comments from a selected block of cells.
© The Knowledge Base www.tkb.co.uk Page 53
3.4.5 Validation
Pastes any input validation settings as set up via ‘Data’, ‘Validation’ from the selected range.
3.4.10 Operations
These allow you to select a cell, or a range of cells, and then paste it to one or more destination cells.
Depending on the operation chosen, the destination cells will be added to, subtracted from, or multiplied or
divided by, the source cells. For values, this will change the values. For formulas, it will add the appropriate
operation to the end of the formula.
You can select cells with values or cells with formulas in them to form the basis for the paste special
operation.
3.4.12 Transpose
This is a very useful one, and best explained by a demonstration. Here we have some dates:
Now we decide that we want them as column headings, rather than row headings. So we select them and
choose ‘Copy’:
Seeing a column for every single day is probably not very helpful. What we need to do is to group the dates
together into months and possibly years. Again it is the right click to the rescue. Right click on any date and
from the shortcut menu choose ‘Group and Outline’, Group (Group). You can now select one or more
grouping periods – from minutes to years! We will leave the default of ‘Months’ selected, but also click on
‘Years’:
This groups our OrderDate field by month, and adds an additional Years field:
Page 56 © The Knowledge Base www.tkb.co.uk
We will drag the Years field to the Page area, above the Sum of ExtendedPrice field. We can now choose to
look at just one year by selecting it from the drop down list. We will choose the most recent year – 1998, and
here is our PivotTable showing a summary of sales by salesperson by month.
We can click in our headings and rename the new fields and groups to make them more useful, and allocate
our other salespersons to appropriate groups:
40,000
20,000 Sales
tons
-
January February March
If we double click (Right click, Format Data Series) the ‘Sales tons’ line we will see the format data series
dialog. We can then choose the axis tab (Series Options), and select to plot the sales in tons against a
Secondary axis:
and here is the revised graph showing appropriate axes for both £’000 and tons:
30,000 8,000
25,000 Net profit
6,000
20,000 £'000
15,000 4,000
10,000 Sales
2,000 tons
5,000
0 -
January February March
This involves the use of the slightly more complicated 'Formula is' rather than 'Cell value is' variation of
conditional formatting and a bit of lateral thinking.
Change the type of condition to 'Formula is' and then enter the condition as: =A1>Top.
Because the active cell is B1 and we have entered the formula as =A1 (don't forget the equals sign), the
format will apply 'relatively' to the cell to the right of each individual figure.
We have set the format for the first condition to a Font colour or red:
We then need to set up the formats for 'amber' and for green.
The format is set in the same way as for the first condition, but with the font colour set to 'gold'.
Green is set to: =A1<=Bottom with the font colour set to green:
Now for the lights themselves. In cell B1 we can use Insert, Symbol to insert a shape from the 'WingDings'
front and then increase the font size to an appropriate value:
This can then be copied down to the rest of the cells in the range.
If we change the value in A1 to 4,000 thus changing the maximum and thereby our 'scaling' factor, the bars
should adjust dynamically as shown below:
We will change Apples to apples first. So we double click (Right click, Format Data Series) on the Apples bar
and the Format Data Series dialog box appears. This has several tabs, but it is the first, ‘Patterns’ tab that we
need (Fill option, Solid fill, Colour):
The Fill Effects dialog has four tabs, allowing you to set gradients, textures, patterns (although in most cases
patterns are probably best avoided) and the option that we are going to choose, Pictures (Picture or texture
fill):
If we look at the Format options at the bottom left hand corner of the screen we can see that we are currently
‘stretching’ the picture to fill the bar, the chart will look like this:
Maybe slightly more interesting, but not of much help in showing how many apples we have sold. If we go
back to our Fill Effects, Picture screen, we can change the format to ‘Stack and scale to:’ a certain number of
units – e.g. one apple represents £10,000 of apple sales:
If you look very carefully, you will see that even the legend keys have been changed to the pictures that we
have chosen.
Fill effects can be applied to the background of many objects, including the whole chart area, the legend and
the plot area.