• Aucun résultat trouvé

MAX and MIN—Recording Highs and Lows

Dans le document Microsoft Excel 2010 (Page 80-88)

But let’s return to the entries in the AutoSum menu. MAX and MIN are almost self-evident; they identify the highest and lowest cells in a range while ignoring blank cells (and text entries), an important omission in these regards. After all, treating blanks as zero could erroneously yield a MIN of zero among a range of other cells—and if you’re working with a range consisting entirely of negative numbers, counting a blank cell as zero could yield a MAX of…zero!

And you’ll doubtless be able to find a broad niche for MAX and MIN in your spreadsheet doings.

And by way of recapitulation—all the functions assigned a place on the AutoSum drop-down menu are written the same way:

=NAME (range, or ranges)

I’m harping on this point because a great many of the other functions in the Excel repertoire display a different syntax, as you’ll see.

And while we’re talking about SUM, COUNT, AVERAGE and the like, here’s another handy but easy-to-miss, hidden-in-plain-sight take on these operations and some more. If you select any set of cells containing numbers (at least two cells, to be exact) and train your gaze on the lower right of the

worksheet screen, on what’s called the Status Bar, you’ll suddenly see a see a mini-report about the data you’ve highlighted (Figure 3–20):

Figure 3–20. A range’s status report on the Status Bar

There it is—the Average, Count, and Sum of the range you’ve selected. Just know that the Count here is really COUNTA; that is, it will count any data in the cell—values, text, and even formulas. What we’re presented with here is an on-the-fly summary of the data in the selected range. None of this information will actually appear in the worksheet—and once you move elsewhere to other cells, those figures will change. Still, if you need a quick improvised read on certain data, select that range and take a look.

And what you see there can be customized, at least within limits. If you right-click anywhere on the status bar, you’ll trigger a towering short-cut menu, which, among other things, allows you to add three more calculations to the bar (Figure 3–21):

Figure 3–21. Where you can add functions to the Status Bar

Thus Numerical Count (that is, COUNT), Max, and Min can take their place on the Status Bar too if you need them; simply click them on.

But now that we’ve gotten our feet wet in the Olympic-sized pool of functions, grab a towel and sit back, because we’ve some more copying and moving to do, of a different and most important kind.

And in this connection, let’s go all the way back to that sample grade-average worksheet I served up in Chapter 1, the one festooned with red highest-score cells and those Sparklines. Don’t remember it?

I’m not taking it personally—look at Figure 3–22 for a refresher:

Figure 3–22. Grade averages by student

Now look at the Formula Bar. I’ve clicked cell I10, the one bearing Alice’s exam average, and its means of calculation—using AVERAGE, of course—--is recorded up there in that bar. By way of review, we see that Alice’s grades occupy range D10:H10 and, by inserting that range reference between AVERAGE’s parentheses, we determined her average grade was 83.0.

The point is this: What if I have 150 students in the class (and I’ve had more than that on occasion), and I need to figure the test average for each and every one of them? Do I have to click the AutoSum button 150 times in order to carry out that disagreeable task?

Yes, that sounds like a rhetorical question, and it is. The answer to it is no, because what we can do instead is copy Alice’s AVERAGE formula down the I column for as many rows of students as I need.

Yes, this is a have-to-know, because copying a formula—which entails in essence copying cell references— is something new—and vital—to the your understanding of how Excel works.

But in fact the ways of actually copying cell references are identical to the ones we described earlier (and we’re going to learn an additional one soon); what’s different is what happens when you copy them. And that preamble raises a larger point. All the cell copying we’ve discussed to date and will continue to discuss in this chapter entail copying whatever we enter in a cell—as opposed to what we see in the cell. If I copy Alice’s AVERAGE elsewhere, I am most assuredly not copying her average of 83.

Rather, I’m copying what I typed in cell I10—the formula that calculated her 83.

The following table enumerates the relationship between the kinds of data I could enter in a cell and what I would see in that cell. In every case, what I would copy is posted in the left column of Table 3–2 below:

Table 3–2. Cell Entries and Cell Displays Data Example (what you’ve typed in the cell,

which is what gets copied) What you see in the cell

3 3

=4+5 9

=T3/7 The result of whatever number you enter in T3 divided

by 7

=AVERAGE(A4:G4) The average of all the numbers you’ve entered in A4 through G4.

Again, what gets copied is what you’ve actually typed in the cell. And if you copy any expression which contains a cell reference, what will happen is that the cell references in the destination cells—the cells to which you’ve copied—will change, corresponding to the distance in either rows or columns from the original cell you’ve copied.

If I copy the number 1, either 1 or a 100 times, I’ll see nothing but 1’s in the range to which I’ve copied. But if I copy this:

=C7

what I’ll see depends on where I’ve copied it. If that =C7 was positioned in cell A2 and I copy it to cell A3, I’ll see this in that destination cell:

=C8

By way of a more pertinent example, if I go to cell I10 in our grading worksheet and copy Alice’s formula:

=AVERAGE(D10:H10) down one row to I11—Derek’s row—we’ll see:

=AVERAGE(D11:H11)

You’re probably starting to get the idea. If I were to copy Alice’s formula all the way down to say, cell I20000—and there’s no reason why I couldn’t—I’d see:

=AVERAGE(D20000:H20000)

