MS Excel 2007 - 10 Techniques the Pros Know v7

26
10 TECHNIQUES THE PROS KNOW About Microsoft Excel 2007

description

MS Excel 2007 - 10 Techniques the Pros Know v7

Transcript of MS Excel 2007 - 10 Techniques the Pros Know v7

Page 1: MS Excel 2007 - 10 Techniques the Pros Know v7

10 TECHNIQUES

THE PROS KNOW About Microsoft Excel 2007

Page 2: MS Excel 2007 - 10 Techniques the Pros Know v7

10 Techniques the Pros Know 2

First edition published in 2011 © Copyright 2011 Train Up Now All rights reserved. No reproduction, copy or transmission of this publication may be made without express prior written permission from the author. No paragraph of this publication may be reproduced, copied or transmitted except with express prior written permission from the author or in accordance with any applicable law in the country of origin. Any person who commits any unauthorised act in relation to this publication may be liable to criminal prosecution and civil claims for damage. Although reasonable efforts have been made to ensure the accuracy of the information contained in this book, as of the date of publication, nothing herein should be construed as giving advice and no responsibility is accepted for any use or application of any information contained therein.

Page 3: MS Excel 2007 - 10 Techniques the Pros Know v7

10 Techniques the Pros Know 3

Contents Introduction ............................................................................................................................... 4

What’s in this book ................................................................................................................... 4

1. Setting the scene................................................................................................................... 5

2. VLOOKUP .............................................................................................................................. 6

Fetching data ........................................................................................................................... 6

How to use it ............................................................................................................................ 6

Putting it into action ................................................................................................................. 6

Your bonuses ........................................................................................................................ 10

The alterntives ......................................................................................................................... 11

3. TRIM and its mates .............................................................................................................. 11

Getting your data into shape .................................................................................................. 11

How to use TRIM ................................................................................................................... 12

4. LOWER (and UPPER and more!) ........................................................................................ 13

5. Error-handling ..................................................................................................................... 14

What a conditional statement does ........................................................................................ 14

What’s in an (error code) name ............................................................................................. 15

6. ISERROR for fixing things up ............................................................................................. 15

Using IFERROR – two formulae for the price of one .............................................................. 16

7. Managing input into your spreadsheet .............................................................................. 17

Drop-down lists ...................................................................................................................... 17

Making them ...................................................................................................................... 17

Restricting choices ............................................................................................................. 18

8. AutoFilters ........................................................................................................................... 19

Making them ...................................................................................................................... 19

9. Using groupings, outlines and subtotals .......................................................................... 20

10. Formatting ......................................................................................................................... 24

Cloning .................................................................................................................................. 24

Copying ................................................................................................................................. 24

Adjacent cells. .................................................................................................................... 24

Non-adjacent cells .............................................................................................................. 24

Now it’s your turn… ................................................................................................................ 26

Page 4: MS Excel 2007 - 10 Techniques the Pros Know v7

10 Techniques the Pros Know 4

Introduction Welcome! This book is designed to give you expert tips on how to handle some of the most useful Excel tools quickly and painlessly. It will show you how to simply and easily move your use of Excel to the next level. There are examples that you can try for yourself by opening up a spreadsheet on your PC and following along. You’ll find them constructive for your own spreadsheets, and also (and above all) for spreadsheets that you make to share with other people. If you’ve already used Microsoft Excel, then you’ll probably be familiar with the fundamentals – for example, entering and copying data for calculations into the cells in a spreadsheet. The power of Excel will be apparent to you, like that marvellous way that it has of automatically adjusting addresses and formulae as you extend your spreadsheet along rows and down columns. However, as you use Excel to handle larger amounts of data and calculations, the complexity increases. Basic manual adjustments rapidly become tedious, or just unreasonable. Cryptic error messages appear when you mistype a formula for a calculation, or when Excel decides it doesn’t like what you’ve entered as data. And if your spreadsheet is destined to be used by other people as well, you’ll want to figure out how you can get your colleagues to use the data choices you give them, rather than what happens to enter their heads at the time. It’s that in-between stage where you know enough to have people ask you your advice about Excel, but not yet enough to make your spreadsheet life more comfortable. Knowing what the problems are is one thing. Now it’s time to see what the answers are.

What’s in this book Like the ones that follow in this series, this book takes a problem-solving approach. What we describe below refers to problems or challenges that commonly crop up as you progress in using Excel. That’s the value of the contents below – practical problem-solving that you can use right away.

How to automatically bring in data, on demand, from different spreadsheets, with VLOOKUP

Keeping Excel happy by simple moves to format all data the same way (TRIM and UPPER)

Smart ways to handle those weird Excel errors so they make sense! (ISERROR and IFERROR)

Saving time by having Excel automatically tell you which data to enter, with DROP-DOWN LISTS

PROTECTING by locking those drop-down lists, so that colleagues using your

spreadsheet play by your rules

Coming up with answers for your manager immediately, thanks to AUTOFILTER

Cool ways to show SUBTOTALS in lists of data, and how to show/hide detail with OUTLINES

