A formula is only as good as its references.
No matter how creative and brilliant your formula is, it won’t do you much good if it does not point to the correct data. It’s easy to get references right for short, individual formulas, but once those formulas get long and need to be copied, the chance of reference mistakes increases dramatically. In this chapter, you’ll exploit absolute and relative references as well as Excel’s advanced new structured reference feature, ensuring that no matter how big and numerous your references are, your formulas will stay tight and accurate.
As the boss of Ace Computer Manufacturing, you know how critical it is to maintain your profit margins in the volatile and competitive business of selling computers.
You need to get on top of your supply chain: are you marking up your computers enough to make a profit? You need to take control of your data to figure it out.
In the computer industry, component prices are always changing, so in order to ensure that you’re getting a healthy margin on the computers you sell, you need to make sure you’re getting the best deal you can.
If you bought the least expensive acceptable parts, how much would the resulting configuration cost?
www.headfirstlabs.com/books/hfexcel/hfe_ch03_low_end_forecast.xlsx
There are multiple worksheets in this file.
You need a function to find the lowest price on the memory worksheet.
When you have a range of numbers and want to figure out what is the smallest number in that range, use the MIN
function.
And, in case you hadn’t guessed it already, the function that tells you the largest number in a list is MAX
.
What you need to do now is write MIN
formulas to find the lowest cost for each of these components and see how much your low-end computer configuration will cost this quarter. Using that information, you’ll be able to forecast your profitability.
Excel does indeed have a syntax for pointing to ranges that exist on worksheets other than the worksheet where your function resides. And you’re about to learn that syntax. But not from this book.
Instead, Excel’s going to show you. One handy trick in writing formulas with arguments that involve cell ranges is to start writing a formula, getting to the argument of your function where you want to put the range but not typing anything:
Now, instead of typing the reference, just use your mouse to select the data you want. Go ahead and click on a different worksheet (or even a different workbook) and select your data with the mouse. Excel will fill in the range for you.
Finally, type a comma for your next argument or a ) symbol to end your formula and press Enter.
What happens?
When you use the mouse to select the data you want your MIN
formula to evaluate, Excel automatically fills in the range for that data, even if the data is on a different worksheet.
Here’s how Excel describes the range for memory prices you want to evaluate.
The range does look a little similar to the first one you tried...
...except that in this case it adds the LowMem! element, which tells Excel to evaluate the range D4:D19
on the LowMem worksheet. So far, we haven’t included an element to describe which worksheet we want to reference, and Excel has taken that to mean that we want to reference the same worksheet where we’ve put our formula.
Now filling in the lowest prices for the rest of the components will be a snap!
Sweet! That definitely means that the computers you sell will earn a higher profit margin. Better calculate to see how much.
You’ve thus far been using relative references in your formulas...
...and when you copy and paste them, relative references shift in proportion to the original formula.
But sometimes you want a reference to stay fixed no matter where you copy and paste it. In that case, you need to use an absolute reference.
To tell Excel to make a reference absolute, the syntax is to add dollar signs. If you put a dollar sign before the column, the row can shift, and if you put one before the row, the column can shift, and if you use two dollar signs, the reference will stay totally fixed.
With your corrected formula using absolute references, you were able to copy and paste to your motherboard and hard disk fields, showing your discounted component costs.
Copying cell C8
and pasting to cell C11
would normally shift the reference in that cell from B4
to B7
—a shift in rows. To prevent the row from shifting, put a $
in front of the 4
in your reference.
You can also put a $
in front of the B
in your reference, but it won’t make a difference, because copying cell C8
to cell C11
wouldn’t cause a shift in column references anyway.
Looks like you’re going to get to pay yourself a big dividend this quarter, assuming that sales go well....
Depending on where you think you might need to copy your references, you should always consider using absolute references to make sure your formulas point where you want them to.
It can indeed. As important as references are, they can become unwieldy once your formulas get long and numerous. If your references start to confuse you, you can turn to a powerful feature of Excel called named ranges....
This reference takes a moment to understand.
Even if you wrote it yourself, chances are, in the future you’ll forget its meaning and have to go back and forth to make sure you know where the reference is pointing. This formula takes a long time to understand.
When you used named ranges, you can replace those references with a plain-language name of your choosing.
And once you name your ranges, which by the way are by definition absolute references, you can drop them right into your formulas.
No problem. Let’s take a look at the data for the other computer lines and see what we can do.
It could take you quite a while to come up with this.
Having more named ranges would be a help.
Your formulas would certainly be easier to read. But going through a whole bunch of cells and ranges and naming them individually takes a lot of time, too!
When you click inside your data and click Table under the Insert tab, Excel gives you all sorts of options, including automatically generated range names. Once you’ve created your table, you can use a special syntax called structured references to simplify your range names.[3] Here’s how you make a table.
Select your data, then head over to the Insert tab and click Table.
Change your table name from Table1 to something more meaningful.
Now you have a table! Go ahead and start using it for structured references.
Easy, right? And you don’t have to worry about making your references point to sheets anymore, since Excel knows how to find your table in a workbook using the structured reference.
Between the $A$1 style of references that you’ve learned and the references that you can name, you’ve spanned a broad universe of possibilities for referring to your data inside of formulas.
Let’s finish off our computer spreadsheet with some structured references....
Business is great, and your sales guys are happier than ever!
[3] Structured references are another one of those Excel 2007 and later–only features. It’ll come to Mac eventually.