You are on page 1of 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 that
range.

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

1. Select the range that is to contain the validation dropdown listbox. This may be
either 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 them
directly.

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.
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 the
same worksheet that has the source list of possible entries.

If a user tries to manually enter anything other than these values, a stop message appears
and 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 cell
to which this validation setting has been applied; a user is not required to actually select
these values from the list.

Some Possible "Gotchas"


• Validation does not look at what is already in the cell.

• It is not case sensitive: WED, Wed, or wed, are all treated the same.

• It does not look at entries made through VBA procedures.

• If users copy or autofill data in restricted cells, error messages don't appear, and
incorrect data may be placed in the cells.

If a range is pasted over this way, it's validation properties are removed.

Locking the range and protecting the worksheet help prevent this problem.

• An error will occur when selecting a validation dropdown if all of the following
conditions are present:

o the cell containing the validation dropdown is locked;

o the worksheet is protected;

o the source values for the validation dropdown is a direct list.

... Possible workarounds are:

o unlock the range containing the validation dropdown list

o set the validation dropdown list to refer to a range for its source values,
instead of a direct list.

It helps as much as anything is to employ this feature in ways where the user is apt to
enter data directly. Properly applied, validation dropdown lists can be used to enable ease
and consistancy of data entry.
Multiple Criteria Text Look-Up

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

There are various options available for the task. Filtering could be the quick and easy
way. 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 most
appropriate 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 a
formula to return an e-mail address from the table, based on a combination of the
Company 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 the
other for the Name field. Dynamic Named Ranges would be ideal, but for the sake of a
simple illustration we'll create a couple of conventional named ranges.

From the worksheet's Insert menu choose Names then the Define... command. Enter a
name 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 when
entering an array formula.

Here's how this works -

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

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

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

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

We needed to get the MATCH function to treat the Company and Name fields
as though they are just one field. We've done so by concatenating the named
ranges - 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 row
number 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 criteria
ranges.

Finally, we can improve this formula by accomodating the possibility that there is no
match in the lookup table. This formula is really one line, but it's shown as wrapped onto
a 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 when
concatenated.

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, the
array formula in range G2 could be:
=INDEX(C:C,MATCH(1,(E2=rngCompany)*(F2=rngName),0))
Conditional Sum
Excel'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 the
entire 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 sum
range 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 the
value of the fifteenth item in the sum range will be included in the total returned by the
formula.
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 through
how 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 this
table. 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 example
you 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 evaluating
A2: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 that
correspond to the items labelled as "blue" in A2:A8.

Here is the key to understanding the AVERAGEIF function (or, for that matter, the
SUMIFIF and COUNTIF functions we'll see below). The items to be included in the
calculation 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 the
value corresponding to the seventh item will be included in the formula's calculation.
Before Excel 2007 ~ the old fashioned way

As with the preceding example, so that you can avoid the need to hard code the criteria in
your formula, you 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 ...
=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're
evaluating the range containing the names of the colors in column A. In other words, this
formula says ...
look at the list in column A and if there's a match on the entry in cell C2 then
include 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're
evaluating the range containing the names of the colors in column A. So this part of the
formula says ...
look at the list in column A and if there's a match on the entry in cell C2 then
count 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 by
the 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 a
conditional average.
{=AVERAGE(IF(Colors=Criteria,Prices))}
Remember, you don't type the curly brackets {} and hold down the CTRL key and
SHIFT key when entering your array formula. So, after you type the formula in the
formula 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 the
PRICE 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 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 worksheet
function 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)))}
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 could
have error values throughout the spreadsheet until you get all the necessary input. The
most common workaround to suppress #DIV/0! and other errors from is to apply the
ISERROR 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 cell
equal 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 also
substitute 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)
SUM or AVERAGE with Multiple Criteria

Many Excel spreadsheet power-users are familiar with writing formulas that use the
SUMIF worksheet function. What can you do when you need to get a set of values based
on 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 may
need 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 ... ARRAY
FORMULAS.

In the first three columns of this worksheet, we have a DATE field, a field with an
ACCOUNT 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 all
records 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<=F2)*(B2:B19=G2)*C2:C19)

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 when entering an
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, the
evaluation 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 be
multiplied by zero, the resulting amount for that record to contribute to the sum of all the
records is also zero.

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