Quick and easy formatting of cells – spreading beauty with a click or two of FORMAT PAINTER

Page 5: MS Excel 2007 - 10 Techniques the Pros Know v7

10 Techniques the Pros Know 5

1. Setting the scene Imagine that you are in an office, working on the production planning of a new range of products. You need a way to organize your information and your thoughts in order to plan ahead and use sales forecasts to help manufacturing. You’ve already used Microsoft Excel to make some simple, if sizable, spreadsheets and you are aware of its extensive possibilities to make changes easily between different models of the future. These “what if” scenarios are already a big plus, especially with some excitable sales people who have started to sound out their customers (under non disclosure, of course) about demand for the new offering. They come back to the office with their eyes shining and questions like “can I take an order next quarter from this customer for 2500 pieces of the new mega-model?” Thank goodness for Excel. You have the basics down already, like setting up a spreadsheet with column and row headers, using the basic arithmetic functions and printing out the parts that interest you. Here is what an extract of the data in a basic Excel file might look like in this situation.

Clearly, we’re keeping things simple at this stage. Your Excel file might well have hundreds of products, what with different models, options or even international versions. You might also have dozens of columns of data for each product.

Figure 1 – an array of data

You’ll see that what we explain below can easily be applied to much bigger spreadsheets – and that the more data you have to handle, the more useful these functions become. At the moment, there are some challenges to take on board. Sales people have their own way of classifying products and prospects. Your colleagues in Marketing might have a similar point of view, but Accounting could see things very differently. Take a look at the Sales Category column above. There’s no particular logic in the way the sales categories are assigned. It’s a matter of sales experience or judgment that product 1 is in the A category (perhaps a fast-moving item), whereas product 5 is in the E category (for example, slower-moving, harder to sell). On the other hand, which product is Accounting’s favourite? Product 10 looks like an interesting candidate – just look at that profit margin! So how can you use what you’ve made in Excel to work with your sales and marketing colleagues on one side, and your colleagues in production on the other side, while keeping track of all the figures and categories as required? Remember, you need to make forecasts for Production that uses information from Sales about which products are going to be bought by

Page 6: MS Excel 2007 - 10 Techniques the Pros Know v7

10 Techniques the Pros Know 6

customers. Yet you don’t know beforehand which products are involved, so your solution has to be flexible and powerful enough to handle that. You want a solution where you can enter just the names of the products forecast to be sold, and have Excel automatically fill in the relevant data on the product categories and costs, instead of having to bring it in all manually.

2. VLOOKUP

Fetching data

Introducing VLOOKUP – a simple, powerful solution for the situation above. VLOOKUP

lets you easily bring data together from different spreadsheets, which is handy when you have different sources of data that you want to feed into one global view of what’s going on. Whether you’ve already met VLOOKUP or not, stay with us. Whereas other textbooks and manuals may tell you how VLOOKUP works, they often don’t tell you the different reasons it can be so useful. So read on to find out about this and more.

How to use it

Here’s an overview. You give the VLOOKUP function:

A value, like “product 1”

The location of a table of data in which to search

The column in that table where VLOOKUP is to fetch information relating to “product 1” – for our example, this might be the profit for each “product 1” that is sold.

You keep your table of searchable data separate from the part of your spreadsheet where you are making your sales and product forecasts. You might choose to keep your table of data on a separate work sheet in the same Excel file, for example. You’d update it only as and when necessary (for example, if production costs change). Now when you make your forecasts in your spreadsheet, you’ll make VLOOKUP act on whatever product name you enter in, so that it goes to the table of searchable data and brings back the relevant information for that product. Naturally, it’s very simple to also have Excel then multiply the product cost, sales revenue and profit by the number of sales forecast for that particular product. For information, the “V” in VLOOKUP stands for “vertical” – we’re working with the values in the table in a vertical column first before telling Excel to “run its finger along the line” to find the value we’re interested in. Excel also has an HLOOKUP function that works in the opposite way by first referencing a row (H for “horizontal”) and then searching down a column.

Putting it into action

Here’s how you can quickly and easily get VLOOKUP working for you. We take the simple approach first and then discuss a few options that you might also like to investigate. So open up a blank Excel spreadsheet on your PC, if you’d like to, and follow the steps below.

Page 7: MS Excel 2007 - 10 Techniques the Pros Know v7

10 Techniques the Pros Know 7

Your blank spreadsheet will normally be created with three separate worksheets that you can access by clicking on the tabs named “Sheet1”, “Sheet2” etc. at the bottom left of the page. We want to see how to keep our data in one worksheet and do our calculations using VLOOKUP in another worksheet (for better organization and data integrity).

1. Click on the tab for “Sheet2” to display that worksheet.

