computer science 1000 spreadsheets iv permission to redistribute or use these slides is strictly...

Post on 05-Jan-2016

222 Views

Category:

Documents

2 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Computer Science 1000

Spreadsheets IV

Permission to redistribute or use these slides is strictly prohibited without permission

Relative Referencesas noted before, Excel seems to do the right

thing when it fills when filling from cell D2, the

formula =B2*C2 automatically became =B3*C3 when applied to cell D3

how did it know to do that?

Relative References when we make a reference using the syntax

defined so far, Excel considers it a relative reference

behind the scenes, a relative reference is not defined as a fixed location, but as a location relative to the current cell

stated another way, the formula Excel uses in D2 is “the cell two columns behind me times the cell one column behind me”

Relative References hence, when a relative reference is copied to a new

cell, the formula is changed to maintain the same spatial relationship

in our example, when the formula from D2 is copied to D3, the references are replaced, so that the new references are “two columns behind D2” and “one column behind D2”

Relative References relative references work across rows and

columns they even work across multiple sheets and

multiple workbooks (coming soon!)

Relative References - Practice suppose that Canada decides to make driving gloves tax-exempt this means that we should compute GST on all items except driving

gloves let’s reformat our receipt, so that the GST is computed for each

individual item

Step 1: Reformat Table delete the appropriate rows from the table

click on a row, right-click, and select Delete

add the appropriate columns to the table

Step 2: Compute Tax for each Item two steps

1) determine the tax rate for that item Driving Gloves – 0% Everything else – 5%

2) multiply that tax rate to the item let’s do the first step first

that is, let’s fill the Tax column with the appropriate tax rate can we do this, whilst keeping the formula consistent for each row?

yes – use an if statement

The If Statement if the item is Driving Gloves

tax rate is 0%

otherwise tax rate is 5%

Turn this into a True/False statement

=IF( A2 = "Driving Gloves“ , 0.00 , 0.05 )Boolean

This is the value of the cell if the item is Driving Gloves

This is the value of the cell if the item is not Driving Gloves

True Value

False Value

Notice that the appropriate choice was made for the tax rate (we’ll update this to the tax amount soon). Now, use the fill handle to fill the other columns with the same formula.

Because of relative referencing, the A2 reference in the first cell updates appropriately. Notice also that because of the if statement, the last cell has a 0% tax rate, as required.

Step 2: Compute Tax for each Item our example is coming, but it’s not quite the same

as what was shown originally rather than showing the tax rate in that column, we

should show the tax amount solution:

multiply the tax rate by the price of the items

Now, fill the rest of the column with the new formula.

While the range is highlighted, format it to Currency.

Step 3: Compute Total for each Item the total for each item is computed as the price +

tax using relative references, we need only compute

the total for F2, and can fill the rest

Step 4: Compute the Bottom Totals the bottom totals are simply the sum of the prices in

each cell note that since we have already computed that total

in D7, we can simply fill the others with that formula

References suppose that Canada changes GST to 7% how many cells do we have to change in our

previous example? all of the item rows (5 in our example) if this were a long receipt, would be cumbersome

These formulas all have to be changed.

References instead of hard-coding 5% into our formula, let’s

make it a cell reference we will store the current tax rate in cell H1

References now, replace the value 0.05 in our formula to refer

to the tax rate cell

References conveniently, anytime we replace the tax rate, the

tax in E2 updates appropriately

Referenceswhat happens if we fill the other items to

update their formula?

References remember: unless explicitly stated otherwise, a cell

reference is relative in our formula for F2, referring to H1 meant “the cell

one up and three to the right” hence, in the formula for F6, one up and three to

the right = H5

Absolute References we can correct the previous example by using an

absolute reference prepend the row/column name with $ by doing this, the cell reference is always the same for

every filled cell

Absolute References notice that by using an absolute reference, we

achieve our desired behaviour updating the tax rate changes all totals appropriately

Mixed Reference note that we have a mixed cell reference

row is relative, while column is absolute or vice versa

in this case, the relative reference will change during a fill, but the absolute reference won’t

example: create a simple table that converts Canadian dollars to three other currencies, for a few specified amounts.

furthermore, we only want to specify the formula once, and use fills for the rest

Mixed References

For each cell, we want to multiply the left most value (amount) by the amount from its second row (rate).

For the amount: - row should be relative - column should be absolute

For the rate: - row should be absolute - column should be relative

Mixed References

For the amount: - row should be relative - column should be absolute

For the rate: - row should be absolute - column should be relative

Mixed Referencesnow, we can fill both rows and columns

Notice that for the filled cells, the amount always refers to column A, while the rate always refers to row 2. However, the other references update appropriately.

Mixed References in our previous example, could we have used a

mixed reference? yes – since our items are always in the same column, we

could use a relative column reference

top related