RANGE NAME REFERS TO


rngDate A2:A19
rngAcct B2:B19
rngAmt C2:C19
rngFromDate E2
rngToDate F2
rngAcctCriteria G2

So, now we can write the formula this way:


=SUM((rngDate>=rngFromDate)*(rngDate<=rngToDate)
*(rngAcct=rngAcctCriteria)*rngAmt)

Now, using an array formula, let's use the same set of data and discover how to do an
AVERAGE with multiple criteria:
=AVERAGE(IF(rngDate>=rngFromDate,IF(rngDate<=rngToDate,
IF(rngAcct=rngAcctCriteria,rngAmt))))

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

In this case we're nesting IF worksheet functions. So, we're saying if the FROM DATE,
and the TO DATE, and the ACCOUNT number all match our criteria, then include the
AMOUNT 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 worksheet
function 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 an
article 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. Array
formulas 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


The CHOOSE function gives you a value from an array of up to 29 values. All you need
to 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 listed
values. In this instance, we provided a number 2. Therefore, the CHOOSE function
returns "Chevron", the second item in the list of value arguments.

Ranking Values
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 greatest
to the least value (descending). While it seems like this task should be quite
straightforward, the LARGE function becomes especially useful whenever there are
multiple items in the list tied for a rank.

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

Whenever multiple items in the list are tied for a position, each will be counted as a
separate 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 will
encompass cells A2:A7. The second argument in our example is the number 5, meaning
we 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 repeated
twice -- 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 in
ascending order.
=SMALL(A2:A7,4)

In this example, the formula returns a value of 8. It starts looking at the smallest number
in the list, being 4. In position #2 is the value 5. Since 8 is repeated in our range, it
occupies 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 the
ranking.

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 the
list. 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 default
from greatest to least. Using a 1 as the third argument indicates that the items in the list
should 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 #4
will 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 the
list. In this final example, the answer is 3. Position #1 is occupied by the number 12, then
9 is in position #2 -- therefore, the number 8 returns a 3.

Comparing Lists
Have you ever had two lists to compare using Excel? Here is one technique you can use
that requires neither VBA nor array formulas - just a few straightforward worksheet
functions.

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 already
exist in the MASTER LIST. We will do this using formulas in column D where the
results will displayed.

This is accomplished by using a combination of the VLOOKUP and ISNA worksheet


functions. 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 list
of 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 the
second 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 got
this 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 formula
says ...
if the VLOOKUP function returns a #N/A error then it's TRUE, otherwise it
tested FALSE for the #N/A error.
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 column
D is a FALSE, it means this item was already included in your MASTER LIST.

List - Counting Unique Items


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 when
entering 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 2
occurances 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 the
range - 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}
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 = 3


This 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


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))
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 already
exists in the list").
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 duplicate
that entry in any other cell within the same range.
Understanding NPV
( Net Present Value )

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

User Inputs

• Discount Rate

An important issue in forecasting the time value of money in budgeting


decisions is establishing the appropriate discount rate to use for calculating
the present value of cash flows.

We'll need to determine some minimum acceptable rate of return on the


money invested. This target rate to use as the basis for present value
calculations 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 be


discounted.

Our net present value in this case will be calculated as the sum of the
discounted 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 on
annual after-tax cash flow.

In practice, our cash flow will often be measured in shorter increments,


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

Understanding Net Present Value


"the Old Fashioned Way"

In general, our investment is acceptable if it has a positive net present value. We'll
see 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 this
analysis.

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

Let's have a look at the formulas:


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 projected
year.

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) by
Row 5.

The NPV Function


Excel 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 the
NPV function can be applied to return the same value as the result in cell B10
from the long calculation method.
=NPV(B1,B4:E4)-B9

The Excel NPV function has an assumption that the first cash flow must occur at
the 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 :


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