2. Make a table of data like the one in figure 1 above (copy it directly for this exercise). It doesn’t matter where you put the block of data on the worksheet, but for the sake of the explanations below, let’s say that the top left-hand entry is in cell A1. For a 5-columns-by-11-rows array like this, that means that the bottom right-hand entry is in cell K5. In other words, the whole array, including the column headers, is A1:K5. However, for the data we’re going to use (without the headers), it’s just A2:K5. VLOOKUP needs to know this precise address afterwards. Note that in the left-hand column (this is where VLOOKUP will go first of all to start looking for information), there are no duplicate entries. If there were, Excel wouldn’t know which one to start with and would give you an error message.

3. Have you made your table of data? OK – then let’s move back to Sheet1 of your spreadsheet (click on the tab at the bottom for Sheet1). You’ll notice we haven’t been very inventive with our product names or sheet names here. When you start using this for “real” spreadsheets, it’ll be better to think up some short but more meaningful names. This helps clarity and understanding!

4. On Sheet1, now make the following entries (see figure 2 below):

Figure 2 As you can see, we’ve inserted an extra column with some forecast numbers, and we’ve picked just some of the entries for the product names. The other cells in the array (other than the column headings) have been left empty.

5. Now it’s time to get started with VLOOKUP! Remember that we want to be able to type in new product names or at least change the existing ones, and have the entries for the information such as sales category, production cost, etc. change automatically. Select the cell that is both in the row “product 1” and in the column “Sales Category” ,like this

Page 8: MS Excel 2007 - 10 Techniques the Pros Know v7

10 Techniques the Pros Know 8

Figure 3 For our example, this cell is C2 (because the array starts with the column header “Product Name” in cell A1).

6. Next, type into this cell exactly what follows: =VLOOKUP($A2,Sheet2!$A$2:$K$5,2,FALSE) This needs a little explanation – but it’s worth it, because afterwards it’s “nice and easy”. You are in fact telling Excel to: * Take the contents of the cell A2 (“product 1” in this case) * Go over to the array of data on Sheet2 and contained in the block of cells A2:K5 and to find the entry corresponding to cell A2 (“product 1”) in the first column of that array (VLOOKUP always starts with the first column) * Locate the content of the cell in the same row but in column number 2 (that’s the “2” towards the end of the VLOOKUP formula above) * And to come back and put that content in cell C2 in Sheet1 (because that’s where you happen to typing this formula). The fourth and final element, “FALSE”, tells Excel to look for an exact match – meaning that if for some reason, “product 1” did not exist in the array Sheet2!$A$2:$K$5, then Excel would stop there and simply return an error message. You can also use the “Insert… Function” possibility for Excel and just type VLOOKUP into the search field to then click on OK. Excel then lays out the four VLOOKUP variables that we’ve just seen in a dialog box and helps you to fill them in. Excel also displays the answer from VLOOKUP as you build the function, so that you can see if your choices are giving you the right result. If you’ve typed everything in right, the entry in cell C2 in Sheet1 should now be “A”:

Figure 4

7. Now we can copy our VLOOKUP formula over to the other cells in our array in

Sheet1. You may have noticed how we used absolute addresses with the “$” signs. This is so that we can then drag select and copy the VLOOKUP formula to the other cells, without Excel automatically incrementing all the cell addresses – that would spoil things in this case. If you decide to use the “Insert… Function” possibility, take care that you also put the “$” signs in as required.

Page 9: MS Excel 2007 - 10 Techniques the Pros Know v7

10 Techniques the Pros Know 9

First, we’ll copy cell C2 over to cells D2, E2 and F2, although we’ll have to make a slight adjustment in each case. This is because even though our absolute addresses hold good, Excel won’t automatically increment the number of the column in the data array (the one on Sheet2) that it goes to in order to get the value we want. For our cell C2 in our example above, we’re going to column number 2 – that’s the “2” in the list of variables inside the brackets). But for cell D2, we want VLOOKUP to go to the third column (“Production Cost”) in the table of data in Sheet2, for cell E2 we want column number 4, and for cell F2 we want column number 5. So in cell D2, edit to make the entry as follows (change that “2” to a “3” in the formula – we’ve written it in green here just to show you where it is): =VLOOKUP($A2,Sheet2!$A$2:$K$5,3,FALSE)

Make similar changes for cell E2 (change it to a “4”) and cell F2 (change it to a “5”). You should now see this:

Figure 5

8. For the Production Cost, Revenue and Profit columns, we also want to multiply by

the number of products forecast to be sold to get the total figures in each case. No problem. We just multiply our VLOOKUP formula by the number concerned (the cell B2 in our example). A quick edit on our formula for the cell D2 (Production Cost) then gives us =$B2*VLOOKUP($A2,Sheet2!$A$2:$K$5,3,FALSE)

Multiply the formulae in cells E2 and F2 by $B2 as well. Don’t multiply cell C2 however, because it contains a letter, not another number, so trying to multiply will just get you an error message.

9. Now we can drag select and copy down each column! This should immediately give us this

Figure 6

Page 10: MS Excel 2007 - 10 Techniques the Pros Know v7

10 Techniques the Pros Know 10

