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

30
Computer Science 1000 Spreadsheets IV Permission to redistribute or use these slides is strictly prohibited without permission

Upload: bernadette-easter-richard

Post on 05-Jan-2016

221 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Computer Science 1000 Spreadsheets IV Permission to redistribute or use these slides is strictly prohibited without permission

Computer Science 1000

Spreadsheets IV

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

Page 2: 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?

Page 3: Computer Science 1000 Spreadsheets IV Permission to redistribute or use these slides is strictly prohibited without permission

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”

Page 4: Computer Science 1000 Spreadsheets IV Permission to redistribute or use these slides is strictly prohibited without permission

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”

Page 5: Computer Science 1000 Spreadsheets IV Permission to redistribute or use these slides is strictly prohibited without permission

Relative References relative references work across rows and

columns they even work across multiple sheets and

multiple workbooks (coming soon!)

Page 6: Computer Science 1000 Spreadsheets IV Permission to redistribute or use these slides is strictly prohibited without permission

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

Page 7: Computer Science 1000 Spreadsheets IV Permission to redistribute or use these slides is strictly prohibited without permission

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

Page 8: Computer Science 1000 Spreadsheets IV Permission to redistribute or use these slides is strictly prohibited without permission

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

Page 9: Computer Science 1000 Spreadsheets IV Permission to redistribute or use these slides is strictly prohibited without permission

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

Page 10: Computer Science 1000 Spreadsheets IV Permission to redistribute or use these slides is strictly prohibited without permission

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.

Page 11: Computer Science 1000 Spreadsheets IV Permission to redistribute or use these slides is strictly prohibited without permission

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.

Page 12: Computer Science 1000 Spreadsheets IV Permission to redistribute or use these slides is strictly prohibited without permission

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

Page 13: Computer Science 1000 Spreadsheets IV Permission to redistribute or use these slides is strictly prohibited without permission

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

Page 14: Computer Science 1000 Spreadsheets IV Permission to redistribute or use these slides is strictly prohibited without permission

While the range is highlighted, format it to Currency.

Page 15: Computer Science 1000 Spreadsheets IV Permission to redistribute or use these slides is strictly prohibited without permission
Page 16: Computer Science 1000 Spreadsheets IV Permission to redistribute or use these slides is strictly prohibited without permission

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

Page 17: Computer Science 1000 Spreadsheets IV Permission to redistribute or use these slides is strictly prohibited without permission

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

Page 18: Computer Science 1000 Spreadsheets IV Permission to redistribute or use these slides is strictly prohibited without permission

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.

Page 19: Computer Science 1000 Spreadsheets IV Permission to redistribute or use these slides is strictly prohibited without permission

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

Page 20: Computer Science 1000 Spreadsheets IV Permission to redistribute or use these slides is strictly prohibited without permission

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

to the tax rate cell

Page 21: Computer Science 1000 Spreadsheets IV Permission to redistribute or use these slides is strictly prohibited without permission

References conveniently, anytime we replace the tax rate, the

tax in E2 updates appropriately

Page 22: Computer Science 1000 Spreadsheets IV Permission to redistribute or use these slides is strictly prohibited without permission

Referenceswhat happens if we fill the other items to

update their formula?

Page 23: Computer Science 1000 Spreadsheets IV Permission to redistribute or use these slides is strictly prohibited without permission

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

Page 24: Computer Science 1000 Spreadsheets IV Permission to redistribute or use these slides is strictly prohibited without permission

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

Page 25: Computer Science 1000 Spreadsheets IV Permission to redistribute or use these slides is strictly prohibited without permission

Absolute References notice that by using an absolute reference, we

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

Page 26: Computer Science 1000 Spreadsheets IV Permission to redistribute or use these slides is strictly prohibited without permission

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

Page 27: Computer Science 1000 Spreadsheets IV Permission to redistribute or use these slides is strictly prohibited without permission

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

Page 28: Computer Science 1000 Spreadsheets IV Permission to redistribute or use these slides is strictly prohibited without permission

Mixed References

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

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

Page 29: Computer Science 1000 Spreadsheets IV Permission to redistribute or use these slides is strictly prohibited without permission

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.

Page 30: Computer Science 1000 Spreadsheets IV Permission to redistribute or use these slides is strictly prohibited without permission

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