excel advanced lessons - collection 1

Upload: banglecowboy

Post on 30-May-2018

227 views

Category:

Documents


1 download

TRANSCRIPT

  • 8/14/2019 EXCEL Advanced Lessons - Collection 1

    1/43

    Putting a DropDown ListBox in a Cell

    A single cell ( or even an entire column ) can be given a data validation setting so that,when selected, a dropdown list appears with a finite list the possible entries for thatrange.

    To create a dropdown list, restricting entries in a range to those values, follow thesesteps:

    1. Select the range that is to contain the validation dropdown listbox. This may beeither a single cell or a larger range, such as an entire column.

    2. From the Data menu, choose Validation .

    3. On the Settings tab, in the Allow dropdown list, select List .

    4. The Source box can refer to a range of cells for its values, or it can contain themdirectly.

    o ... a direct list :

    You may type the source list directly in the Source box.

    In this example, the list is simply days of the week, separated by commas. Notice there are no quotes around the text.

  • 8/14/2019 EXCEL Advanced Lessons - Collection 1

    2/43

    o ... a referenced list :

    Click in the Source box, and then either type a range reference manually[ preceded by an = ( equals ) sign ] or use the mouse to select a range on thesame worksheet that has the source list of possible entries.

    If a user tries to manually enter anything other than these values, a stop message appearsand will not allow the cell to keep the invalid entry. The only options for the user will be

    to Retry or Cancel .

    It will be possible to make valid entries (i.e., MON, TUE, WED, etc .) manually in a cellto which this validation setting has been applied; a user is not required to actually selectthese values from the list.

    Some Possible " Gotchas "

  • 8/14/2019 EXCEL Advanced Lessons - Collection 1

    3/43

  • 8/14/2019 EXCEL Advanced Lessons - Collection 1

    4/43

    Multiple Criteria Text Look-Up

    Let's say you need to return a text value from a list, in which there are multiple criteriaused to determine which record provides that data.

    There are various options available for the task. Filtering could be the quick and easyway. And, developing a VBA procedure for the job would be another alternative.

    Nonetheless, we really just want a formula for this -- and, sometimes that makes the mostappropriate solution.

    First, let's look at the data in the example I've set up.

    There are three all-TEXT fields: Company , Name , and E-Mail . We want to write aformula to return an e-mail address from the table, based on a combination of theCompany and Name field values as criteria.

    Notice, the table has records for two companies, ABC CORP. and XYZ CORP. , and both have someone named Charles Smith .

    Step 1 will be to create two named ranges - one encompasing the Company field and theother for the Name field. Dynamic Named Ranges would be ideal, but for the sake of a

    http://www.beyondtechnology.com/geeks007.shtmlhttp://www.beyondtechnology.com/geeks007.shtmlhttp://www.beyondtechnology.com/geeks007.shtml
  • 8/14/2019 EXCEL Advanced Lessons - Collection 1

    5/43

    simple illustration we'll create a couple of conventional named ranges.

    From the worksheet's Insert menu choose Names then the Define... command. Enter aname for your new range. We'll use Sheet1!rngCompany and Sheet1!rngName . Next,in the Refers to: box, enter or select the following to be rngCompany :

    =Sheet1!$A$1:$A$7

    ... and, respectively, for rngName in our second field :=Sheet1!$B$1:$B$7

    Step 2 will be for us to set-up another range, for entering the lookup criteria and our formula. We'll just move over a few columns for this.

    In cells E2 and F2 I've entered a Company and a person's Name . The combination of both of these will be our lookup criteria.

    In cell G2 I've entered the following as an array formula:

    =INDEX(C:C,MATCH(E2 & F2,rngCompany&rngName,0))

    Now [ IMPORTANT before you hit the enter key] , you will need to use Ctrl + Shift +Enter instead. This creates an ARRAY FORMULA , recognizable by the curly brackets

    " { } " that automatically appear around it. You never type these curly brackets whenentering an array formula.

    Here's how this works -

    The key to the formula is concatenation of the criteria variables, also the lookupranges. To concatenate means to join together. There is a CONCATENATEfunction for this purpose, but an ampersand ( & ) will work just the same.

    Therefore, instead of looking at two distinct fields, the formula will be treating theCompany and Name as though it is a single field.

    The criteria will be the combination of cells E2 and F2 . Concatenated, it lookslike " ABC CORP.Charles Smith ", stuck together.

    The MATCH function returns the index number within the lookup array of theitem matching the given criteria.

    We needed to get the MATCH function to treat the Company and Name fields

  • 8/14/2019 EXCEL Advanced Lessons - Collection 1

    6/43

    as though they are just one field. We've done so by concatenating the namedranges - rngCompany & rngName .

    By the way, the MATCH function in this example gives us the value of 3.

    Finally, the INDEX function with a zero as the 3rd argument, returns the item,from an array, corresponding to the index value argument (that will be the rownumber of the matching record).

    Our formula returns the 3rd item in range C:C , the E-Mail field.

    Note: We're counting the header (row 1), since it was also included in the criteriaranges.

    Finally, we can improve this formula by accomodating the possibility that there is nomatch in the lookup table. This formula is really one line, but it's shown as wrapped ontoa second line so it will fit on this page.=IF(ISNA(INDEX(C:C,MATCH(E2 & F2,rngCompany&rngName,0))),"MISSING",

    INDEX(C:C,MATCH(E2 & F2,rngCompany&rngName,0)))

    Translating this to plain English, it says -" If a match is NOT found in the table, then display the word 'MISSING' instead of a function error ."

    Another Approach

    It is unlikely, however possible, that a combination of the criteria could be the same whenconcatenated.

    In this example, the multiple criteria could be A & BC = ABC just as AB & C = ABC .

    Therefore, another approach would be in order. Referring to our original example, thearray formula in range G2 could be:

    =INDEX(C:C,MATCH(1,(E2=rngCompany)*(F2=rngName),0))

  • 8/14/2019 EXCEL Advanced Lessons - Collection 1

    7/43

    Conditional SumExcel's SUMIF is one of it's most versatile and truly useful native worksheet functions.Here is one of the many ways it can be applied in your projects.

    Here's the scenario. Let's say you have a column of numbers (col A) -- both positive and

    negative values. How can you sum just the numbers meeting some criteria ... such as,only those greater than or equal to zero.

    Here's the formula ...

    =SUMIF(A:A,">=0",A:A)The first argument tells Excel what range to evaluate. In this case, we're evaluating theentire column A.

    The second argument is your criteria. So, for our example it's all positive numbers ">=0"(notice the quotation marks).

    Finally, the third argument says what range to use to get the values to sum whenever your criteria is met. In our case, again it's all of column A.

    Here's the key to understanding the SUMIF function. The items to be added in the sumrange corresponds to the index of the items matching the criteria in the evaluated range.In other words, if the fifteenth item in evaluated range satisfies your criteria then thevalue of the fifteenth item in the sum range will be included in the total returned by theformula.

  • 8/14/2019 EXCEL Advanced Lessons - Collection 1

    8/43

    Conditional Average

    An AVERAGEIF worksheet function was introduced with Excel 2007.

    I'll show you how to use this if you are working on a later version.

    And, since it did not exist until recently as a standard feature in Excel, we walk throughhow to create an equivalent. This can be done by dividing the result of a SUMIF function

    by the result of a COUNTIF function.

    Let's say you have the list of items with prices shown in the first two columns of thistable. You need to be able to get the average price of all items of a color. In our example,we'll get the average of the "blue" items.

    Excel 2007 ( and presumably beyond )

    So that you can avoid the need to hard code the criteria in your formula, in our exampleyou can just enter the name of a color in cell C2 . The result is being displayed in cell C5 ,where we've entered the following formula ...

    =AVERAGEIF(A2:A8,C2,B2:B8)The first argument tells Excel what range to evaluate. In this case, we're evaluatingA2:A8 .

    The second argument is your criteria. For our example the formula will average all the"blue" items since that is the criteria entered in cell C2 .

    Finally, the third argument says what range to use to get the values to average whenever your criteria is met. In our case, the formula will average the values in range B2:B8 thatcorrespond to the items labelled as "blue" in A2:A8 .

    Here is the key to understanding the AVERAGEIF function (or, for that matter, theSUMIFIF and COUNTIF functions we'll see below). The items to be included in thecalculation correspond to the index of items matching the criteria in the evaluated range.In other words, if the seventh item in the evaluated range satisfies your criteria then thevalue corresponding to the seventh item will be included in the formula's calculation.

  • 8/14/2019 EXCEL Advanced Lessons - Collection 1

    9/43

    Before Excel 2007 ~ the old fashioned way

    As with the preceding example, so that you can avoid the need to hard code the criteria inyour formula, you can just enter the name of a color in cell C2 . The result is beingdisplayed in cell C5 , where we've entered the following formula ...

    =SUMIF(A2:A8,C2,B2:B8)/COUNTIF(A2:A8,C2)The first part of this formula returns the sum of the prices for all the "blue" items. We'reevaluating the range containing the names of the colors in column A. In other words, thisformula says ...

    look at the list in column A and if there's a match on the entry in cell C2 theninclude that item's corresponding value from column B in the addition.

    =SUMIF(A2:A8,C2,B2:B8)The result is 18.00 .

    The second half of this formula returns a count of the "blue" items. Again, we'reevaluating the range containing the names of the colors in column A. So this part of theformula says ...

    look at the list in column A and if there's a match on the entry in cell C2 thencount that item.

    COUNTIF(A2:A8,C2)The result, of course, is 3.

    Finally, all that remains to be done is to divide the sum of items matching your criteria bythe count of those same items. So, 18.00 / 3 = 6.00 -- the average price of "blue" items .

    One More Valuable Tip:

    To improve usability, you can try to use named ranges whenever it is possible and practical. For instance, in this example you may want to do something like this ...

    A2:A8 = Colors B2:B8 = Prices C2 = Criteria

    ... so your formula could be restated as ...=SUMIF(Colors,Criteria,Prices)/COUNTIF(Colors,Criteria)

    If you are familiar with the use of an array formula, here's another approach to aconditional average.

    {=AVERAGE(IF(Colors=Criteria,Prices))}

  • 8/14/2019 EXCEL Advanced Lessons - Collection 1

    10/43

    Remember, you don't type the curly brackets {} and hold down the CTRL key andSHIFT key when entering your array formula. So, after you type the formula in theformula bar or range the last step will be CTRL + SHIFT + ENTER.

    In this case we're saying if an item's COLOR matches our CRITERIA, then include thePRICE amount in the array of values to be averaged.

    Otherwise, if any field in a record fails to meet our criteria, then the amount for thatrecord will simply be ignored. FYI, the 3rd argument in an IF worksheet function isoptional - it simply defaults to a FALSE if omitted.

    One thing to be aware of when using this formula is that the AVERAGE worksheetfunction will return a #DIV/0 error if there are not any records that satisfy your criteria.The workaround is to write a longer formula that traps the error and returns either a 0(zero) or "" (empty quotes) if there are no records matching the criteria. Something like

    this ...{=IF(ISERROR(AVERAGE(IF(Colors=Criteria,Prices))),"",

    AVERAGE(IF(Colors=Criteria,Prices)))}

  • 8/14/2019 EXCEL Advanced Lessons - Collection 1

    11/43

    IsError Function

    Sometimes it is necessary to include formulas in a worksheet that will require the sheet to be completed by a user before they will display a correct result. In this case, you couldhave error values throughout the spreadsheet until you get all the necessary input. Themost common workaround to suppress #DIV/0! and other errors from is to apply theISERROR function in your formulas. Something like so ...

    =IF(ISERROR(A1/B2),"",A1/B2)

    This would say if cell A1 divided by B2 caused an error, then make the value in the cellequal to nothing -- otherwise (ELSE), make it whatever A1 divided by B2 really should

    be. This is a good way of handling 'can't divide by zero' and similar errors. You can alsosubstitute just a 0 (zero) or even a text message in the place of the empty double-quotes.Like this ...

    =IF(ISERROR(A1/B2),"Input Incomplete",A1/B2)

  • 8/14/2019 EXCEL Advanced Lessons - Collection 1

    12/43

    SUM or AVERAGE with Multiple Criteria

    Many Excel spreadsheet power-users are familiar with writing formulas that use theSUMIF worksheet function. What can you do when you need to get a set of values basedon multiple criteria?

    Prior to Excel 2007 there wasn't an easy solution. Now we have the SUMIFS ,COUNTIFS , and AVERAGEIFS worksheet functions.

    Anyone who hasn't upgraded will need to be more resourceful. Also, at times you mayneed a formula that is a little more robust than these new functions by themselves. So,let's see how you can apply some of the most powerful tools offered in Excel ... ARRAYFORMULAS .

    In the first three columns of this worksheet, we have a DATE field, a field with anACCOUNT number and a field with a dollar AMOUNT.

    In this problem, we'll want to write a formula to get the SUM from the AMT field of allrecords between our FROM DATE ( in cell E2 ) and the TO DATE ( in cell F2 ) ~and~

    belonging to the ACCOUNT criteria ( in cell G2 ).

    For this demonstration, we'll start by writing a formula in H2 as follows:=SUM((A2:A19>=E2)*(A2:A19

  • 8/14/2019 EXCEL Advanced Lessons - Collection 1

    13/43

    array formula.

    Here's how this array formula works -

    It evaluates each of the conditions as either TRUE or FALSE . A match on the criteria =

    1 and anything else returns a 0 ( zero ). So, record that matches all the criteria, theevaluation of every individual record to something like this ...=1 * 1 * 1 * AMOUNT Field Value

    ... then the array formula gets the SUM of what is returned for all the records.

    If the record didn't match then it will have one or more of the criteria evaluating to a zero.Like so ...

    =1 * 1 * 0 * AMOUNT Field Value

    ... and, because the failure of a match on one of the criteria causes this record to bemultiplied by zero, the resulting amount for that record to contribute to the sum of all therecords is also zero.

    We can make the original formula more understandable by using named ranges, asfollows:

    RANGE NAME REFERS TOrngDate A2:A19rngAcct B2:B19rngAmt C2:C19rngFromDate E2

    rngToDate F2rngAcctCriteria G2

    So, now we can write the formula this way:

    =SUM((rngDate>=rngFromDate)*(rngDate

  • 8/14/2019 EXCEL Advanced Lessons - Collection 1

    14/43

    and the TO DATE, and the ACCOUNT number all match our criteria, then include theAMOUNT in the array of values to be averaged.

    Otherwise, if any field in a record fails to meet one of our criteria, then the amount for that record will simply be ignored. FYI, the 3rd argument in an IF worksheet function is

    optional - it simply defaults to a FALSE if omitted.

    One thing to be aware of when using this formula is that the AVERAGE worksheetfunction will return a #DIV/0 error if there are not any records that satisfy your criteria.The work around is to write a longer formula that traps the error and returns either a 0(zero) or "" (empty quotes) if there are no records matching the criteria. Click here for anarticle describing how to use the ISERROR function to suppress #DIV/0 errors.

    These are only a couple of the many powerful applications of array formulas . Arrayformulas are among the most useful yet untapped features available in Excel's toolbox.

    With the example we've shown here you can create versatile reports against tables of changing data.

    How to Use the CHOOSE Function

    http://www.beyondtechnology.com/tips005.shtmlhttp://www.beyondtechnology.com/tips005.shtmlhttp://www.beyondtechnology.com/tips005.shtml
  • 8/14/2019 EXCEL Advanced Lessons - Collection 1

    15/43

    The CHOOSE function gives you a value from an array of up to 29 values. All you needto do is specify the index of the value you want it to return. For example ...

    =CHOOSE(2,"Schlumberger","Chevron","Shell","Bechtel","ExxonMobil")

    The first argument supplied is the index specifying which item to return from the listedvalues. In this instance, we provided a number 2. Therefore, the CHOOSE functionreturns "Chevron", the second item in the list of value arguments.

    Ranking Values

  • 8/14/2019 EXCEL Advanced Lessons - Collection 1

    16/43

    Some of the various techniques for ranking values include using the LARGE, SMALL,and RANK worksheet functions.

    Now, let's see how we might apply these functions:

    LARGE Worksheet Function

    The LARGE Worksheet function returns values from a list in rank order from the greatestto the least value (descending). While it seems like this task should be quitestraightforward, the LARGE function becomes especially useful whenever there aremultiple items in the list tied for a rank.

    There are two required arguments. The first is the address of the range of values to beevaluated -- that is, the list. The second argument is the position of the value to bereturned. For instance, 1 returns the highest value, 2 returns the second highest value inthe list, and so on.

    Whenever multiple items in the list are tied for a position, each will be counted as aseparate item within the ranking.

    Let's see how it works.=LARGE(A2:A7,5)

    Using our sample spreadsheet above, the range to be evaluated in all the examples willencompass cells A2:A7 . The second argument in our example is the number 5, meaningwe want to know the value of the number that is in the fifth largest position.

    The result happens to also be 5. The largest number was 12, then 9, and 8 is repeatedtwice -- so, the fifth number occuring is the value of 5.

    SMALL Worksheet Function

    The SMALL Worksheet function works the same way as the LARGE function, except inascending order.

    =SMALL(A2:A7,4)

    In this example, the formula returns a value of 8. It starts looking at the smallest number

  • 8/14/2019 EXCEL Advanced Lessons - Collection 1

    17/43

    in the list, being 4. In position #2 is the value 5. Since 8 is repeated in our range, itoccupies positions #3 and #4 -- therefore, the making the answer to be 8.

    RANK Worksheet Function

    The RANK Worksheet function is much like the former two functions, except:

    ... it returns the position number of a specified value in the list;

    - and -

    ... it counts multiple instances of a value in a list as separate but equal items in theranking.

    The RANK function has three arguments - the first two are required. The first argument

    is the criteria value. This is the value for which you want to know it's position within thelist. The second argument, is the range to be evaluated -- the list, itself.

    The third argument tells Excel whether to evaluate the list in descending order or ascending order. A value of 0 (zero), or omitting the argument, ranks the list by defaultfrom greatest to least. Using a 1 as the third argument indicates that the items in the listshould be evaluated in ascending order.

    Here is an example:=RANK(9,A2:A7,1)

    This formula returns a value of 5. It gives the position of the number 9 within the list,ranked from the smallest to the largest value.

    Since the number 8 appears twice in our list, it is counted as position #3, and position #4will be skipped.

    Here is another example demonstrating this, except in decending order:=RANK(8,A2:A7)

    In this case we want to know the position of the number 8 from the largest number in thelist. In this final example, the answer is 3. Position #1 is occupied by the number 12, then9 is in position #2 -- therefore, the number 8 returns a 3.

    Comparing Lists

  • 8/14/2019 EXCEL Advanced Lessons - Collection 1

    18/43

    Have you ever had two lists to compare using Excel? Here is one technique you can usethat requires neither VBA nor array formulas - just a few straightforward worksheetfunctions.

    In this example we will assume that you have a MASTER LIST of cities (column A).Then you will have a second list of cities (column C ) to compare to the MASTER LIST.We want to know which items in the second list are NEW cities and which ones alreadyexist in the MASTER LIST. We will do this using formulas in column D where theresults will displayed.

    This is accomplished by using a combination of the VLOOKUP and ISNA worksheetfunctions. We have entered the following formula in cell D2 ...

    =ISNA(VLOOKUP(C2,A:A,1,FALSE)) Next, we copied this formula down through the last row in the column adjacent to the listof possible NEW items. Let's break this down to see what this is doing.

    VLOOKUP(C2,A:A,1,FALSE)First, we're using the VLOOKUP function to try to find each individual item from thesecond list (column C ) anywhere within the MASTER LIST. In other words, this part of the formula says ...

    look at the list in column A and determine if there's a match on the entry in cell C2 .

    If a city was not found in the MASTER list, then the VLOOKUP returns a #N/A error.That's okay though, because the next part of our formula looks at whether or not we gotthis error. To do this, we have nested the VLOOKUP in an ISNA function.

    ISNA(VLOOKUP(C2,A:A,1,FALSE))The ISNA function will return either a TRUE or FALSE . This part of the formulasays ...

    if the VLOOKUP function returns a #N/A error then it's TRUE , otherwise it tested FALSE for the #N/A error.

  • 8/14/2019 EXCEL Advanced Lessons - Collection 1

    19/43

    So, whenever the formula returns a TRUE , it means that item from the second list is NEW - it does not exist already in the MASTER LIST. Likewise, if the result in columnD is a FALSE , it means this item was already included in your MASTER LIST.

    List - Counting Unique Items

  • 8/14/2019 EXCEL Advanced Lessons - Collection 1

    20/43

    For this example, we'll use a table containing street addresses and the subdivisions(neighborhoods) in which they belong.

    Our objective is to get a count of the unique neighborhoods in the list.

    For this demonstration, we'll write a formula as follows :

    =SUM(1/COUNTIF(B2:B10,B2:B10))

    Now [ IMPORTANT before you hit the enter key] , you will need to use Ctrl + Shift +Enter instead. This creates an ARRAY FORMULA , recognizable by the curly brackets" { } " that automatically appear around it. You never type these curly brackets whenentering an array formula.

    Here's how this array formula works -

    The COUNTIF function returns an array with the count of each unique element. In our example, it looks like this :

    {2,3,4,2,4,3,4,3,4}Try to follow this. Wimbledon Forest (B2) is the first item in the list, and there are 2occurances of it, therefore the first element in our COUNTIF array is 2.

    The second item in the list is Oakwood West (B3), and there are 3 instances of itself counted in the whole list, therefore a 3 is returned as the second element in the array.

    The third item in the list is Shannon Forest (B4). The count of 4 instances of itself is

    returned as the third element in the COUNTIF array.Our function does this for every cell in its source range B2:B10 . There are 9 cells in therange - note, there are 9 elements in our COUNTIF array.

    Next, the elements in our COUNTIF array are each divided into 1, resulting in an array of fractions.

    {1/2, 1/3, 1/4, 1/2, 1/4, 1/3, 1/4, 1/3, 1/4}

  • 8/14/2019 EXCEL Advanced Lessons - Collection 1

    21/43

    Finally, our formula takes the sum of these fractions. There are two occurances of 1/2,three instances of 1/3, and four instances of 1/4.

    (1/2 + 1/2) = 1(1/3 + 1/3 + 1/3) = 1

    (1/4 + 1/4 + 1/4 + 1/4) = 1___________________________________________

    NUMBER OF UNIQUE ITEMS = 3This may require a couple of readings to understand how the formula works.

    Try it. There's a lot of power in this little formula, and it will return a correct count of unique items.

    Preventing Duplicate Entry

  • 8/14/2019 EXCEL Advanced Lessons - Collection 1

    22/43

    Here is a technique to prevent duplicate entries within a range ( which is easy to do if you're entering, let's say, invoice numbers ).

    Suppose you want to prevent duplicate entries in the range A1:A10 :

    1. Select cell A1 and choose the Validation command from the Data menu.

    2. Click the Data Validation dialog's Settings tab.

    3. In the Allow dropdown list, select Custom .

    4. In the Formula box, type:.

    5. =NOT(OR(COUNTIF($A$1:$A$10,A1)>1))

  • 8/14/2019 EXCEL Advanced Lessons - Collection 1

    23/43

    6. Now you'll need to set an alert style. Click the Error Alert tab.

    7. Set the Style dropdown to Stop (the alert message with a 'Stop' sign on it ).

    8. In the Title box, type what you want to appear in the Error Alert's title bar (for example, " Duplicate Entry ").

    9. In the Error message box, type the your text (for example, " This value alreadyexists in the list ").

  • 8/14/2019 EXCEL Advanced Lessons - Collection 1

    24/43

    10. Click OK .

    11. Finally, back in the worksheet, copy cell A1 down through A10 .

    Now, you can test it by making an entry in a cell within A1:A10 , then try to duplicatethat entry in any other cell within the same range.

  • 8/14/2019 EXCEL Advanced Lessons - Collection 1

    25/43

    Understanding NPV( Net Present Value )

    Net present value takes into account the time value of money. All projected after-taxcash flow from a proposed investment are discounted to their present values using aminimum acceptable rate of return.

    User Inputs

    Discount Rate

    An important issue in forecasting the time value of money in budgetingdecisions is establishing the appropriate discount rate to use for calculatingthe present value of cash flows.

    We'll need to determine some minimum acceptable rate of return on themoney invested. This target rate to use as the basis for present valuecalculations may be at or above the cost of capital.

    This is entered in cell B1 of the example below. We need to see a 12%minimum rate of return to consider this investment acceptable.

    Initial Investment

    Since our initial investment occurs immediately, it does not need to bediscounted.

    Our net present value in this case will be calculated as the sum of thediscounted net cash flows minus the initial investment.

    In our example, assume we are considering an investment having a$20,000 initial cost, entered in cell B10 .

    Cash Flow

    For the purpose of simplicity, the analysis in this example will be based onannual after-tax cash flow.

    In practice, our cash flow will often be measured in shorter increments,such as months and quarters.

  • 8/14/2019 EXCEL Advanced Lessons - Collection 1

    26/43

    In Row 4 of our example below, we'll project net cash flows after taxesover the next four years to be $ 4,800 , $7,200 , $9,600 , and $ 10,800respectively.

    Understanding Net Present Value"the Old Fashioned Way"

    In general, our investment is acceptable if it has a positive net present value. We'llsee this in cell B10 , the net present value returned when we calculate it all out is$3,722 .

    Since the sum of the discounted net cash flows, $ 23,722 ( in cell B8 ), is greater than the initial cost of $ 20,000 ( in cell B9 ), the investment is acceptable in thisanalysis.

    If subtracting the initial cost from the sum of the discounted net cash flows turnedout to be a negative value, then the return on investment would not have beenadequate to satisfy our minimum acceptable rate of return.

    Let's have a look at the formulas:

  • 8/14/2019 EXCEL Advanced Lessons - Collection 1

    27/43

    Looking back at the first illustration, notice that the values in Row 5 range from .89 at the end of the first year, to .64 at the end of the fourth year.

    This represents the value of a dollar we have today at the end of each projectedyear.

    The syntax for the calculations in Row 5 are:

    1 / (1 + Discount Rate ) ^ Year Number

    The ^ (caret) is the exponentiation operator.

    The Discounted Cash Flow is the result of multiplying Row 4 (net cash flow ) byRow 5.

    The NPV FunctionExcel provides a NPV (net present value ) function to perform the discounting

    process with a single formula.

    The following formula has been entered in cell E10 and demonstrates that theNPV function can be applied to return the same value as the result in cell B10from the long calculation method.

    =NPV(B1,B4:E4)-B9

    The Excel NPV function has an assumption that the first cash flow must occur atthe end of one period.

    Therefore, we subtract the initial investment to get a net present value.

    Here's the syntax for the formula:

    =NPV( DiscountRate , CashFlow ) - InitialInvestment

    Something to Think About :

  • 8/14/2019 EXCEL Advanced Lessons - Collection 1

    28/43

    Net present value can also be used to help select from competing investmentalternatives.

    When this method is used for screening alternative investments, a higher net present value is sometimes considered a positive indicator.

  • 8/14/2019 EXCEL Advanced Lessons - Collection 1

    29/43

    Referencing Most Recent Entry in a List

    Let's say you have an ongoing chronological list with values that is periodically updated by making a new entry at the bottom of the list. It may be useful to have a formula thatalways references whatever the last entry to the list would be. If we want to know whatthe last item in column A is, the basic formula will be:

    =INDEX(A:A,COUNTA(A:A),1)

    Now, let's see how we might apply this:

    In this example we want cell D3 to always show the sum of the Unit Price entries for themost recent day as they have been added to the bottom of the list. Therefore, the formulain D3 can either be:

    =INDEX(B:B,COUNTA(B:B),1)+INDEX(C:C,COUNTA(C:C),1)- or -

    =INDEX(B:B,COUNTA(A:A),1)+INDEX(C:C,COUNTA(A:A),1)The difference between these two formulas is that the first will add the last entry in eachcolumn, regardless of the date field (column A). On the other hand, the second formulareturns the sum of the last date entry in column A, regardless of whether thecorresponding values have been provided in columns B and C for that row.

    How It Works:

    This technique works by combining the INDEX and COUNTA worksheet functions.

    The INDEX function uses at least three arguments. The first is the range in which youwill look for the values. In this case, we are looking for values in a range encompassingone entire column.

    The other two arguments for the INDEX function are essentially X and Y coordinates(row and column numbers for us non-mathematicians) within the range you justspecified.

    The second argument, the row number, will be determined by the COUNTA function.The third argument will be 1 in this case since there is only a single-column range beingevaluated. If the range spanned more than one column, then you could specify an integer value for which column to return a value from.

  • 8/14/2019 EXCEL Advanced Lessons - Collection 1

    30/43

    Finally, COUNTA requires just a single argument -- a range. It counts the number of items in the range, excluding blank cells. Remember, that this will include the header rowalso.

  • 8/14/2019 EXCEL Advanced Lessons - Collection 1

    31/43

    YTD Formula- Using the OFFSET Function

    With a combination of the SUM, OFFSET , MONTH, and NOW functions, we can makea formula that sums only your year-to-date values, even if you enter projected estimatesto forecast the remainder of the year.

    Refer to this illustration, in which we have twelve months in contiguous columns and aYTD calculation at the end.

    If we assume that the current month is April, then we want to see the sum of the actualvalues in A:D (JAN through APR only -- 4 columns).

    Let's see what the YTD formula looks like in cell M2 . Then we can dissect this formulato understand how it works.

    =SUM(OFFSET(A2,0,0,1,MONTH(NOW())))

    First, the NOW function returns today's date. The advantage of this is that it's alwayscurrent, but you can substitute for the NOW function with the address to another cell

    containing a different date.MONTH( cell address )

    When you nest that in the MONTH function, Excel returns an integer value between 1and 12 representing the month.

    Next, we get to the real workhorse in this formula, the OFFSET function. We're usingthis to define the range to sum. Here's the syntax:

    OFFSET (reference ,rows ,cols ,height,width )

    Reference is our anchor cell. The other arguments will be relative to this cell'saddress (it's A2 in this example).

    Rows is the number of rows up or down from the anchor, to which you want theupper-left cell of the range to refer. We'll use zero because we want the range to

    begin at the same row as the anchor cell.

    Columns is the number of columns left or right from the anchor, to which youwant the upper-left cell of the range to refer. Again, we'll use zero because wewant the range to start from same column as the anchor cell.

  • 8/14/2019 EXCEL Advanced Lessons - Collection 1

    32/43

  • 8/14/2019 EXCEL Advanced Lessons - Collection 1

    33/43

    Calculating End of Month ~and~ Adding Whole Months

    Sometimes it's necessary to calculate with dates using the last day or some other specifiedday of the month - whether it's the current month, previous month, or some future month.A special EOMonth function is provided with Excel's Analysis ToolPak Add-In. The

    only problem with using this ready-made function is that it makes your project dependentupon a user having the Analysis ToolPak loaded.

    We'll look at some great ways to use ordinary worksheet formulas to add months and toreturn the end of any month. Let's begin by entering any date in cell A1 on a worksheet.In the next cell, A2 , enter the following formula:

    =DATE(YEAR(A1),MONTH(A1)+1,0)

    It will look something like this ...

    Basically, the DATE function uses three arguments - Year , Month , and Day .

    For example ...=DATE(2000,2,4)

    ... returns February 4, 2000.

    In this case, we have nested a YEAR function and a MONTH function that reference the

    original date from cell A1 .

    What is really interesting is that, when you provide a zero for the day , you can get the lastday of the prior month.

    =DATE(2000,3,0)

    By adding 1 to the month we can get the last day of the current month ( the 0th day of March ) as in the example above.

    This provides you with the means to programmatically determine how many days are ina month .

    Now, we can take this a step further and add a series of dates well into the future as onemay do in an amortization table or some similar schedule. In column A , enter a series of integers representing (next) months ... such as 2 through 25 in our example. Next, in B1enter the following formula ...

    =DATE(1998,A1,0)

  • 8/14/2019 EXCEL Advanced Lessons - Collection 1

    34/43

    ... then copy the formula down through row 24. The result is a series of dates startingwith the last day of January, 1998, through the last day of December, 1999.

    A huge advantage to this approach is that you never have to determine whether themonths have 28, 29, 30, or 31 days.

    Additionally, you may prefer to Copy and PasteSpecial Values, discarding the formulas,once you have generated your list of dates.

  • 8/14/2019 EXCEL Advanced Lessons - Collection 1

    35/43

    BackSolving for Daily % Gain or Loss- Financial formula to return a daily growth (or loss) rate of an investment.

    If we know an investment has grown x% between two dates, but do not have the daily

    detail, how can we arrive at an estimate of the average daily gains or losses?

    This example demonstrates the problem.

    If an investment has grown 4% over 4 days ( ... it's fun to pretend ), we cannot divide 4% by 4 and use 1% because there's a compounding effect that returns a 4.06040% gain

    when it's applied daily.

    What we need is a formula to return an estimated average of the percent gains or losses of .98534% applied daily to return 4% at the end of the 4 days.

    Here's the basic formula ...

    daily growth = ( 1 + % gain ) ^ ( 1 / # days ) - 1

  • 8/14/2019 EXCEL Advanced Lessons - Collection 1

    36/43

    With the percentage ( 4% or .04 ) in cell A1 and the number of days ( 4 ) in B1 , theformula looks like this ...

    =(A1+1)^(1/B1)-1

    Let's dissect this formula to understand how it works.

    ( 4% + 1 ) = 1.04

    ( 1 / 4 days ) = .25

    1.04 ^ .25 = 1.00985340654897

    The ^ (caret) is the exponentiation operator, therefore it's 1.04 to the .25th power.

    1.00985340654897 - 1 = .00985340654897 or 0.98534%

    This was the choice of several possible solutions for this problem,including the IRR and RATE functions.

    Viewing Formulas

  • 8/14/2019 EXCEL Advanced Lessons - Collection 1

    37/43

    Instead of going to the Tools menu, Options... menuitem, View tab, then checkingFormulas , to take a look at all your formulas at once, try Ctrl+` (apostrophe -- the keyshared with a tilde ~ to the left of the number 1 on your keyboard).

    Also, save yourself the trouble of repeating all the steps to get back to a normal view --

    just repeat the same shortcut key combination.

    Carriage Return - Inserting a Line Break in a CellHave you ever needed to control the line break when making long text entry into a cell?If you press the Enter key, as you would be accustomed to doing with a text editor, Exceltakes your command as the completion of your entry in the cell. So, to get things to fit,you find yourself adjusting your column width, row height, font size, etc.

    The fix is so easy! To force a line break, just use Alt + Enter and Excel will insert acarriage return so you can continue on the next line.

    I'm told, if you're using a Mac Option + Command + Return does the job.

    Hiding Unused Rows & ColumnsHiding rows and columns does not just have to be for concealing data or formulas. If your spreadsheet only uses a small area of the 16,777,216 available cells in an Excelworksheet, maybe it would be nice to hide some of that vast unused region to keep usersfrom scrolling off the edge of your working area.

    Here are the simple steps to accomplish this task:

    1. Select the row header just beneath the used area of your spreadsheet, where youwant to start hiding rows.

    2. Press Ctrl + Shift + Down Arrow . This will highlight everything from your selected row through the bottom of the worksheet.

    3. From the worksheet's Format menu, choose Row , then Hide .

    Follow the same basic steps to hide columns. The difference will be that you should

    begin by selecting a column header in the first empty column to the right of your usedarea, then press Ctrl + Shift + Right Arrow .

    Finally, from the worksheet's Format menu, choose Column , then Hide .

    Adding Time Values

  • 8/14/2019 EXCEL Advanced Lessons - Collection 1

    38/43

    Let's say you need to add all the hours required to complete a project, or maybe the sumof all the hours your staff has worked. A problem arises in displaying time valuesexceeding twenty-four hours. The key to adding time values is to use a custom number format.

    From the worksheet's Format menu, choose Cells... . Then go to the Number tab, selectthe Custom category, and enter the following as your custom format type:

    [h]:mm Notice that the number format code for hours is in brackets. This tells Excel that youintend to possibly exceed twenty-four hours, therefore it will handle your time valuesaccordingly.

    Formula to Display Dates as Quarters

  • 8/14/2019 EXCEL Advanced Lessons - Collection 1

    39/43

    Without requiring any VBA, here's a neat worksheet technique that returns the quarter corresponding to a given date.

    Without requiring any VBA, here's a neat worksheet technique that returns the quarter corresponding to a given date.

    =INT((MONTH(A1)+2)/3)

    For the purpose of this demonstration, let's say the date entered in cell A1 current monthis 28-Aug-2001 . Our formula should return a 3 -- as being in the 3rd Quarter of the year.

    Let's dissect this formula to understand how it works.

    First, the obvious -- MONTH(A1), where the date in A1 is 28-Aug-2001 , returnsa value of 8.

    8 + 2 = 10 ... add 2 months

    10/3 = 3.333333 ... Why divide by 3 ? ... because there's 3 months in a quarter.

    INT(3.333333) = 3 ... since the INT function rounds down to the nearest integer -- and that gives us our answer!

    What about Fiscal Years ?

    Let's say your organization's fiscal year begins on October 1 and ends September 30. Wecan create a custom variation of this formula to do the job.

    =INT((MONTH(A1) + IF(MONTH(A1)>9,-7,5))/3)

    This differs from the calendar year formula with the inclusion of an IF function.

    + IF(MONTH(A1)>9,-7,5)

    If the date being evaluated is OCT through DEC ( therefore the month is >9 ) then insteadof adding 2 months, as we did in step 2 of the calendar year example, we'll subtract anadditional 9 months; so, -7 .

    If the month of the date being evaluated is JAN through SEP, then instead if adding the 2

    months, we'll adjust that by 5 additional months; so, +5 .

    IsError Function

  • 8/14/2019 EXCEL Advanced Lessons - Collection 1

    40/43

    Applying the ISERROR function in your fomulas to suppress #DIV/0! errors.Sometimes it is necessary to include formulas in a worksheet that will require the sheet to

    be completed by a user before they will display a correct result. In this case, you couldhave error values throughout the spreadsheet until you get all the necessary input. Themost common workaround to suppress #DIV/0! and other errors from is to apply theISERROR function in your formulas. Something like so ...

    =IF(ISERROR(A1/B2),"",A1/B2)

    This would say if cell A1 divided by B2 caused an error, then make the value in the cellequal to nothing -- otherwise (ELSE), make it whatever A1 divided by B2 really should

    be. This is a good way of handling 'can't divide by zero' and similar errors. You can alsosubstitute just a 0 (zero) or even a text message in the place of the empty double-quotes.Like this ...=IF(ISERROR(A1/B2),"Input Incomplete",A1/B2)

    Change Stored Value to Display Value

  • 8/14/2019 EXCEL Advanced Lessons - Collection 1

    41/43

    Forcing a worksheet's underlying values always be exactly the same as they are displayed. The number displayed in a cell may be different from the underlying number because of the formatting you have applied to the cell. For instance, 3.99 and 3.9854765 are not thesame, but they will both be displayed as 3.99 if you have the cells number formatting setto show two decimal places. There is a way of making the underlying values always beexactly as they appear.

    From the Office Button in the upper left corner of the Excel application window, click on the Excel Options button at the bottom of the dropdown menu.

    Scroll to the Advanced options then down to the Set precision as displayed checkbox. Note the warning message that appears when this is checked.

  • 8/14/2019 EXCEL Advanced Lessons - Collection 1

    42/43

    You should be aware that this technique can diminish the accuracy of some spreadsheets,therefore it probably will NOT be desirable in many instances.

    Before Excel 2007 ~ the Old Fashioned Way

    From the worksheet's Tools menu, choose Options... . Then go to the Calculation tab,and check the item labelled Precision as displayed

    Copy-and-Paste Chart Editing A simple, but time-saving technique to add new data to charts.

    The chart below has average temperatures by month for Houston and Dallas.

    We want to add the temperatures in column D for Oklahoma City to the chart.

  • 8/14/2019 EXCEL Advanced Lessons - Collection 1

    43/43

    Copy the range D1:D13 containing a new series of data to be added our existing chart.

    Select the chart and simply paste the new values onto the chart and Excel will redraw it toinclude the new data.