10. And NOW the REAL magic begins. Up to this point, we could almost have just copied and pasted the figures from one place to another to get the same effect. But look what happens if you replace the entry “product 1” by “product 3”, for example. Change just that cell (A2 in our example on Sheet1), put in a different sales forecast (let’s say 57) and VLOOKUP automatically goes and gets the corresponding data to calculate and fill in the rest of the rows:

Figure 7

You can imagine how powerful this becomes either when you want to try out different combinations of product sales forecasts in the same table, or when you have different selections out of a hundred or more products that might need to be forecast.

Your bonuses

We already hinted at some of the extras in VLOOKUP. So here they are:

VLOOKUP can also go and fetch data which is not only in a separate worksheet, but in a separate Excel file. This can be useful for you when you are working with several sources of data. To do this, open the other file before defining your VLOOKUP formula and keep both files open. When you build your VLOOKUP formula for example using “Insert… Function”, then change windows to go to the second file to select the table of data from the second workbook. However if you plan to make a spreadsheet available to other people, it may be better to bring that data into different worksheets within the same file – separate files can all too easily get lost when other people are involved.

VLOOKUP can also look for approximate matches instead of exact ones. You might have a separate table of data for example with the first column containing production lead times and the other columns containing corresponding data like product names, profits and so on. At the end of the quarter, when you’re looking to see what you can make and ship the quickest, so that you can book the revenue, then you can have VLOOKUP get information on a product with a production lead time of “about 4 days”. For this you’ll need to do two things: firstly, you have to make sure that the lead times in the first column are in ascending order; secondly, instead of specifying “FALSE” in the VLOOKUP formula, specify “TRUE” instead (or just leave this part blank).

You can also use VLOOKUP as an “array function” (although we don’t discuss array functions here). Instead of copying the VLOOKUP formula from one column to another to then tweak it for each column, like we did above, you can drag select across columns and just do one copy and no tweaking. In that case, the

Page 11: MS Excel 2007 - 10 Techniques the Pros Know v7

10 Techniques the Pros Know 11

entry for cells D2, E2 and F2 in Sheet1 of our example could become (note the two pairs of curly brackets and the multiple column numbers in bold, green type): {=$B2*VLOOKUP($A2,Sheet2!$A$2:$K$5,{3,4,5},FALSE)}

to be copied without tweaking from D2 to E2 and F2, instead of our earlier version of =$B2*VLOOKUP($A2,Sheet2!$A$2:$K$5,3,FALSE) which we copied but then had to also tweak for cells E2 and F2.

With these different possibilities at your disposal, you can see why VLOOKUP quickly makes much more sense for larger spreadsheets than trying to run your finger along the line and find the value you want that way.

The alterntives Excel does have other functions such as MATCH and INDEX that can help you to do similar things, but VLOOKUP still scores highly in terms of convenience and ease of use. VLOOKUP also replaces the use of multiple “IF” statements. In a sense, VLOOKUP takes the value you give to it (“product 1” in our example above) and then goes to the array of data to compare: if the value given is the same as the first value in the first column of data in the table, then it uses the first line to get the information required; if the value given is the same as the second value in the first column, then it uses the second line; if it’s the same as the third one… and so on. However, even if you tried to write all this out using IF statements in Excel (which would be very tedious), you are also limited in the total number of such IF statements. With VLOOKUP, there is no such limit and your table of data can have as many rows as you like.

3. TRIM and its mates

Getting your data into shape

So far so good! With VLOOKUP, you’re happily working with sales forecasts and production planning. And making a good impression on your colleagues by showing them how easily your spreadsheet can calculate different projections of revenue, cost and profit just by slotting in different product names. As long as you are there to do the demonstration, everything works well. People from the Sales, Production and even Accounting departments start sending you their own tables of data for you to plug in to your spreadsheet. Sales wants to see what a new set of sales categories might do, Production has some new cost figures corresponding to a change in volumes of production, and Accounting wants to do some “what if” scenarios for changing cost allocations and profit figures.

Page 12: MS Excel 2007 - 10 Techniques the Pros Know v7

10 Techniques the Pros Know 12

Unfortunately, not everyone has the same idea about how such data should be presented. There’s no problem about the figures, but when it comes to product names, it’s a real zoo. Some people are entering “PRODUCT 1” (and so on) into their tables, others are writing “ Product 1 ” (with spaces after or even before the name as well) and other “creative” people are even typing in “ProDUCT 1”. The problem is that when you specify the “FALSE” condition in VLOOKUP to make sure that you get an exact match, VLOOKUP quite rightly considers that none of the variations in the paragraph above are the same as “product 1”. So it gives you an error. What are your options? You can change the “FALSE” condition to “TRUE” which means that you accept approximate matches (try it for yourself to see how much leeway this then gives you). However, this is a dangerous game in this kind of context. You’ll see things like a search on a name like “product 10” returning the data that belongs to “product 1” – hey, we said “approximate”, right? So we need another option, which is the one where we correct or “massage” the data from other departments before using it in our model. The good news is that Excel has some more simple functions to help out. One of these is TRIM. It strips out the blanks before and after a text string.

How to use TRIM