See what’s changed, and what’s remained the same? Remember that a cell address comprises a lettered column reference and a number row reference—and when you copy cell references down a column, only the original row references change, commensurate with the distance you’ve traveled from the original cell. That’s because you’ve moved down rows, and haven’t shifted any columns—and the destination results reflect the amount of movement from the source cell reference.

If on the other hand, were I to copy Alice’s formula to cell L10, I’d see:

=AVERAGE(G10:K10)

And see why? In this case, I’ve copied Alice’s original formula three columns to the right, such that only the column parts of its cell references—that is, the letters—have changed, again corresponding to the degree of movement from I10. Thus G is three column letters “away” from D, and K is three columns removed from H. And this time there’s been no change in the row references—the numbers, because we’ve copied across columns only, remaining on the same row as Alice’s average. We’re still on row 10 in this case.

A quick, acronymic way for nailing this row/column movement question is CARD, which stands for:

Columns Across, Rows Down. Copy a cell reference across, and the column letters change; copy it down—or up—and the rows numbers change.

In any event, we’ve encountered a foundational spreadsheet feature—relative references —which describes what happens by default when you copy a cell reference to any other cell. We can see now that if I click on Alice’s original AVERAGE formula, I should be able to copy it down the I column for as many rows as I need, confident in the knowledge that, as long as the original formula is correct, I should be able to compute all the other students’ averages correctly. Put another way, I need only write AVERAGE once—and then copy it; and so you can see why this tool is so potent.

And note, by the way, that cells can certainly team cell references with simple numeric values; just keep in mind that copying such a cell will only change the cell reference. Thus if I write this:

=D5+7 in cell H2 and copy it down one row, I’ll get:

=D6+7

We see, then, that the 7 won’t change—only the original D5 will.

And when you need to copy a formula containing cell references down a column or across a row, there’s a most expeditious way to do so, by finding a novel use for a tool we already know —the fill handle. To illustrate:

Let’s take a few steps back in the design of our grading sheet, and for the sake of clarity, we’ll scrub away all the fancy formatting, too. We’ve written Alice’s AVERAGE formula, and now want to copy it down the column, as in Figure 3–23:

Figure 3–23. Alice’s average will serve as the formula to be copied

If I station my mouse over the fill handle in cell I10—Alice’s test average—and then click the handle, don’t release the mouse, and drag down the column through Ringo’s cell in cell I19 and then release the mouse, I will have copied all the student AVERAGE formulas, as in Figure 3–24:

Figure 3–24. Copying allowed, here: Dragging to copy Alice’s formula gives me the averages for all the students

Then click anywhere to turn off the blue selection color. Here, the fill handle—that same device we earlier put to the task of producing series of data—e.g., 1,3,5,7, days of the week, etc.—is used to copy formulas. Just click on the first (which at the moment is the only) formula, and drag the fill handle as far as you need to go—either down a column or across a row. The copy procedure collaborates with relative referencing to install the proper cell references in each cell, and what this means is that if you need to copy a formula to many cells, you only need to actually write the formula once—the formula that will serve as the model to be copied to all other cells.

And once you learn how that capability works, there’s an even easier and cooler means to carry out this kind of copying task. Once you write that first, model formula, click back on that cell (in this case Alice’s average in I10), and double-click the fill handle. All the other student cells running down the I column receive the formula, without you needing to drag the fill handle. The double-click automatically copies the original formula down all the cells that also have data in the immediately adjoining column to its left or right.

To summarize this tip—if you need to copy a formula down a column—and this only works when you copy down a column, not across a row—click on the cell storing the original formula and then double-click its fill handle. As long as there are data in the adjoining column (either to the left or right;

and that means in our example if the H column were empty this wouldn’t work), the formula copies down for as many rows as there are data. And this will work as surely for 20,000 rows as it will for 20. I use this shortcut all time; I told you I was lazy.

Now there is one more permutation of this cell-reference copying business that you need to know.

Consider this case:

Suppose I’ve given my students a rather challenging exam, and, after having canvassed the sobering results, decide to grant them an extra three points in order to curve the scores upward. My simple grade book looks like Figure 3–25, at the outset:

Figure 3–25. Test scores, about to be boosted by three points each

So how do I go about padding these pause-giving scores by those three points? Gordon’s score is in cell D11, and so I could write the following in E11, couldn’t I:

=D11+3

Sure I could. Then I’d return to cell E11, and utilize my newfound double-click-on the fill-handle trick.

I’ll bring about this revised grade distribution (Figure 3 - 26):

Figure 3–26. Nice guy: the three-point curve, now in effect

Are my calculations correct? Absolutely; but still I wouldn’t recommend this approach. That’s because if I conclude that I need to award my charges say, 5 points instead, I’d need to edit the formula in E11 to read:

=D11+5

and then copy that rewritten expression down the column again, so that all the students will enjoy my 5-point largesse. Not an enormously big deal, but not an elegant way in which to proceed. As a rule, one wants to avoid editing cells if one can; it can get messy, and a preferable alternative would be to enter the 5-point bonus figure in a cell—say in this case, A11, and rewrite Gordon’s formula thusly:

=D11+A11

and copy it down the column. And exactly why is this approach recommended? Because if I change my mind again and issue a 7-point curve, all I need do is type 7 in cell A11, and all the scores should change automatically—with no additional cell editing required.

Dans le document Microsoft Excel 2010 (Page 80-88)