When this method is used for screening alternative investments, a higher net
present value is sometimes considered a positive indicator.
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 that
always references whatever the last entry to the list would be. If we want to know what
the 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 the
most recent day as they have been added to the bottom of the list. Therefore, the formula
in 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 each
column, regardless of the date field (column A). On the other hand, the second formula
returns the sum of the last date entry in column A, regardless of whether the
corresponding 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 you
will look for the values. In this case, we are looking for values in a range encompassing
one 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 just
specified.

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 being
evaluated. If the range spanned more than one column, then you could specify an integer
value for which column to return a value from.
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 row
also.
YTD Formula
- Using the OFFSET Function

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

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

If we assume that the current month is April, then we want to see the sum of the actual
values 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 formula
to 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 always
current, 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 1
and 12 representing the month.

Next, we get to the real workhorse in this formula, the OFFSET function. We're using
this 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's
address (it's A2 in this example).

• Rows is the number of rows up or down from the anchor, to which you want the
upper-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 you
want the upper-left cell of the range to refer. Again, we'll use zero because we
want the range to start from same column as the anchor cell.
• Height is a positive number telling Excel a count of how many rows are to be in
the vertical dimension of the range. Here, we just want the range to be 1 row high.

• Width is a positive number for how many columns are to be in the horizontal
dimension of the range. This is where we're letting the MONTH function
determine how many columns should be included.

Since (for the purposes of this demonstration) we said the current month is April, the
MONTH function gives us a 4 as the width parameter in the OFFSET function defining
our range to sum.

The reference for the final SUM then is A2:D2, returning a value of 19 in the example.
This is useful, because it enables you to enter numbers in future months without effecting
your YTD calculation and without needing to change your YTD formula at anytime as
the year progresses.

What about Fiscal Years ?

Let's say your organization's fiscal year begins on October 1 and ends September 30. We
can create a custom variation of this formula to do the job.
=SUM(OFFSET(A2,0,0,1,MONTH(NOW()) + IF(MONTH(NOW())>9,-9,3)))
Let's assume again that the current month is April, then we'll need to have the sum of the
values in A:G (SEP through APR), being 34 in this example.

This differs from the calendar year formula with the inclusion of an IF function.
+ IF(MONTH(NOW())>9,-9,3)
If the current month is OCT through DEC ( therefore >9 ) then 9 is subtracted from the
value of the OFFSET range width argument. If the current month is JAN through SEP
then 3 is added to it.
Calculating End of Month ~and~ Adding Whole Months
Sometimes it's necessary to calculate with dates using the last day or some other specified
day 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 dependent
upon a user having the Analysis ToolPak loaded.

We'll look at some great ways to use ordinary worksheet formulas to add months and to
return 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 last
day 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 in
a month.

Now, we can take this a step further and add a series of dates well into the future as one
may 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 B1
enter the following formula ...
=DATE(1998,A1,0)
... then copy the formula down through row 24. The result is a series of dates starting
with 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 the
months 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.
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


With the percentage ( 4% or .04 ) in cell A1 and the number of days ( 4 ) in B1, the
formula 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
Instead of going to the Tools menu, Options... menuitem, View tab, then checking
Formulas, to take a look at all your formulas at once, try Ctrl+` (apostrophe -- the key
shared 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 Cell


Have 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, Excel
takes 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 a
carriage 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 & Columns


Hiding 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 Excel
worksheet, maybe it would be nice to hide some of that vast unused region to keep users
from 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 you
want 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 used
area, then press Ctrl + Shift + Right Arrow.

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

Adding Time Values


Let's say you need to add all the hours required to complete a project, or maybe the sum
of all the hours your staff has worked. A problem arises in displaying time values
exceeding 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, select
the 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 you
intend to possibly exceed twenty-four hours, therefore it will handle your time values
accordingly.

Formula to Display Dates as Quarters


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 month
is 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, returns


a 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. We
can 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 instead
of adding 2 months, as we did in step 2 of the calendar year example, we'll subtract an
additional 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
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 could
have error values throughout the spreadsheet until you get all the necessary input. The
most common workaround to suppress #DIV/0! and other errors from is to apply the
ISERROR 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 cell
equal 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 also
substitute 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


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 the
same, but they will both be displayed as 3.99 if you have the cells number formatting set
to show two decimal places. There is a way of making the underlying values always be
exactly 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.
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.
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 to
include the new data.

You might also like