In Excel, the TRIM function takes the text you give it and hands it back to you with the leading and trailing spaces (if there are any) removed. So far example, if we entered the following into a cell: =TRIM(“ Product 1 “) then the result would be Product 1 with no spaces before or after (although the space in between is maintained). Like VLOOKUP, you wouldn’t bother with TRIM if you had to deal with the contents of one cell. But if you have hundreds or thousands of cells to deal with, then just one copy and paste to apply TRIM to whole columns of data can be just the ticket.

Here are a few examples “before and after” of how TRIM handles contents with spaces.

But we still don’t have all we need, because “Product 1” does not yet exactly match the “product 1” format that we are using.

Figure 8

Page 13: MS Excel 2007 - 10 Techniques the Pros Know v7

10 Techniques the Pros Know 13

4. LOWER (and UPPER and more!) Here’s a function in Excel that will get us what we want. It’s the LOWER function and it converts

all letters into lowercase. If we entered the following into a cell: =LOWER(“Product 1“) then the result would be product 1 Now we have the version that is exactly the same as what we have been using in our VLOOKUP example above. Running TRIM and LOWER on thousands of cells can make your spreadsheet life so much easier! Excel also has a few more functions like these. You might decide for example to standardize on product names that are all in uppercase, like BIG_PRODUCT, in which case you’d use the UPPER function to massage data and convert all the names to capital letters. You might simply

want to format certain texts in a particular way in your spreadsheet – perhaps ALL IN CAPITALS to call attention to it (so you’d use UPPER), or with the first letter of each word in capitals, such as Mary Grant or Joe Dupont (you can do this using the PROPER function).

Here are some examples using the functions above. Just for info, look at what PROPER does to the original “99proDUCT” string.

Figure 9

Page 14: MS Excel 2007 - 10 Techniques the Pros Know v7

10 Techniques the Pros Know 14

5. Error-handling What happens when matches are still not found by VLOOKUP? Try putting a product name into the forecasts table in Sheet1, and that you know isn’t in Sheet2 – for example, “Pack 13B”. This is what happens:

Talk about ugly. And baffling. While as an increasingly seasoned Excel user, ”#N/A” and the rest of the joyous band of Excel errors may no longer strike fear into your heart, put yourself in the position of your less knowledgeable colleagues – including your boss and your boss’s boss. If a match really can’t be found, it would be more user-friendly to have comprehensible message in the Excel field instead of “#N/A”. In fact, what would be good would be to have Excel act according to an “IF statement.” For example, IF the value returned is “#N/A”, THEN we’d like Excel to avoid displaying “#N/A” and to replace this with something more understandable, like “not found”. After all, that’s the real problem in this case: “Pack 13B” doesn’t exist in our table of data on Sheet2, so we cannot find it.

What a conditional statement does

Let’s talk a little about how Excel handles conditional statements (like “if I have time at midday, I’ll work out at the gym”). The IF principle is straightforward. You want Excel to

look at a value, check to see if it matches another value (that you’ve defined) and if so, to take one action, and if not, to then take another action. The formula in general takes the following form: =IF(logic test, value if true, value if false) Here’s an example of what you could enter into a cell at the end of the first row of our forecast table in Sheet1, referring to example above: =IF(C2=”A”,“fast mover”,“ “) Excel then looks at cell C2, sees that it contains the letter “A” and therefore displays the words “fast mover”. If we changed our forecasts and replaced “product 1” by “product 2” for example, then the cell C2 would contain the letter B (again, according to our example). Excel would then check the condition, see that the content of cell C2 was no longer equal to “A”, and would simply leave the cell at the end of the first row blank (because we specified “ “ as the action in that case).

Figure 10

Page 15: MS Excel 2007 - 10 Techniques the Pros Know v7

10 Techniques the Pros Know 15

Now that we’ve seen conditional statements, we’d like to do something similar to handle error messages. For example, if the content in a cell is the error code #N/A, we’d like to replace the content of that same cell with “not found”, to indicate more clearly that the product entered into the forecasts does not exist in our table of data in Sheet2. We’ll need something more than the simple IF statement above however, because an IF statement like that does not handle error codes as such.

What’s in an (error code) name

We’ve seen the #N/A error code above. From our discussions, we know that in this case it comes from trying to forecast a product with a name that is not present in our table of data in Sheet2. However, you may well encounter other error codes as you build your spreadsheets. They can range over #REF!, #NAME?, #DIV/0!, #NULL!, #VALUE! and #NUM!, as well as the #N/A error code. Knowing what might be causing such errors is the first step to resolving them, or to make sure that you are not ignoring a more serious problem if you choose to simply change the error code into a more comprehensible message.

#NAME? You’ll get this error if you try to reference a cell or a function that doesn’t exist – for example the non-existent “tellmetheanswer()” function. Sometimes it’s a matter of correcting a spelling mistake.

#REF! Comes from trying to reference a cell that cannot be found on the spreadsheet. Can happen for example if you delete a whole column that comes just before another column with formulae still referring to the column that just got deleted. In other words, you start going round in circles!

#DIV/0! Whenever you try to divide a number by zero. You probably wouldn’t do this intentionally, so you have to find out why the denominator in this fraction is turning out to be zero.

#VALUE! When an invalid value or the wrong number of values is specified for use with a function. May come when text and numbers get inappropriately mixed up – remember what we said above about not trying to multiply the sales category (a letter) by the sales forecast (a number)?

#NUM! Trying to put a non-numeric value into a function that expects a numeric one, or when you exceed Excel’s capabilities to handle a number (in which case, it’s better to exceed it in profit on sales, rather than in production costs!)

#NULL! When you try to specify an action on two areas in a spreadsheet that don’t intersect or you have incorrectly specified an address range.

#N/A And so we come round full circle again. This is in fact a generic error code for the case when none of the other error codes above are applicable, but there’s still a problem.

6. ISERROR for fixing things up ISERROR is what we can use to evaluate if we are dealing with an error code, and then take action accordingly. Using the possibilities in Excel to nest formulae (to put one formula inside

Page 16: MS Excel 2007 - 10 Techniques the Pros Know v7

10 Techniques the Pros Know 16

another), we can put our VLOOKUP formula inside an ISERROR formula, and then we use our IF statement from above to make Excel do one of two things according to whether or not ISERROR says there’s an error. The generic way to do this looks like: =IF(ISERROR(expression),action1,expression) This means that if ISERROR detects an error in “expression” (whatever “expression” happens to be), then Excel will take “action1” (whatever that has been defined to be); otherwise, and therefore if there is no error, Excel will display the expression. Using this for example in our forecasts in Sheet1, we could rewrite our formula in cell C2 as: =IF(ISERROR(VLOOKUP($A2,Sheet2!$A$2:$K$5,2,FALSE)),”not found”, VLOOKUP($A2,Sheet2!$A$2:$K$5,2,FALSE) ISERROR will function for all the error codes described above (#NAME?, #REF!, #DIV/0!, #VALUE!, NUM!, #NULL! and #N/A). But in our example, we still need to make sure that if the product name is valid, then the VLOOKUP formula works correctly – so that only a non-existent product name can trigger the “not found” message.

Using IFERROR – two formulae for the price of one

Our use of ISERROR above with our already complex VLOOKUP formula makes it hard sometimes to figure out what’s going on – especially if you come back to this a couple of weeks after you set it up. Because we want to go straight into the IF condition after using ISERROR, Excel conveniently provides IFERROR to combine the two. So now we can

rewrite our formula in cell C2 as: =IFERROR(VLOOKUP($A2,Sheet2!$A$2:$K$5,2,FALSE),”not found”)

What does this give us? If our VLOOKUP formula has no error in it, then IFERROR leaves things as they are, and the result of the VLOOKUP formula is what is displayed in the cell. But if there is an error, then IFERROR causes the phrase “not found” to be displayed. Simpler and more elegant than ISERROR in this situation – just be sure not to mix up the two names, as there’s only a one letter difference between them.

Page 17: MS Excel 2007 - 10 Techniques the Pros Know v7

10 Techniques the Pros Know 17

7. Managing input into your spreadsheet Your spreadsheet is now making you new friends every day. Management seems to be taking an interest. After all, as a useful tool for people in different departments, this kind of thing tends to get management attention. So now management wants to structure the input that people can make – on the one hand to remind people of what options are available, and on the other to avoid people being a little too “creative”. Good news – Excel has a function to let you do just that. It’s the Drop Down List.

Drop-down lists

Making a drop down list for a cell means that the drop down list can display a selection of predefined choices when you click on that cell. You can also attach a notice to the cell with a message, for example, about what you want the user to do. The drop down list appears when you click on the down-arrow to the right of the cell.

Making them

Let’s say you’d like to make a drop down list for the product names for your forecast sheet. As things stand, there are 10 valid product names and they are held in Sheet2 in cells A2:A11.

1. So first of all, go to Sheet1 and click on cell A2, which is where you would enter a product name for VLOOKUP to then go and fetch the relevant associated information.

2. Now click on the Data tab.

3. Click on the Data Validation option that you can see after clicking on the Data tab, to open up a dialog box.

4. Click on the Settings tab in this box.

5. Choose “List” in the Allow menu.

6. Click on the source line in the dialog box.

Figure 11 Figure 12

Page 18: MS Excel 2007 - 10 Techniques the Pros Know v7

10 Techniques the Pros Know 18

7. In this field, enter the following to reference the list of product names you want to use: =Sheet2!A2:A11

8. Write a short and polite message if you want to by going to the Message tab, just next to the Settings tab.

9. Click on OK in the dialog box.

When you now click on cell A2, you should see the arrow appear to the right and your message, if you wrote one. You can then copy cell A2 to as many of the other cells in column A underneath A2 as you want, with a simple drag select and paste. Excel keeps the same reference to the list at Sheet2!A2:A11 in all cases (there is no incrementing of these references to worry about).

Restricting choices

To prevent any unwanted or unwarranted tampering with what is in the drop-down list, you want to be able to lock the data in the drop-down list. Here is how you lock the data, if this was not done by default by Excel when you set up the drop down list.

1. Go to the Data Validation dialog box for the cell concerned, like you did in the procedure above

2. Then go to the Error Alert tab in the dialog box 3. Make sure that the “Show error alert after invalid data is entered” check

box is indeed checked 4. Click on OK to close the dialog box

Page 19: MS Excel 2007 - 10 Techniques the Pros Know v7

10 Techniques the Pros Know 19

8. AutoFilters Wouldn’t you know it! Now that you’ve set up your spreadsheet so that people can easily enter in the right sales forecast data and get revenue, cost and profit data out at the click of a mouse, they’re coming back at you with more questions. Like “how many of those fast moving A-category products are we now forecasting?” If your spreadsheet hasn’t grown much, then you might still be able to see all your product forecasts on one screen and pick out the A-category products visually. But it would still be nice to be able to compile a list just of those particular products, and if you are now dealing with hundreds of products rather than just ten, you certainly need a better solution. OK, you’ve already guessed. When we come up with problems like this that are worth solving, we also have the answer. In this case, the answer is to use AutoFilters. This is how Excel lets

you sort data to be able to just display the A-category products, or the B-category products, or whatever, but without deleting any of the other data on the worksheet. Excel is smart enough for you to tell it with a mouse click what to display, and therefore what to hide.

Making them

Suppose you want to use an AutoFilter on your sales forecast table from Sheet1, for the reasons we describe above. Here’s the sequence of steps to be followed:

1. Click on any cell in your sales forecast table. 2. Go to the Data tab/menu and click on Filter. 3. You’ll see that each column in your sales forecasts table now has a drop down

arrow to the right of the column heading.

Click on the arrow to see the values for that particular column. Note that Excel assumes that the top row in the table has the column headings and that the data only starts on the row immediately below that one. If you’re making your own tables, remember to make the first row for headers, and to put your data into the second, third, fourth, etc. rows thereafter. The fact that you can click on any cell in the table to switch on AutoFilters like this is because Excel assumes that the table is defined by the upper and left-hand borders of the worksheet and the blank row and column below and to the right, respectively. You could also put your table in the middle of a worksheet, surrounded by blank rows above and below and blank columns to the left and to the right. However, this means that you cannot have any completely blank rows or columns in your table. If you do, Excel will think it’s already reached the end of the array, when in fact there was still more data.

Figure 13

Page 20: MS Excel 2007 - 10 Techniques the Pros Know v7

10 Techniques the Pros Know 20

4. If you want to turn off AutoFilter for the same table, just click on one of its cells and then click again on Filter in the Data ribbon at the top of the Excel window to turn it off.

5. Now you can start to filter on individual columns; such as the one for sales categories. To filter for a particular category, say all the “A”s, click on the drop down arrow and remove all the check marks in the list apart from the one for the “A”s.

6. Click on OK to display the filtered list. Now only the rows for the A-category product forecasts are visible. The rows corresponding to the other sales categories still exist in the worksheet, but they have been hidden. Excel indicates that this is what has happened by showing the row numbers for the filtered rows in blue and by changing the drop down arrow in the sales category column to show a smaller arrow and a filter symbol. You can filter in many other ways as well, including for example reordering all the forecasts rows in ascending order of production costs, or descending order of profit earned, and showing just the lowest or highest values in each case. You can also filter on two or more columns at the same time. First apply a filter via one column (e.g. to see just “A”, “B” and “C” category products. Then apply a filter in a second column (e.g. to re-order the rows that are still visible in descending order of sales revenue). And you can “unfilter” in the same way – simply click on the down arrow for the filter concerned, and then on “Clear Filter From…”

9. Using groupings, outlines and subtotals In the same way that you can highlight particular data by using filtering, you can also use Excel to display or hide different levels of detail. As your spreadsheet gets bigger and you start to add more information such as sales forecasts by country, region or sales office, Excel gives you the possibility to display either the global summary and totals, or at the click of a mouse, to dive into and expand the display for a chosen area. We’ll start by making an outline of rows. For this example, we’ve used a copy of our table of data that we’ve put onto a separate worksheet (and kept the original one safe and sound on the first worksheet).

1. The copy of the table of data is a good model to try this on because it satisfies the following conditions: each column has a column header in the first row; each column contains the same sort of data for each of its entries; and there are no blank rows or columns. At the moment, your copy of the table of data looks like this:

Page 21: MS Excel 2007 - 10 Techniques the Pros Know v7

10 Techniques the Pros Know 21

2. Let’s sort this table according to the Sales Category, to have all the “A”s together, the “B”s together and so on. To do this, select the “Sales Category” header (or any other cell in this column) and then go to the Data tab in Excel.

3. In the Data ribbon, click on the simple A->Z sorting icon. This automatically reorders the rows in your table (apart from the column headers) to give this:

4. Now you can insert summary rows and automatically create outlines as you do so. Make sure that you have selected one of the cells in the table above, and in the Data ribbon

Figure 14

Figure 15

Page 22: MS Excel 2007 - 10 Techniques the Pros Know v7

10 Techniques the Pros Know 22

(click on the Data tab again if you need to), click on “Subtotal”. The subtotal dialog box will then open on your screen.

5. In the subtotal dialog box, click on the down arrow for the first field to select “Sales Category”.

6. In the second field, make sure that the function to be used is “Sum”.

7. In the third field, check the boxes for “Product Cost”, “Revenue” and “Profit”.

8. Click on OK in the dialog box and you should see the following (or similar):

You’ll notice a few things about this new display:

The products are neatly separated into groups by sales category, as we wanted, and underneath each group is the subtotal for the cost, revenue and profit concerned.

On the left hand side of the worksheet, the border has been expanded to show “-“ signs, indicating that you can collapse down the different groups of products as you wish. In the top left hand corner, the “1 2 3” icons indicate that our grouping is being done at three levels.

If you want different labels for the subtotals (for example, change “Total A” to “Category A”), then just type the new name you want into the cell containing that label.

Figure 16

Page 23: MS Excel 2007 - 10 Techniques the Pros Know v7

10 Techniques the Pros Know 23

Try clicking on some of the “-“ signs. The groups concerned will contract and the “-“ sign will change to a “+” sign to show that you can expand the group again if you want. Note how the row numbering changes as groups are contracted or expanded:

As you probably saw in the dialog box, you are not limited to adding up figures like this. You can also tell Excel to display the maximum for a group of numbers, the minimum, the average, and so on. You can also set up groups and outlines separately without having to use the subtotals function. On the other hand, using subtotals like this is a foolproof way to see how groups and outlines can be put in place, so that you can explore these separately afterwards.

Figure 17

Page 24: MS Excel 2007 - 10 Techniques the Pros Know v7

10 Techniques the Pros Know 24

10. Formatting

Cloning

Has the following ever happened to you? You’ve tried many different formatting combinations on a cell, such as changing the exact colour, the font, the font size, the border and so on, and you’ve finally found a combination you like. But you just can’t seem to find the same combination again when you want to apply an identical formatting to other cells. Never fear – “Format Painter” is here!

Format Painter is a handy tool that can make you look good and save you headaches and stress. Interested? OK, then – here’s how it works.

Copying

Adjacent cells.

Click on the cell that has all the formatting options that you want to replicate

Click on the Format Painter icon on the Excel toolbar at the top of the Excel window

Hint: you’re looking for this ( ) icon.

Now click on the other cell where you want these same formatting options to apply, or if there are several adjacent cells to be formatted , click on the first cell and drag select the rest.

Non-adjacent cells

The process is similar to the one above. First click on the cell whose formatting is to be replicated

Then double click on the Format Painter icon.

After that you can hop from one cell to another, applying the formatting options each time you click on a cell.

To turn Format Painter off afterwards, click once again on the Format Painter icon.

So for example, after experimenting with just one cell in the top left hand corner (“Product Name”), by double-clicking on Format Painter, we can spread the same formatting out to the other cells as shown, in just a few seconds. Adding the appropriate formatting to your worksheet can make it easier to read and more appealing. It can also draw users’ attention directly to important information. With Format Painter, you no longer even have to try to remember how you formatted existing cells. You can simply swipe new cells (for example, cells you have added to

Page 25: MS Excel 2007 - 10 Techniques the Pros Know v7

10 Techniques the Pros Know 25

the end of a table to present additional data) with Format Painter and in a second or two, it’s done for you. Of course, the example above (figure 18) is just that – an example. You should choose the formatting that makes sense for your spreadsheet and the people who will be using it.

Figure 18 – easy replication of formatting

Page 26: MS Excel 2007 - 10 Techniques the Pros Know v7

10 Techniques the Pros Know 26

Now it’s your turn… In this book, you’ve seen how to apply different Excel techniques to be able to easily comb ine data from several sources into one worksheet (VLOOKUP), and how to make sure that the data you bring in is in the right format - either by handling it with functions like TRIM, LOWER, UPPER, etc. or by restricting choices by using drop down lists. If you want to put your formulae in place, ready for use, but you don’t yet have the data to plug into them, then ISERROR and IFERROR let you avoid those arcane Excel error messages and replace them with something much more user friendly. Finally, for formatting ease and readability for both you and anyone else who uses your spreadsheet, you saw how Format Painter, AutoFilters, and Subtotals and Outlines can draw attention to particular information on your spreadsheet or easily mask other data without deleting them. You’ll get the most out of this book if you put the techniques into practice for yourself. Pick the ones that are likely to be the most useful for you first of all. And start with simple cases, like the ones used here. Step by step, you can build them up to more complex ones. Check at each step that you’re getting the result you should. If at the next step something unexpected happens, you just have to undo the last step and figure out how to fix it, rather than trying to dive into a complicated formula where it’s often hard to know where to begin. Happy exceling! And feel free to let us know how you get on!