Вы находитесь на странице: 1из 50

Checking for Messages in Cells

Blair has a worksheet divided into two areas: data entry and data verification. The data verification area consists of formulas that check entries using IF statements. If a problem is located, a text message is displayed in a cell in the verification area, otherwise the formula returns a blank. The following is a typical verification formula: =IF(A1<>5,"Value in A1 is not 5") The problem is that the data verification area can be uite large, which means it is easy to miss one of the text messages. Blair wondered if there was a way to create a formula that examined the data verification area and returned a single message if there were any other messages in the area. There are a number of different ways that this problem can be approached. If the data verification area is contiguous, then a simple array formula will do the trick. !nter the following in any empty cell on the worksheet: =SUM((LEN(ValRange)> )!1) "ake sure that #al$ange is replaced with the range of cells in the data validation area. %lso, make sure you enter the formula by pressing Shift+Ctrl+Enter &to denote it is an array formula'. The formula returns a value that indicates how many cells in the range have a length that is greater than (. In other words, it counts the number of cells that have messages visible. If you prefer to not use an array formula, you can accomplish the same result by using the following regular formula: =SUM"R#$U%&((LEN(ValRange)> )!1) The result, again, is the number of cells that have a length greater than (. %nother approach is to use some of the )*+,T functions provided by !xcel: =%#UN&A(ValRange) ' %#UN&(LAN)(ValRange) This formula counts the number of cells in the range, and then subtracts the number of blank cells in the range. The result is the number of cells that are non-blank, or those that are displaying messages. % different formulaic approach can be used to determine a simple yes.no response: =IF(%#UN&IF(ValRange,"*!"),"","No ") + "Ve,i-i.ation Messages" If there are no messages in the #al$ange, the formula returns /,o #erification "essages./ If there are messages, it strips the /,o/ and simply returns /#erification "essages./ It would also be a good idea to apply conditional formatting to your data verification area. 0hile the formulas discussed so far will tell you if there are messages, it won1t highlight where those messages are--conditional formatting can pinpoint each message. 2elect all the cells in the area that contain formulas, and then use conditional formatting to check the length of those cells. If the length is greater than (, the cell could be formatted to show a red background. This will make any messages in the data verification area much harder to miss when scrolling through the worksheet. If you are in the mood to completely redesign your worksheet, a more powerful approach would be to do away with the data verification area. 3ou can achieve the same results &checking what is in the data entry area' by using data validation for each of the entry cells. 2et up properly, data validation would make sure that the user entered acceptable values into each cell, removing the need for much of the data validation area.

Comparing Lists for Duplicates Imagine for a moment that you have a worksheet that contains lists of part numbers. On one worksheet you have a list of part numbers, and on another worksheet you have a similar list. The lists are not identical, however, and you want to determine if a particular part number on one list also appears on the other.

One solution is to somehow combine the lists, but add some sort of indicator as to which original list the particular part number came from. This approach (or a variation thereon) is, in fact, the approach taken by many E cel users. !hat if you don"t want to combine the lists, however# In this case, there is a very easy way to do the comparison. $ollow these steps% &. 'ake sure there is a blank column (ust to the right of each list of part numbers on each worksheet. ). *elect the part numbers on the first worksheet and give them a name such as +,art-ist&+. (.se Insert / 0ame / 1efine to assign the name to the list.) 2. *elect the part numbers on the second worksheet and give them a name such as +,art-ist)+. 3. 4ssuming that the first part number on the first worksheet is in cell 4), enter the following formula in cell 5)%
=ISNUM(ER(MA&%/(A0,"a,tList0, ))

&. 6opy the formula down so that a copy appears to the right of each part number on the first worksheet. ). 7epeat steps 3 and 8 on the second worksheet, but use the following formula%
=ISNUM(ER(MA&%/(A0,"a,tList1, ))

!hen you are done, either T7.E or $4-*E will appear to the right of each part number on each worksheet. If T7.E appears, the associated part number appears on the other worksheet. If $4-*E appears, then the part number is uni9ue and does not appear on the other worksheet. 4nother approach is to use an array formula to do the comparisons. :ou could follow the same steps shown above, but use the following formula in step 3 (and ,art-ist& variation in step ;)%
=#R(E1A%&(A0,"a,tList0))

*ince this is an array formula, you would enter it by using Shift+Ctrl+Enter. The result is the same T7.E and $4-*E designation described above. 7egardless of which formula approach you use, you can use the 4uto$ilter capabilities of E cel to limit what is shown on either worksheet. If you filter to show only the $4-*Es, you will have a list of all uni9ue part numbers. If you filter to show T7.Es, then you will have a list of duplicates.

Comparing Workbooks <rishna <umari asked if there was a way to compare the contents of two E cel workbooks. .nfortunately, there is no built=in comparison feature, as there is in !ord to compare two documents. There are third=party programs available that can help you out, and a 9uick search of the !eb can help to locate such programs. 1epending on your needs, there can be an easier way. If the worksheets in each workbook are laid out the same, and you (ust want to find differences between values in the cells of each worksheet, then you can use formulas to compare worksheets. Try the following steps% &. 6reate a new workbook called 6ompare. ls. ). In cell 4& of the first worksheet in 6ompare. ls, enter the following formula%
=IF(23(145ls6S7eet18A1<>23(045ls6S7eet18A1,"$i--e,ent","")

2. 6opy the formula from 4& into all the other cells that represent the range you want to compare. $or instance, if you want to compare 4&%>&) in both worksheets, then you would copy the formula from 4& into the full range of 4&%>&). These steps assume that the worksheets you want to compare are both named *heet&, and they are in !5&. ls and !5). ls, respectively. If you have other sheets in !5&. ls and !5). ls to compare, you can use similar formulas in other sheets of 6ompare. ls. !hen done, any cell that has the word +1ifferent+ in it represent cells that are different in the ranges being compared. Thus, if 6? had +1ifferent+ in it, then there is a difference between the cell 6? of *heet& in !5&. ls and cell 6? of *heet& in !5). ls. If you are comparing only numeric values between the two worksheets, you could use a different formula in step ), above%
=23(145ls6S7eet18A1'23(045ls6S7eet18A1

The result is a worksheet that subtracts the values in one workbook from the other, which results in the numeric differences. ,roblem% 6ounting the number of unique numeric values or unique data in -ist&, disregarding blank cells. *olution&% To count the number of uni9ue values use the *.', I$, and $7E@.E06: functions as shown in the following formula% A *.'(I$($7E@.E06:(4)%4&2,4)%4&2)BC,&)) *olution )% To count the number of uni9ue data use the *.',7O1.6T and 6O.0TI$ functions as shown the following formula% A*.',7O1.6T((4)%4&2DB++)E6O.0TI$(4)%4&2,4)%4&2F++))

In the above screenshot, in the first formula, change 0 to I$.

Counting Unique Numeric Values or Unique Data in a List Problem 6ounting the number of uni9ue numeric values or uni9ue data in -ist&, disregarding blank cells. Solution! To count the number of uni9ue values use the *.', I$, and $7E@.E06: functions as shown in the following formula% A *.'(I$($7E@.E06:(4)%4&2,4)%4&2)BC,&)) Solution " To count the number of uni9ue data use the *.',7O1.6T and 6O.0TI$ functions as shown the following formula% A*.',7O1.6T((4)%4&2DB++)E6O.0TI$(4)%4&2,4)%4&2F++)) =B1avid has a worksheet in which there is a list of countries. This list, in cells 4&%4&CC, can contain duplicates. 1avid wants to determine the number of uni9ue countries in the list. There are several ways you can go about deriving a count, without resorting to using a macro. The method you should use depends on the characteristics of the data in the list. 4 good place to start, however, is to define a named range that represents the list of countries. In the following e amples, it is assumed that the range is named 6ountries. (6atchy name, huh#) If the list contains only te t entries, and does not contain any blank cells, then the following will provide a count%
=SUM(19%#UN&IF(%ount,ies,%ount,ies))

This should be entered as an array formula, by pressing Ctrl+Shift+Enter. If the list contains blank cells, then the formula becomes a bit more comple . The following long array formula will work if there are blanks%
=SUM(IF(FRE:UEN%;(IF(LEN(%ount,ies)> ,MA&%/(%ount,ies,%ount,ies, ),""), IF(LEN(%ount,ies)> ,MA&%/(%ount,ies,%ount,ies, ),""))> ,1))

This approach==using the $7E@.E06: function==is fully recounted in the 'icrosoft <nowledge 5ase%
7tt<=99su<<o,t4>i.,oso-t4.o>9*?@iA=1 100

If you prefer to not use array formulas (for whatever reason), you can utiliGe a blank column to the right of your list. This column will contain regular formulas that indicate if the value to its left is uni9ue in the list or not. The first time a value appears, the formula returns the number &. On each subse9uent appearance of the same value, the formula returns a C. *tart by sorting your list, then place the following formula in cell 5&%
=IF(ISNA(VL##)U"(A0,BAB1=A1,1,)),1, )

Hust copy the formula from 5& to the range 5)%5&CC. !ith these results in place, you can easily sum column 5 and have a count of the uni9ue values in the list.

Delete Duplicates in #icrosoft E$cel

*ort your sheet by the column in which you"re trying to find duplicates. $or our e ample formula, our data is in column 4. In a spare column (we"re using column 5), use the following formula% %&'()!%)"*!*+, 6opy the formula down, using the fill handle. 6lick anywhere in your data, and hit 1ataFilter4utofilter.

$rom the 4utofilter dropdown in your spare column (we"re using column 5), choose &. :ou"ll see only those rows that returned a & as a result of the formula above, which means they"re all duplicates.

*elect all the rows you see, and delete them. Turn off the 4utofilter by going to 1ataFilter and uncheck 4utofilter. 1elete the column in which you typed your formula.
Easil- Duplicate ) Worksheet 'any times you will need to create a workbook that is made up of two or more identical sheets. 'any E cel users create each worksheet from scratch. Others, insert a new worksheet and copy and paste using the original worksheet. The problem with this is that the print settings have to be manually duplicated = which can often be tedious and frustrating. .ou can sa/e -ourself a lot of 0ork by properly designing the first worksheet and then simply duplicating it (print settings and all) by holding down the CTRL key while dragging the sheet tab of the original. 4s you drag, you will notice a small sheet icon with a plus sign (indicating copying) and a small black arrow (indicating where the duplicated sheet will be inserted). -et up on the mouse button and C12L key and -ou 0ill ha/e an i3entical cop- of -our original sheet.
When you have two large tables of data in an Excel Workbook you may need to compare the tables to try and spot the differences. Below we will look at two very easy ways this can be done which will save you hours of manual work. For both examples I will use the two ranges shown in the screen shot below. Note that I have bolded the cells in the second table that are not the same as their counterpart in the first table for easier viewing.

Method 1 - Using True or False


he first method involves entering a simple formula in another identically si!ed and shaped range. he best part of this method is that we can add the formulas in one step without having to copy and paste. ". $. &. #sing the above ranges to compare select the range E1:G7 starting from cell E1. This ensures that E1 is the Active cell in the selection. With this range selected click in the Formula Bar and type in% =A1=A9 Now enter this formula by pushing Ctrl'Enter at the same time

(ou should now see the range E1:G7 filled with True )the same* and False )not the same*.

Method 2 - Using Conditional Formatting


he second method is often the preferred way as it is easier to make any needed changes once the comparison has been done. ". $. &. /. #sing the above ranges to compare+ select the range A1:C7 stating from cell ,". his ensures that ," is the ,ctive cell in the selection. With this range selected+ go to Format-Conditional Formatting .elect Formula Is and then type the formula =NOT(A1=A9) 0lick the Format button and choose the format to mark differences with. I have used an orange background.

Now simply click O table.

and all your differences will be formatted according to the format you have chosen. When or if you make

any changes the cells format will automatically revert back to normal if the cell content is the same as the cell in the other

If you need to compare ranges or Worksheets from different Workbooks take a look at Excel 0ompare Workbooks

'iltering Columns for Unique Values


It is not unusual to ac9uire or develop data tables that have duplicate values in a column. If you want to see only the uni9ue values, without the duplicates, you want to filter your data table. E cel makes this rather easy for must scenarios. $or instance, let"s say you have a data table in which you have part numbers in column 4. If you want to filter the list so you see only uni9ue part numbers, you can follow these steps% &. *elect one of the cells in the list of part numbers. ). 6hoose $ilter from the 1ata menu, and then choose 4dvanced $ilter. E cel displays the 4dvanced $ilter dialog bo . (6lick here to see a related figure.) 2. I always like to choose the 6opy to 4nother -ocation option. 3. In the 6opy To field, specify the cell where you want the list of uni9ue, filtered values to be copied. 8. 'ake sure the .ni9ue 7ecords Only check bo is selected. ;. 6lick on O<.

4o0 1o Use E$cel5s )uto'ilter E cel has some great tools that allo0 -ou to 3o ama6ing things 0ith -our 3ata. The sad thing is that most E cel users spend years working with E cel without ever knowing they even e ist. One such tool is E cel"s )uto'ilter. If you work with lists of data in E cel (and who doesn"t#), )uto'ilter is essential. I"ll cover the basics here. $irst you must have a list. The first row must contain headings. The list can be any number of columns wide and any number of rows high. There should be no blank rows in the list. There should be a blank column to the right and a blank row to the bottom of the list. If the list doesn"t start in row & there must be a blank row above the headings. If the list doesn"t start in column 4, there should be a blank column to the left of the list. To get started you need to turn on 4uto$ilter. *elect a cell in your list and from the Data menu select 'ilter* )uto'ilter. :ou will see a dropdown arrow appear beside each column heading in your list. *electing either dropdown arrow will present a list you can choose from to filter your data to show (ust the rows that match the criteria you select. 4ll other rows are temporarily hidden. :ou can further filter your list by selecting another dropdown arrow.

0otice that blue dropdown arrows identify the columns you have applied filters to and blue row numbers identify the rows that meet the filter criteria.. To remove the filter applied to a column, click on that dropdown arrow and select ()ll, from the list. To remove the filters applied to all columns, from the Data menu select 'ilter* Sho0 )ll. If you want to do further work with your filtered data, you can copy and paste it somewhere else. To calculate amounts for your filtered data, add a *.5TOT4- formula t0o ro0s belo0 -our list in the column you wish to calculate. 1o this before applying any filters. :our subtotal formula will look like %SU7181)L(9*D! D:+, where 1& is the first row in your list and 18C is the last row in your list. 0ow, when you apply filters to your list, the subtotal formula will automatically calculate the total for only those records matching your filter criteria. (Bonus Excel Addict Trick: For ad hoc analysis of your data, instead of putting the subtotal formula below your data, insert a couple of rows above your data and add the subtotal formula there. Then you won't have to scroll all the way to the bottom after applying each filter.) This is powerfulI To remove the filters applied to all columns and turn off 4uto$ilter, from the Data menu select 'ilter* )uto'ilter.

Con/erting Units
$ortunately, E cel includes a function that will handle many different unit conversions for you. The 6O0JE7T function is part of the 4nalysis Tool,ak, and will handle doGens of conversions. The synta for the function is as follows%
%#NVER&(Calue, "-,o>", "to")

:ou simply supply the value you want to convert, along with an abbreviation for the units you are converting from and to. $or instance if you wanted to find out the e9uivalent of 2CC 5T.s when you convert to calories, you would use the following%
%#NVER&(D , "(&U", ".")

The number of different conversions that can be handled by 6O0JE7T is 9uite impressive, indeed. In fact, the list is so long that it cannot be included here. :ou can perform conversions in the areas of weight, volume, distance, time, pressure, energy, force, power, magnetism, and a few others. 4 complete list can be found in the E cel on=line Kelp system. (*imply search for +6O0JE7T worksheet function.+) :ou should note that if the 6O0JE7T function does not work on your system, it means you have not installed or enabled the 4nalysis Tool,ak. To enable it, follow these steps% &. 6hoose 4dd=Ins from the Tools menu. This displays the 4dd=Ins dialog bo . (6lick here to see a related figure.) ). 'ake sure the 4nalysis Tool,ak option is selected. 2. 6lick on O<. If you did not see an 4nalysis Tool,ak option in step ), it means that you did not install the option when you first installed E cel. :ou can rerun the E cel *etup program and choose to install the option. :ou must then enable the add= in, and you can use the function.

Calculating Week;En3ing Dates


here are two formulas you can use in order to calculate your week=ending dates. -et"s assume, for the sake of this e ample, that your year is stored in cell 4&. :ou could then figure out the first *aturday of the year by using this formula in cell 42%
=$A&E(A1,1,1)EF'3EE)$A;($A&E(A1,1,1))

This works because the !EE<14: function returns a value of & (*unday) through ? (*aturday) for any date. If you subtract that value from ?, then you have a value of ; (*unday) through C (*aturday). !hen you add that value to the 14TE value for Hanuary & of the year, you end up with the first *aturday of the year. If you prefer to have your weeks end on $ridays, then the formula needs to change a bit%
=$A&E(A1,1,1)EF'(3EE)$A;($A&E(A1,1,1)E1))

$inally, if you prefer to have your weeks end on *undays, then the formula needs to be like this one%
=$A&E(A1,1,1)EF'3EE)$A;($A&E(A1,1,1),0)

This formula uses a parameter for the !EE<14: function that calculates weekdays that range from & ('onday) through ? (*unday). Once you have the first week=ending date for the year (in 42, remember#), then you can calculate the rest of the week= ending dates for the year. ,lace the following formula in cell 43%
=IF(;EAR(ADEF)=BAB1,ADEF,"")

This checks to see if one week past the previous date is still in the year. If it is, then the new date is returned. If it isn"t, then an empty string is returned. If you copy this formula from 43 down through 488, then you will have all the desired week=ending dates for the year. !ith the formulas in place, simply change the year in cell 4& to see how the dates change. The range 42%488 provides room for 82 week=ending dates, which is possible for any given year. 5ecause you used the I$ statement in the formula in cells 43%488, then the very last value (488) will be blank if there were only 8) week= ending dates for the year.

Con/erting Numeric Values to 1imes


*am has a lot of worksheets that contain times. The problem is that the times are in the format +&2CC+ instead of the format +&2%CC.+ Thus, E cel sees them as regular numeric values instead of recogniGing them as times. *am wants them to be converted to actual time values. There are several ways you can approach this task. One way is to use the TI'E function to convert the value to a time, as shown here%
=&IME(LEF&(A1,0),RIG/&(A1,0),)

This formula assumes that the time in cell 4& will always contain four digits. If it does not (for instance, it might be 3)? instead of C3)?), then the formula needs to be modified slightly%
=&IME(LEF&(A1,LEN(A1)'0),RIG/&(A1,0),)

The formula basically pulls the leftmost digit (or digits) and uses them for the hours argument of the TI'E function, and then uses the two rightmost digits for the minutes argument. TI'E returns an actual time value, formatted as such in the cell. 4 similar formulaic approach can be taken using the TI'EJ4-.E function%
=&IMEVALUE(RE"LA%E(A1,LEN(A1)'1, ,"="))

This formula uses 7E,-46E to insert a colon in the proper place, and then TI'EJ4-.E converts the result into a time value. :ou will need to format the resulting cell so that it displays the time as you want. 4nother variation on the formulaic approach is to use the TELT function, in this manner%
=''&E1&(A1," H= ")

This returns an actual time value, which you will then need to format properly to be displayed as a time. 4nother approach is to simply do the math on the original time to convert it to a time value used by E cel. This is easy once you realiGe that time values are nothing more than a factional part of a day. Thus, a time value is a number between C and &, derived by dividing the hours by )3 (the hours in a day) and the minutes by &33C (the minutes in a day). Kere is a formula that does that%
=IN&(A191 )90IEM#$(A1,1 )91II

This determines the hour portion of the original value, which is then divided by )3. The minute portion (the part left over from the original value) is then divided by &33C and added to the first part. :ou can then format the result as a time, and it works perfectly. 4ll of the formulas described so far utiliGe a new column in order to do the conversions. This is handy, but you may want to actually convert the value in=place, without the need for a formula. This is where a macro can come in handy. The follow macro will convert whatever cells you have selected into time values and format the cells appropriately%
Su@ Nu>@e,&o&i>e() $i> ,%ell As Range $i> i/ou,s As Intege, $i> iMins As Intege,

Fo, Ea.7 ,%ell In Sele.tion I- IsNu>e,i.(,%ell4Value) AnA Len(,%ell4Value) > i/ou,s = ,%ell4Value H 1 iMins = ,%ell4Value MoA 1 ,%ell4Value = (i/ou,s E iMins 9 J ) 9 0I &7en

,%ell4Nu>@e,Fo,>at = "7=>> AM9"M" EnA INe5t EnA Su@

The macro uses an integer division to determine the number of hours (iKours) and stuffs the remainder into i'ins. This is then ad(usted into a time value and placed back into the cell, which is then formatted as a time. :ou can change the cell format, if desired, to any of the other time formats supported by E cel.

Parsing Non;Stan3ar3 Date 'ormats


*ubscriber 5ill ,almer is faced with the challenge of importing data into E cel that was originally created in other applications. The problem is that the data contains lots of dates, but they are in a format that E cel doesn"t understand. $or instance, the dates may be in the format C).C&.C3 or ).&.)CC3, neither of which is treated as a date by E cel. 5ill wants to know how to convert the non=standard dates to a date format that E cel understands. If the dates are in the same se9uence format that you use in your regional settings, then converting is a snap. $or instance, if your regional settings use the date format '1: (month followed by day followed by year), and the date you are importing is in the same format, then you can simply select the cells and replace the periods with a slash. !hen E cel changes ).&.)CC3 to )E&E)CC3, it automatically parses the result as a date. If the format you are importing doesn"t match your regional settings, then you need to shuffle around the date into the same format. $or instance, if the date you are importing is C).C&.C3 ($ebruary &, )CC3), and your system would interpret this as Hanuary &, )CC3, then the easiest way is to separate the date into individual components, and then put them back together. $ollow these general steps% &. Insert three blank columns to the right of the date column. ). *elect the cells containing the non=standard dates. 2. .sing the Te t to 6olumns !iGard (1ata / Te t to 6olumns), choose delimited data and use a period as the delimiter. 4fter the wiGard is done, you end up with three columns containing the month, day, and year. (6lick here to see a related figure.) 3. In the remaining blank column, enter a formula such as the following%
=$A&E(%1,A1,(1)

8. ;. ?. M.

6opy the formula down to other cells ne t to the dates. *elect the cells containing the formulas you (ust created, then press Ctrl+C. .se Edit / ,aste *pecial / Jalues to convert the formulas to results. 1elete the three columns that contain the separated dates, and keep the column that contains the final dates.

4nother solution is to simply use a macro to do the conversion. The following is a user=defined function that takes the non=standard date and converts it to a properly formatted date value. The macro also switches around the position of the month and day, as done in the Te t to 6olumns techni9ue.
"u@li. Fun.tion %onCe,tK$ate(A As St,ing) As $ate $i> ) As Long $i> )1 As Long $i> )0 As Long

) = Len(A) )1 = InSt,(1, A, "4") )0 = InSt,()1 E 1, A, "4") %onCe,tK$ate = $ateSe,ial(Val(MiA(A, )0 E 1, K ) ' )0 E 1)), Val(MiA(A, )1 E 1, )0 ' )1)), K Val(MiA(A, 1, )1 ' 1))) EnA Fun.tion

!o" #an I sho" the da$ and date in the one #ell in m$ E%#el &7 "or'(oo') ". ype the date into a cell+ such as &*+*&& )for 1th ,ugust "111* then press )Enter*.

$. 0lick back on the cell and select the Format menu then Cells,,, &. .elect the Custom category on the left of the box+ not the -ate category+ as you would in version 2.

/. 0lick in the field under T$.e and delete the entry that3s there. 2. ype in ddd/ d*mm*$$ as shown. he ddd tells Excel to display the abbreviation of the day+ such as Mon. he rest of the code tells Excel to display the date as usual.

4. 0lick 56 and the date will appear as Mon/ 0&*0+*&&. Entering any other date into the cell will also display the new day and date. #se the following examples to work out which code you need to enter to get the result you want%

4o0 can & calculate the 3ifference bet0een t0o 3ates<


E cel stores dates as serial numbers. The number & represents Hanuary &, &NCC, the number ) represents Hanuary ), &NCC, and so on. $ormatting these numbers using a date format causes them to appear as actual dates. Therefore, if you have dates stored in two cells, you can simply create a formula that subtracts one from the other to get the number of intervening days. :ou"ll want to make sure that the formula cell is formatted as a number, not a date. :ou might also find the 14TE1I$ function useful. This function, which was not documented prior to E cel )CCC, returns the difference between two dates, e pressed in years, months, or days. :ou might use the 14TE1I$ function to calculate how many months the payment on an invoice is overdue or to determine a person"s age when you know their birth date. E cel"s 14TE1I$ function takes three arguments. Its synta is% A14TE1I$(startOdate,endOdate,units)

In the synta , start_date is a date or reference to a date, end_date is a date or reference to a date, and units is a one= or two=digit string (in double 9uotes) specifying the units for the difference between the two dates. 4cceptable values for the units argument are shown below.

y returns the number of full years in the period. m returns the number of full months in the period. d returns the number of full days in the period. md returns the number of full days in e cess of the last full month. ym returns the number of full months in e cess of the last full year. yd returns the number of full days in e cess of the last full year.

$or e ample, assume cells 4& and 5& contain dates. The formula below returns the number of full years between the dates (useful for calculating a person"s age)% A14TE1I$(4&,5&,+y+) The formula below calculates the number of full months between the two dates% A14TE1I$(4&,5&,+m+)

Calculate A Person's Age Here is an easy way to calculate someones age using Excel. In cell A1 enter someones date of birth and in another cell enter this formula (copy and paste it right from this page). =DATEDIF(A1,NOW(),"y") " years, " DATEDIF(A1,NOW(),"y!") " !ont"s, " DATEDIF(A1,NOW(),"!#") " #ays"

his will return a string li!e" $$ years, % !ont"s, 1& #ays #ou could also use this techni$ue in many other situations where you need to calculate the time between today and some any other date.

,roblem% 6alculating the number of business days between the two dates listed in 4)%5). *olution% .se the 0ET!O7<14:* function, as follows% A0ET!O7<14:*(4),5)) In case the 0ET!O7<14:* function is not available (formula returns P04'E#), install the 4nalysis Tool,ak 4dd=in% Tools=B4dd=ins=Bselect 4nalysis Tool,ak=B6lick O<.

Calculate A Person's Age


Here is an easy way to calculate someones age using Excel. In cell A1 enter someones date of birth and in another cell enter this formula (copy and paste it right from this page). =DATEDIF(A1,NOW(),"y") " years, " DATEDIF(A1,NOW(),"y!") " !ont"s, " DATEDIF(A1,NOW(),"!#") " #ays"

his will return a string li!e" $$ years, % !ont"s, 1& #ays #ou could also use this techni$ue in many other situations where you need to calculate the time between today and some any other date.

Calculate the number of days in a month


E cel lacks a function for calculating the number of days in a particular month, so you"ll need to construct your own formula. If cell 4& contains a date, this formula will return the number of days in the month%
=$A;($A&E(;EAR(A1),M#N&/(A1)E1,1)'1)4

%reating A &eries 'f (or!days


If you want to create a series of dates in a column) consisting of only wee!days (*onday through +ridays)) enter your starting date in a cell (A,) in the example)) and then enter the following formula in the cell below that cell. =IF(OR(WEEKDAY(A4+1)=1,WEEKDAY(A4+1)=7),A4+3,A4+1) hen use +ill -own to fill out your entire series of dates.

1ate 4rithmetic
4dding 1ates

:ou can add some number of days to a date by simply using the =SUM function. *ince E cel stores dates as a number of days, no further work is re9uired. $or e ample, to add 8 days to &E&ENM, in A1, use =A1E5, which gives &E;ENM. To add a number of months or years to a date, you first need to decompose the initial date into its year, month, and day components, add in the desired offset, and then have E cel put the components back together. $or e ample, say you have a date in A1, to which you want to add 2 months and 3 days. :ou"d use the following formula% =DATE(YEAR(A1), MONTH(A1)+3, DAY(A1)+4) E cel will automatically handle the situation which arises when you pass a number greater than &) to the M#N&/ function, or a number greater than 2& to the $A; function. $or e ample, adding ; months and &C days to ME)8EN?, in 4& with the formula =DATE(YEAR(A1),MONTH(A1)+6, DAY(A1)+10) gives 2E?ENM. >enerally, you cannot add two dates that are in serial format. $or e ample, adding &E&8E&NNM and ;E&8E&NNM gives ;E2CE)CN;, which is essentially meaningless. If you want to add some number of days to a date, but e clude weekends and holidays, you can use the WORKDAY function, which is part of the 4nalysis Tool ,ack. 0ote, however, that adding a month to a date may give you a result that you do not e pect. $or e ample, suppose 4& contains the date 2&=Han=)CC). If you use the formula =DATE(YEAR(A1), MONTH(A1)+1, DAY(A1)) you will get the date 2='arch=)CC), because the +2&st+ day of $ebruary, )CC), is 2='arch. The formula below will work around this issue, returning the last day of the ne t month if the date in 4& is a day that does not e ist in the ne t month. =DATE(YEAR(A1),MONTH(A1)+1,MIN(DAY(A1),DAY(DATE(YEAR(A1),MONTH(A1)+2,0)))) $or e ample, if 4& contains the date 2&=Han=)CC), this formula will return )M=$eb=)CC). It is important that you and your users understand what +one month later+ means in the conte t of your workbook.

*ubtracting 1ates
:ou can subtract some number of days to a date by simply using the SUM function. *ince E cel stores dates as a number of days, not further work is re9uired. $or e ample, to subtract 8 days to ;=Han=NM, in 4&, use =A1-5, which gives &=Han=NM. To subtract a number of months or years to a date, you first need to decompose the initial date into its year, month, and day components, subtract the desired offset, and then let E cel put the components back together. $or e ample, say you have a date in 4&, to which you want to subtract 2 months and 3 days. :ou"d use the following formula%

=DATE(YEAR(A1), MONTH(A1)-3, DAY(A1)-4) E cel will automatically handle the situation which arises when you pass a number less than C to the MONTH function, or a number less than C to the DAY function. $or e ample, subtracting ; months and &C days to 3E8EN?, in 4& with the formula =DATE(YEAR(A1),MONTH(A1)-6, DAY(A1)-10) gives NE)8EN;. >enerally, you cannot subtract two dates that are in serial format. If you want to subtract some number of days from a date, but e clude weekends and holidays, you can use the WORKDAYfunction, which is part of the 4nalysis Tool ,ack.

4dding Times
:ou can add times using the =SUM worksheet function. Hust enter all of your times as KK%''%**, and then use SUM to add them up. :ou may leave off the =SS if you prefer. 5y default, E cel will display the sum of times in +time=of=day+ format, meaning that adding &)%2C Q &)%38 will yield C&%&8. :ou can prevent E cel from +rolling over+ at )3 hours by formatting the result cell as 276=>> which will cause it to display )8%&8 rather than C&%&8. If you want to add up minutes and seconds, you must include a leading + =+ in your data. $or e ample, enter + =1 =0 + to indicate &C minutes, )C seconds. !hen you sum these times, E cel will display the sum in +time=of=day+ format, meaning that adding C%3C%&C and C%2C%)C will yield &%&C%2C. :ou can prevent E cel form +rolling over+ at the hour by formatting the result cell as !"#$$ which will cause it to display ?C%2C rather than &%&C%2C. 4nother method of adding times is to use the TIME function. To add & hour, 28 minutes, &C seconds to a time in 4&, use the function =A1 + TIME(1,35,10)

*ubtracting Times
*ubtracting one time from another is a little more difficult, since E cel does not handle negative numbers as times. !hen you enter a time without a date, E cel assumes this is that time of day on Hanuary &, &NCC, since it puts a C in for the date component of the serial number. $or e ample, you cannot subtract &M hours from 3%CC ,', since this would result in a negative number (C.;? = C.?8 A =C.M2). :ou can get around this by entering a full date and then subtracting a time from this, and the formatting the result as time=only. $or e ample to subtract &M hours from 3%CC ,', enter the 3%CC ,' as +&E&ENM 3%CC ,'+ and subtract &M%CC from this. $ormatting the result as %%#!! will result in +&C%CC ,'+ which is what we would e pect. 4nother method is to use the TIME function. To subtract & hour, 28 minutes, &C seconds from a time in 4&, use the function

=A1 - TIME(1,35,10)

Time Intervals
:ou can determine the number of hours and minutes between two times by subtracting the two times. Kowever, since E cel cannot handle negative times, you must use an =IF statement to ad(ust the time accordingly. If your times were entered without a date (e.g, ))%2C), the following statement will compute the interval between two times in 4& and 5& . =IF(A1&'1,'1+1-A1,'1-A1) The +E1+ in the formula causes E cel to treat 5& as if it were in the ne t day, so 0=D '00= will result in I=D , four hours and thirty minutes, which is what we would e pect. To covert this to a decimal number, for e ample, 3.8, indicating how many hours, multiply the result by )3 and format the cell as >eneral or 1ecimal, as in =24((IF(A1&'1,'1+1-A1,'1-A1))

7ounding Times
$or many scheduling or payroll applications, it is useful to round times to the nearest hour, half=hour, or 9uarter=hour. The MROUND function, which is part of the 4nalysis Tool,ack add=in module, is very useful for this. *uppose you have a time in cell 4&. In 5& , enter the number of minutes to which you want to round the time == for e ample, enter 2C to round to the nearest half=hour. The formula =TIME(HOUR(A1),MROUND(MINUTE(A1),'1),0) will return a time rounded to the nearest half=hour, either up or down, depending what is closest. $or e ample, &)%&3 is rounded to &)%CC, and &)%&8 is rounded to &)%2C. To round either up or down to the nearest interval, enter the interval in 5&, and use either of the following formulas% =TIME(HOUR(A1),F)OOR(MINUTE(A1),'1),0) to round to the previous interval (always going earlier, or staying the same). =TIME(HOUR(A1),*EI)IN+(MINUTE(A1),'1),0) to round to the ne t interval (always going later, or staying the same).

Calculating an age bet0een t0o 3ates using the D)1ED&' function


It is easy to determine the number of days between any two dates simply by subtracting one from the other, but it is e tremely difficult to return a string that says something like ")3 years, ; months and M days". The maths and logic involved in this apparently straightforward 9uestion are very comple . :ou may wish to try it using the 'O0TK() and 14:() functions, but make sure you thoroughly test your formulaI

4n E cel function called 14TE1I$() will perform this calculation although it is not included within the E cel help files or the function wiGard until E cel )CCC. It does however e ist in previous versions of E cel. It takes the following structure% A14TE1I$( ate!, ate", #utput$e%uirement). The first two parameters are simple, although you must ensure that the second date is greater than the first. The Output7e9uirement parameter is a character code (typed inside inverted commas) that specifies the type of value you wish to obtain. 6ode +d+ +m+ +y+ E planation The number of days between 1ate& and 1ate). The number of complete months between 1ate& and 1ate). The number of complete years between 1ate& and 1ate). The number of days between 1ate& and 1ate), as if 1ate& and 1ate) were in the same +yd+ 1ays e cluding :ears year. The number of months between 1ate& and 1ate), as if 1ate& and 1ate) were in the +ym+ 'onths e cluding :ears same year. 1ays e cluding 'onths and The number of days between 1ate& and 1ate), as if 1ate& and 1ate) were in the same +md+ :ears month and the same year. This function is ideally suited to calculating someones precise age on any particular date or the number of days until your ne t birthday. The first date can be your date of birth and the second date is either entered in another cell by the user, or automatically set to todays date with the 0O!() function. 1escription 1ays 'onths :ears

The diagram (right) illustrates the difference between the different types of day count. The first formula (row );) counts the total number of days between the ) dates. The ne t formula counts the days which are the remainder after the whole years are deducted. The final formula returns the number days after both the whole years and the months have been deducted.

The second diagram (left) shows how the function can be incorporated within a comple formula to return a sentence describing a time interval (in cell 42M). The Te t function is the correct way of incorporating both numeric values within a string of characters.

>eneral information about 1ate and Time functions is also available within this site. It is possible to convert whole phrases, including number values, into proper words (e.g. "Twelve years and $our days"). This re9uires a user defined function such as shown here. Kow can I enter the current date into a cell so it doesn"t change from day to day# !hen I use the 0O! function, it always shows the current date. The easiest way to enter the current date into a cell is to use the &trl'( key combination (press the 6trl key and type a semicolon). *imilarly, you can enter the current time by pressing &trl')hift'( (press the &trl and )hift keys and type a semicolon). 5oth of these key combinations enter the information as a volatile value, not as a formula.
7ecently an *+celTips subscriber asked if it was possible to use E cel to calculate the months of tenure for a series of employees, given the date at which the employee started. This can be done very easily. $or the sake of this e ample, let"s assume that column 6 contains the starting date for a list of employees. :ou could use the following formula in column 1 to determine each employee"s tenure%
.-A E-I+(%/)0'(())1*1)

he -A E-I+ function calculates the difference between a starting date and an ending date. he 1*1 used in the formula indicates that you want the result in completed months. o calculate the a2erage tenure for your series of employees) simply include the following formula at the bottom of column %"
.A3E4A5E(%/"%16,)

'f course) you should replace the range in the function (%/"%16,) with the actual range of employee tenures as determined by the -A E-I+ formula.

This page describes a few methods for working with intervals of dates. *pecifically, it address the 9uestions of whether a date falls within an interval, the number of days that two intervals overlap, and the how many days are in one interval, e cluding those days in another interval. These formulas can be 9uite useful for scheduling applications, such as employee vacation schedules.

Is 4 1ate In 4n Interval#
*uppose we have 2 dates == a start date, and end date, and a test date. !e can test whether the test date falls within the interval between start date and end date. In this formula, we will use three named cells% &$ate1 for the start date, &$ate0 for the end date, and &$ate for the test date. This formula will return either &RUE or FALSE, indicating whether &$ate falls in the interval. =AND((TD,-.&=MIN(TD,-.1,TD,-.2)),TD,-./=MA0(TD,-.1,TD,-.2)) $or e ample if &$ate1 is 1'Lan and &$ate0 is D1'Lan , and &$ate is 15'Lan , the formula will return &RUE, indicating that &$ate falls in the interval. In this formula, it does not matter whether &$ate1 is earlier or later than &$ate0.

0umber Of 1ays In One Interval 4nd 0ot In 4nother

!e can also work with two date intervals, and determine the number of days that fall in one interval, and not in another. This can become complicated because of how the intervals may overlap. $or e ample, the main interval may complete contain the e clusion interval. Or, the e clusion interval may completely contain the main interval. 'oreover, only part of the main interval may be contained within the e clusion interval, either at the starting or the ending end of the interval. $inally, the two intervals may not overlap at all. 5elow is a summary of the various interval types. The 1ates values are the days we wish to count. The J1ates values are the days we wish to e clude from the 1ates interval. The comple ity of the formula is due to the fact that it must handle all of the interval types.

$or this formula, we will have 3 named cells, as shown below%

Name $ate1 $ate0 V$ate1 V$ate0 N3Range

Description The starting date of the main interval. The main interval is the dates we want to work count. The ending date of the main interval. The starting date of the e clusion interval. The e clusion interval is the dates that we want to e clude from the count of the main interval. The ending date of the e clusion interval. 4 list of holiday dates. .sed in the second version of the formula, which uses the NE&3#R)$A;S function.

$or this formula, we re9uire that $ate1 is less than (earlier than) or e9ual to $ate0, and that V$ate1 is less than (earlier than) or e9ual to V$ate0. =IF(OR(D,-.2/1D,-.1,1D,-.2/D,-.1),D,-.2D,-.1+1,IF(OR(AND(D,-.1/=1D,-.1,D,-.2&=1D,-.2), AND(D,-.1&=1D,-.1,D,-.2/=1D,-.2)),MA0(0,(D,-.2-D,-.1)-(1D,-.2-1D,-.1)), IF(OR(AND(D,-.1/=1D,-.1,D,-.2/=1D,-.2),AND(D,-.1&=1D,-.1,D,-.2&1D,-.2)), MA0(0,(1D,-.1-D,-.1))+MA0(0,D,-.2-1D,-.2),NA()))) Kere are some e amples.

Date!

Date"

VDate! VDate" 2esult 1 ' Lan 0 ' Lan

Description There are )C days between &=Han and N=Han (N days) and )&= Han and 2&=Han (&& days). The && days between &C=Han and )C=Han are subtracted from the 2& days between &=Han and 2&= Han. In this e ample, the entire e clusion interval (the J1ates) is included within the main interval (the 1ates). Kere, the entire main interval is included within the e clusion interval. There are no days between &C=Han and )C=Han that do fall outside the &=Han and 2&=Han. In this case, the ending segment of the main interval (&=Han to &8=Han) overlaps with the beginning segment of the e clusion interval (&C=Han to )C=Han). There are N days (&=Han to N=Han) in the main interval that do not overlap with the e clusion interval. Ending segment of the main interval overlaps the e clusion interval. There are 8 days (&;=Han to )C=Han) in the main interval that are not included in the e clusion segement.

1'Lan

D1'Lan

1 'Lan 0 'Lan 1'Lan

D1' Lan

1'Lan

15'Lan

1 ' Lan

0 ' Lan

1 'Lan 0 'Lan 1'Lan

15' Lan

0ote that the dates here are inclusive. There are &C days between &=Han and &C=Han. This is one day different that what you would get from simply subtracting the dates. The formula above does not treat weekend days differently from working days. In other words, *aturdays and *undays are included in the calculations. If you want to count only weekdays, e cluding weekends and holidays, use the modified version below, which calls the NE&3#R)$A;S function to compute the number of working days in the intervals. This function adds another name ranged to the mi . This name, N3Range, refers to a range containing a list of holidays. If you do not use holidays, you can either point this name to an empty cell, or eliminate it from the formula entirely.

=IF(OR(D,-.2/1D,-.1,1D,-.2/D,-.1),NETWORKDAYS(D,-.1,D,-.2,NWR,23.), IF(OR(AND(D,-.1/=1D,-.1,D,-.2&=1D,-.2),AND(D,-.1&=1D,-.1,D,-.2/=1D,-.2)), MA0(0,NETWORKDAYS(D,-.1,D,-.2,NWR,23.)-NETWORKDAYS(1D,-.1,1D,-.2,NWR,23.)), IF(OR(AND(D,-.1/=1D,-.1,D,-.2/=1D,-.2),AND(D,-.1&=1D,-.1,D,-.2&1D,-.2)), IF((D,-.1&=1D,-.1),0,NETWORKDAYS(D,-.1,1D,-.1-1,NWR,23.))+ IF((D,-.2/=1D,-.2),0,NETWORKDAYS(1D,-.2+1,D,-.2,NWR,23.)),NA()))) The NE&3#R)$A;S function is part of the 4nalysis Tool ,ack 4dd=In, so you must have this module installed in order to use this formula. $or more information about using formulas to create the dates of holidays, see the Kolidays page. 1angent The reason the named cells are V$ate1 and V$ate0 is that I originally wrote this formula for a Jacation timekeeping application, and the V refers to +Jacation+. Of course, you can name your cells anything that works with your application, or you can simply use cell references.

0umber Of 1ays 6ommon To Two Intervals


The previous section worked with a logical 0OT condition == dates in one interval and 0OT in another. This section describes a formula for working with the inverse of that == the number of days that are in 5OTK of two intervals. $or this formula, we will have 3 named cells, as shown below% Name I$ate1 I$ate0 R$ate1 R$ate0 N3Range Description The starting date of the first interval. The ending date of the first interval. The starting date of the second interval. The ending date of the second interval. 4 list of holiday dates. .sed in the second version of the formula, which uses the NE&3#R)$A;S function.

$or this formula, we re9uire that I$ate1 is less than (earlier than) or e9ual to I$ate0, and that R$ate1 is less than (earlier than) or e9ual to R$ate0. The formula below will return the number of days that are in both intervals. =IF(OR(ID,-.2/RD,-.1,ID,-.1&RD,-.2),0,(MIN(ID,-.2,RD,-.2)-MA0(ID,-.1,RD,-.1)+1)) Kere are some e amples. &Date! &Date" 2Date! 2Date" 2esult Description D1' 1'Lan Lan 1 ' Lan 1'Lan 0 ' Lan 15' Lan 1 ' Lan 0 ' Lan D1' Lan 0 ' Lan 11 There are && days common to the intervals. *ince the 71ates are contained within the I1ates, the result is the number of days between &C=Han and )C=Han, or && days. *ince this is an 401 condition format, we can reverse the dates between I1ates and 71ates, and get the same result as above, && days. Kere, there are ; days common to the two intervals == the dates &C=Han to &8=Han fall in both intervals.

1'Lan 1 ' Lan

11 J

1'Lan

1 ' Lan

15' Lan

0 ' Lan

The result here is C, because there are no dates in the I1ate interval (&=Han to &C=Han) than fall in the 71ate interval (&8=Han to )C=Han).

0ote that the dates here are inclusive. There are &C days between &=Han and &C=Han. This is one day different that what you would get from simply subtracting the dates. The formula above does not treat weekend days differently from working days. In other words, *aturdays and *undays are included in the calculations. If you want to count only weekdays, e cluding weekends and holidays, use the modified version below, which calls the NE&3#R)$A;S function to compute the number of working days in the intervals. This function adds another name ranged to the mi . This name, N3Range, refers to a range containing a list of holidays. If you do not use holidays, you can either point this name to an empty cell, or eliminate it from the formula entirely. =IF(OR(ID,-.2/RD,-.1,ID,-.1&RD,-.2),0, A'S(NETWORKDAYS(MIN(ID,-.2,RD,-.2),MA0(ID,-.1,RD,-.1),NWR,23.))) The NE&3#R)$A;S function is part of the 4nalysis Tool ,ack 4dd=In, so you must have this module installed in order to use this formula. $or more information about using formulas to create the dates of holidays, see the Kolidays page.

) final note% These formulas are designed to illustrate the concept of the date +intervals+, and how they need to be handled by the E cel date arithmetic. -ogicians can probably reduce the formulas to simpler forms by consolidating the AN$s and #Rs. 5ut the point here is illustration and education, not the simplest possible formula. ) & 8l3 Date ) &&)2C2 2 C2&&)2 3 )2&&C2 7 'ormula Use3 AJ4-.E(-E$T(4),))F+E+F'I1(4),2,))F+E+F7I>KT(4),))) AJ4-.E('I1(42,2,))F+E+F7I>KT(42,))F+E+F-E$T(42,))) AJ4-.E('I1(43,2,))F+E+F-E$T(43,))F+E+F7I>KT(43,))) C Ne0 Date &&E)2EC2
""7$&78& ""7$&78&

) & 8l3 Date ) &&)2C2 2 C2&&)2 3 )2&&C2

7 'ormula Use3 AJ4-.E('I1(4),2,))F+E+F-E$T(4),))F+E+F7I>KT(4),))) AJ4-.E(7I>KT(42,))F+E+F'I1(42,2,))F+E+F-E$T(42,))) AJ4-.E(-E$T(43,))F+E+F'I1(43,2,))F+E+F7I>KT(43,)))

C Ne0 Date )2E&&EC2


$&7""78& $&7""78&

,roblem% 6reating new I, addresses, composed of the first three segments in the original address and the last segment in the original address multiplied by ). *olution%

.se the -E$T, 'I1 and $I01 functions to e tract the last segment of the original address, multiply it by ) and (oin that new segment back to the remaining three. $ollowing is the formula% A(-E$T(4),$I01(++.++,4),$I01(++.++,4),$I01(++.++,4))Q&)Q&)))F('I1(4),$I01(++.++,4),$I01(++.++,4),$I01(++. ++,4))Q&)Q&)Q&,NN)R))

Installing he Analysis ool 7ac!


&ince the A 7 is pro2ided free with Excel) you already ha2e it on your computer. o install it and ma!e its functions a2ailable in your wor!boo!s) go to the ools menu) and select the Add8Ins item. This page describes a number of worksheet functions for working with dates and times in E cel.

!orking 1ays 4nd Kours 5etween Two 1ates 4nd Times


*uppose you have a schedule start date and time and an end date and time. *imply subtracting the end=time from the start=time will return the total number of days and hours between the times. Kowever, suppose you want to know how many work days and hours the pro(ect will actually take. $or e ample, suppose a pro(ect starts on 'onday, )8=October= NN at &2%CC and ends on Thursday, )M=Oct=NN at &8%CC, and that your normal working hours are N%CC to &?%CC. In this case, there are 2 days and ) hours between the start and end times () full days, Tuesday and !ednesday, plus 3 hours on 'onday and ; hours on Thursday, for ) days and &C hours, or, since there are M hours in a workday, 2 days and ) hours). The following formula will return the number of working days and hours between two dates and times. It returns a string like +2 days ) hours+. =IF(AND(INT(S-,4-DT)=INT(E25DT),NOT(ISNA(MAT*H(INT(S-,4-DT), H6785,9)8$-,0)))),:0 5,9$ 0 %6;4$:, IF(INT(S-,4-DT)=INT(E25DT), :0 5,9$ : < ROUND(24((E25DT-S-,4-DT),2)<:%6;4$:, MA0(NETWORKDAYS(S-,4-DT+1,E25DT-1,H6785,9)8$-),0)+ INT(24((((E25DT-INT(E25DT))-(S-,4-DT-INT(S-,4-DT)))+ (D,9E25-D,9S-,4-))=(24((D,9E25-D,9S-,4-)))< : 5,9$ :<MOD(ROUND(((24((E25DT-INT(E25DT)))-24(D,9S-,4-)+ (24(D,9E25-(24((S-,4-DT-INT(S-,4-DT)))),2), ROUND((24((D,9E25-D,9S-,4-)),2))<: %6;4$ :)) !here the following names are used%

Name Sta,t$& EnA$& $aOSta,t $aOEnA /oliAaOList

Description The starting date and time The ending date and time The time of day that the normal work day begins. The time of day that the normal work day ends.

E$ample 05'#.t' MM 1D= 0N'#.t' MM 15= M= 1F=

4 range containing a list of dates to e cluded, e.g., holidays or /1=/1 vacation days.

To return the total number of working hours, use the following formula% =IF(AND(INT(S-,4-DT)=INT(E25DT),NOT(ISNA(MAT*H(INT(S-,4-DT),H6785,9)8$-,0)))) ,0,A'S(IF(INT(S-,4-DT)=INT(E25DT),ROUND(24((E25DT-S-,4-DT),2), (24((D,9E25-D,9S-,4-)( (MA0(NETWORKDAYS(S-,4-DT+1,E25DT-1,H6785,9)8$-),0)+ INT(24((((E25DT-INT(E25DT))(S-,4-DT-INT(S-,4-DT)))+(D,9E25-D,9S-,4-))=(24((D,9E25-D,9S-,4-))))+ MOD(ROUND(((24((E25DT-INT(E25DT)))-24(D,9S-,4-)+ (24(D,9E25-(24((S-,4-DT-INT(S-,4-DT)))),2), ROUND((24((D,9E25-D,9S-,4-)),2)))))) This will return the number of working hours as a numeric value, which can be used in other calculations. $or e ample, if there are M hours in a working day, and the duration is 2 days, ; hours (from the first formula), the formula above will return 2C (2RM Q ;). *ince these formulas use the NETWORKDAYS worksheet function, you must the 4nalysis Tool ,ack installed in order to use the formula. 0OTE% These formulas will not work properly if the working day starts at a later time of day than it ends. $or e ample, if your working day crosses midnight, the formulas will not work properly.

-ays In *onth
o return the number of days in a month) use the following formula. &uppose cell A1 contains the date 198 :an81;;<. =DAY(DATE(YEAR(A1),MONTH(A1)+1,0)) his will return /1) the number of days in :anuary) 1;;<.

+irst -ay 'f *onth

#ou can use the following formula to get the date of the first day of the month. &uppose the date in cell A1 is 198:an81;;<. =DATE(YEAR(A1),MONTH(A1),1) his will return 18:an81;;<.

=ast -ay 'f *onth


#ou can use the following formula to get the date of the last day of the month. &uppose the date in cell A1 is 198:an81;;<. =DATE(YEAR(A1),MONTH(A1)+1,0) his will return /18:an81;;<.

+irst (ee!day -ay 'f *onth


#ou can use the following formula to get the date of the last wee!day (*onday thru +riday) of the month. &uppose the date in cell A1 is 18:une8>??>. =DATE(YEAR(A1),MONTH(A1),1)+*HOOSE(WEEKDAY(DATE(YEAR(A1),MONTH(A1),1)),1,0,0,0,0, 0,2) his will return /8:une8>??>.

=ast (ee!day -ay 'f *onth


#ou can use the following formula to get the date of the last wee!day (*onday thru +riday) of the month. &uppose the date in cell A1 is @80o28>??>. =DATE(YEAR(A1),MONTH(A1)+1,0)-(MA0(0,WEEKDAY(DATE(YEAR(A1),MONTH(A1)+1,0),2)-5)) his will return >;80o28>??>. Another formula) gi2en a month and year) is the following array formula" =MA0(ROW(INDIRE*T(DATE(9.,4,!62-%,1)<:#:<DATE(9.,4,!62-%+1,0)))((WEEKDAY(ROW(INDI RE*T(DATE(9.,4,!62-%,1)<:#:<DATE(9.,4,!62-%+1,0))),2)/6))

=ast -ay 'f 7re2ious *onth


#ou can use the following formula to get the date of the last day of the pre2ious month. &uppose the date in cell A1 is 198:an81;;<. =DATE(YEAR(A1),MONTH(A1),0) his will return /18-ecember81;;6.

0th -ay 'f (ee! +or A *onth And #ear


his formula will return will return the date of 0th day8of8wee! for a gi2en month and year. +or example) it will return >@8*arch8;< for the ,th hursday of *arch) 1;;<. -ays8of8wee! range from 1 to 6) with &unday . 1 and &aturday . 6. =DATE(Y4,M62,1+((N-%-(D6W&=WEEKDAY(DATE(Y4,M62,1))))(7)+ (D6W-WEEKDAY(DATE(Y4,M62,1)))) (here ;,, Mon, Nt7, and $o3 are cell references or 2alues indicating #ear) *onth) 0th) and -ay8'f8 (ee!.

0th -ay 'f (ee! +or A #ear


his formula will return will return the date of 0th day8of8wee! for a gi2en year. +or example) it will return 118 April8>??1 for the 19th (ednesday of the year >??1. -ays8of8wee! range from 1 to 6) with &unday . 1 and &aturday . 6. =DATE(Y4,1,1+(N-%-(D6>&=WEEKDAY(DATE(Y4,1,1))))(7)+ D6>-WEEKDAY(DATE(Y4,1,1)) (here ;,,Nt7, and $o3 are cell references or 2alues indicating #ear) *onth) 0th) and -ay8'f8(ee!.

0umber 'f *ondays In 7eriod


If you need to return the number of *ondayAs (or any other day) that occur within an inter2al between two dates) use the following Array +ormula" =SUM(IF(WEEKDAY(A2-1+ROW(INDIRE*T(:1#:<TRUN*('2-A2)+1)))=*2,1,0)) his formula assumes the following" A0 contains the beginning date of the inter2al (0 contains the ending date of the inter2al %0 contains the day8of8wee! number (1.&unday) >.*onday)...)6.&aturday)

(ee! -ifferences
#ou cannot use the =$A&E$IF function of return the difference of of two dates in wee!s) so you can use the following function return the number of wee!s and days between two dates" =TRUN*(('1-A1)=7)<: W..?$ :<MOD('1-A1,7)<: D,9$:

(hat -ay Is ItB


If you need to !now the day8of8wee! for a specific date) the =3EE)$A; function gi2es you a number between 1 and 6 indicating the day) (1.&unday) >.*onday) ... ) 6.&aturday). o con2ert this number to the actual name of the day (1&unday1) for example)) use the =&E1& function" =TE0T(A1, :555:) returns the three character abbre2iation for the day) e.g.) 1*on1. =TE0T(A1,:5555:) returns the full name of the day) e.g.) 1*onday1. o determine if a date is a wor! day (*onday 8 +riday)) create a name called 3o,?$aOs which refers to =@2A3A4A5A6B hen following function will return 4CE or +A=&E) indicating whether the date in A1 is a wor! day" =IF(ISERROR(1)OOKUC(WEEKDAY(A1),W64?D,9$,1,0)),FA)SE,TRUE)

(hat Duarter Is ItB


o return the $uarter of the year) use the formula =ROUNDUC(MONTH(A1)=3,0) .

(hat (ee! Is ItB


If you need to !now what wee! of the year at date falls in) use the following formula" =TRUN*(((A1-DATE(YEAR(A1),1,1))=7))+1+ IF(WEEKDAY(DATE(YEAR(A1),1,1))&WEEKDAY(A1),1,0) his will return a number between 1 and 9/) indicating the wee! of the year for the date in A1.

=ast (ee!day 'f *onth

There are several ways that this can be done in E cel, and you should pick the method that is best for your purposes. The first method is to simply add a column to your worksheet that will be used for the alert. 4ssuming your due date is in column $, you could place the following type of formula in column >%
=IF(FD<(&#$A;()EF),"<<<","")

The formula checks to see if the date in cell $2 is earlier than a week from today. If so, then the formula displays +DDD+ in the cell. The effect of this formula is to alert you to any date that is either past or within the ne t week.

4nother approach is to use the conditional formatting capabilities of E cel. $ollow these steps% &. *elect the cells that contain the document due dates. ). 6hoose 6onditional $ormatting from the $ormat menu. E cel displays the 6onditional $ormatting dialog bo . (6lick here to see a related figure.) 2. 'ake sure the first drop=down list is +6ell Jalue Is.+ (This should be the default.) 3. 'ake sure the second drop=down list is +-ess Than.+ 8. In the formula area, enter +ATO14:()+ (without the 9uote marks). ;. 6lick the $ormat button. E cel displays the $ormat 6ells dialog bo . (6lick here to see a related figure.) ?. .sing the 6olor drop=down list, choose the color red. M. 6lick O< to close the $ormat 6ells dialog bo . N. 6lick 4dd. The 6onditional $ormat dialog bo e pands to include a second condition. &C. 'ake sure the first drop=down list for the second condition is +6ell Jalue Is.+ (This should be the default.) &&. 'ake sure the second drop=down list is +-ess Than.+ &). In the formula area, enter +ATO14:()Q?+ (without the 9uote marks). &2. 6lick the $ormat button. E cel displays the $ormat 6ells dialog bo . &3. .sing the 6olor drop=down list, choose the color blue. &8. 6lick O< to close the $ormat 6ells dialog bo . (6lick here to see a related figure.) &;. 6lick O< to close the 6onditional $ormatting dialog bo . This is a two=tiered format, and you end up with two levels of alert. If the due date is already past, then it shows up as red. If the due date is today or within the ne t seven days, then it shows up in blue.

E$tract 1he .ear* #onth* or Da- 'rom ) Date 1o you use lots of dates in E cel# If you do you probably have needed to use the year, month or day referred to in a date cell in a separate cell. The solution is simple. -ets say that cell )! contains the date =ul- "!* "++> (entered as )&E?E)CC3 or ?E)&E)CC3 depending on your date system). :ou want to e tract the year (i.e. )CC3) from that date and put it in cell C!. *imply enter the formula %.E)2()!, in cell 6&. *ame thing for month and serial number of the day. .se %#8N14()!, or %D).()!,. To know the day% ATELT(4&,SddddS)

7oger 'iddleton is keeping track of invoices in an E cel worksheet. 4ll of the invoices need to be submitted with a due date of the )Mth of the month, and 7oger wondered if there was a way to force a date to always +(ump forward+ to the ne t instance of the )Mth. The cleanest way to force dates forward is to create a formula that will e amine a date in a cell, and then force that date to the ne t desired date, such as the )Mth. The following formula is a good one to start with%
=IF($A;(A1)>0N,$A&E(;EAR(A1),M#N&/(A1)E1,0N),$A&E(;EAR(A1),M#N&/(A1),0N))

This formula e amines the date in cell 4&. If the 14: value of the date is greater than )M, then the formula constructs and returns a date that is e9ual to the )Mth of the ne t month. If it is less than or e9ual to )M, then the )Mth of the current month is returned. There is an even shorter way to render an acceptable formula, however==one that entirely gets rid of the I$ function%

=$A&E(;EAR(A1),M#N&/(A1)E($A;(A1)>0N),0N)

This uses the current year as the year, and the day is always )M. The month uses a 5oolean calculation. If the day is greater than )M then (1ay(4&)B)M) will be T7.E and will calculate as a &, thereby adding & to the current month. If it is less than or e9ual to )M it will be $4-*E and calculate as a C, (ust calculating the current month. If you don"t want to be +strict+ giving some people only a day (NE)?E)CC8 will give a due date of NE)ME)CC8), you could plan on giving them at least a week with the formula%
=$A&E(;EAR(A1),M#N&/(A1)E($A;(A1)>01),0N)

This would give the )Mth of the current month for the &st thru )&st, but for later dates it will (ump to the )Mth of the following month.

#ultipl-ing 1imes /alues an3 numbers

,roblem% 6olumn 6%6 contains time values representing worked hours. 6olumn 1%1 contains rates. In order to calculate the payment, we would have to multiply each time value by its matching numerical rate. *olution% To calculate the payment, the time value must be multiplied by )3 as well as by the rate, as follows% A4)R5)R)3

!orking !ith Overtime Kours In E cel


E cel is often used to manage employee time records == number of hours worked, meal breaks, regular and overtime pay, and so on. This page e amines a number of related formulas for a simple daily timekeeping record. *uppose we have 8 employees, and we want to keep track of the time each comes into work, breaks for lunch, returns from lunch, and leaves for the day. 4lso, we need to keep track of the regular and overtime hours for each employee, and pay the the overtime hours at a different rate. The sample below shows what the worksheet might look like%

0ow, lets look at the values and formulas in each column. 6olumn 5 is simply the 0ame of each employee. 6olumns 6, 1, E, and $ are the times that each employee started work, left for lunch, returned from lunch, and left work for the day. ,ay attention to the hours worked by Emma, in row M. Ker shift e tended over midnight (she started at &C,' and left at ?4'), and her lunch break also e tended over midnight. Our formulas will take this into account, and calculate the proper times. 6ell K) contains the number of regular, non=overtime, hours per shift. Kere, the M indicates that a normal shift is M hours. 6ell <) contains the rate at which overtime hours are paid. The &.8 indicates that overtime is paid at time=and=a=half. The total hours are in column >. This is the difference between the start time in column 5 and the end time in column $. This value does not pay any attention to the time taken for lunch == we"ll do that later. The formula in >3 is% =(F4-*4+(F4/*4))(24 This formula subtracts the start time in 63 from the end time in $3. Then, it compares the end time to the start time. If $3 is less than, or earlier than, 63, the e pression (FI<%I) will evaluate to True or &. If not, it will evaluate to $alse or C. 4dding this comparison result will calculate the number of hours properly in the case where the start time is later in the day than the end time. This is e actly the situation with Emma. $inally, the result is multiplied by )3, to get the actual number of hours, rather than a time value == e.g., N.CC rather N%CC. (*ince times are stored as a fraction of a )3=hour day, multiplying a time by )3 will return the number of hours).
N81E .ou onl- nee3 to use the E(FI<%I)part of the formula 0hen the start an3 en3 times are ?ust times* 0ithout a 3ate@ &f -ou are entering a complete 3ate an3 time* then -ou 3on5t nee3 the comparison formula* because the 3ate part of the /alue 0ill allo0 E$cel to properl- calculate the 3ifference@

6olumn K contains the number of hours that were actually worked, after taking out the time taken for lunch. The formula in K3 is% =((F4-*4+(F4/*4))-(E4-D4+(E4/D4)))(24

This formula is very similar to the formula in >3, e pect that it subtracts the time between 13 and E3, the start and end times of the lunch break. 4gain, we compare the start and end times to ensure that the number of hours is calculated properly if the time period crosses midnight. -ook at Emma"s

hours again == she left for lunch at &&,' and returned at &)%2C 4'. 'ultiplying the result by )3 gives us the actual number of hours worked, rather than a time value. 6olumn I contains the number of regular hours worked by each employee. If the actual worked hours in column K is less than the 7egular Kours value in K), we want to use the actual number of worked hours. Kowever, if the actual worked hours in column K is greater than the 7egular Kours value in K), we only want to count K) hours as regular time. The formula in I3 is% =MIN(DHD2,H4) This formula simply takes the minimum of the allowed regular hours in K) and the number of hours actually worked in K3. 6olumn H contains the number of overtime hours for each employee. If the employee worked less than the allowed regular hours, the overtime hours will, of course, be Gero. Kowever, if they worked more than the allowed regular hours, the overtime hours will be the difference between the hours actually worked and the allowed regular hours. The formula in cell H3 is% =MA0(0,H4-DHD2) This is simply the ma imum of C and the difference between actual hours and allowed regular hours. 6olumn < is (ust the hourly wage for each employee. Of course, these may be different for each employee, but they are the same in our e ample. 6olumn - is the amount of regular, non=overtime wages paid. This is (ust the product of column I, the regular hours, and column <, the hourly wage. 6ell -3 has the formula% =I4(K4 6olumn ' is the amount of overtime wages paid. This is the product of column H, the overtime hours, column <, the hourly wage, and cell <), the rate at which overtime hours are paid. 6ell '3 has the formula% =E4(K4(DKD2 $inally, column 0 is (ust the total wages paid, the sum of the regular and overtime wages. 6ell 03 has the formula% =)4+M4 The worksheet and formulas are summariGed below%

:ou can download a workbook with these formulas. ,dditional $esourcesHohn !alkenbach has an e ample timesheet here. 1avid 'c7itchie has an e ample timesheet here.
Sho0 1he Current Date &n ) Cell -ast week I showed you how to insert time and date stamps into your worksheets. Those were fi ed values. This weeks tip will show you how to add a date function to your worksheet that will update with the current date. The formula to show the current date is %18D).(,. One thing to keep in mind is, this formula will only update when the worksheet is recalculated or when you reopen the workbook. That"s usually not a problem since the date only changes once a day. 4lso, you may have to format the cell to give you your desired date format. If you"d like to show the current time, you can use the formula %N8W(,. This formula gives you both the date and time in the same cell (i.e. &N= 'ay=C2 N%CCpm), however, is less useful because the time in the cell won"t change until your worksheet recalculates or when you reopen your workbook. If you (ust want the cell to display the time only, you"ll have to change the number format by selecting 'ormat* Cells* Number* 1ime* (select a desired time format), 8A.

Summing time /alues that are separate3 into hours an3 minutes in 3ifferent columns

,roblem% 6olumns 5%6 contains numbers representing hours and minutes accordingly. Kow could we sum up the numbers in both columns to a single time value# *olution% To get a time value representing the sum of hours and minutes in columns 5%6 use the following 4rray $ormula% TA*.'(TI'E(5&)%5&3,6&)%6&3,C))U E ample% KoursOOO'inutes

8OOOOOOO)C ;OOOOOOO8C 2OOOOOOO&C 7esult% &8%)C $ormula% TA*.'(TI'E(5&)%5&3,6&)%6&3,C))U 0otes% To perform an 4rray $ormula% Insert the formula, press $) and then press 6trlQ*hiftQEnter simultaneously. The format in the cell contains formula is%VKK%''W

E$cel 'unctions 1e$t* )bs an3 number or 3ate formats


The Te t and "F" functions are very useful for including cell values within meaningful sentences which can be understood by a layman. *tatements can be constructed which combine words and numeric values (e.g. +The budget for )pril is B"C*+++ o/erspent+). The "F" symbol is not strictly a function. It is an operator which can be used to (oin together two strings or pieces of te t. $or e ample% %D1he /ariance is D E D" where cell 1) contains either +4dverse+ or +$avourable+. If you (oin together a piece of te t and a number or date the appearance and formatting of the number can be unpredictable unless you use the Te t function. The Te t function converts a number into te t and also formats it to the re9uired appearance. It takes the structure% %1EF1(/alue* D'ormatCo3eD,. The complicated aspect of this function is understanding the $ormat6odes. *ome of them are shown in the following e ample and tables. 4lternatively use E cel help and search for "$ormatting numbers % 6ustom formats". The 4bs function changes negative values to positive. % )7S(/alue,

cell '2 cell '3 cell <; cell <&& cell <&) cell <&2

A 0O!() te t entered by user A+Out ,atient 4ctivity% + F '3 A'3 F + has undertaken + F TELT(45*(-N),+C+) F I$(-NDC,+ less+, + more+) F + episodes+ A+This represents + F I$(-NDC,+ an adverse+, + a favourable+) F + variance of + F TELT(45*(-NE-?),+C.CX+) A+7eporting month% + F TELT('2,+mmmm yyyy+) $ormulae used in the e ample

E amples of $ormat 6odes

0ote that the e9uivalent function to Te t in 4ccess is called "$ormat".

These format codes give a flavour of how numbers can be displayed as te t. If you want to format the appearance of numeric, date or te t values in cells and retain their original data type use the menu command $ormat / 6ells / 0umbers and make your choice. .nfortunately many of the default formats within E cel are useless and you may be advised to create your own custom formats = either see the section on 6onfiguring E cel or use the 6ustom number category in the format cells dialog bo (right). 1ates and times in E cel are stored as numbers (e.g. 2;82;.?NN). These numbers sometimes appear une pectedly when cell formats have been accidentally changed. :ou may change the cell number formatting to replace the numbers with a more conventional appearance such as "&&EC&E)CCC". To change a number format back to a date, select the re9uired range of cells and then choose $ormat / 6ells / 0umber 6ategory% 1ate. If a cell value une pectedly appears as a series of hashes (P) as in cell $) (see diagram to the right) this is probably due to the column being too narrow to display the value in the selected format. Try widening the column by moving the cursor to the faint line between the column titles and then dragging it to an appropriate siGe (or use $ormat / 6olumn / !idth).

Using the '82EC)S1 'unction


The $O7E64*T function can be used whenever you have an e isting set of data pairs ( =values and y=values) and you want to calculate an estimated y=value to a new =value. E cel performs a linear regression based on the e isting values and then inserts the =values into the e pression for the regression which gives you an y=value. The new =value can have any value and is not restricted to be larger than the e isting =values. The $O7E64*T function uses the following synta %
=F#RE%AS&(1, ;,ange, 1,ange)

In this usage, L is the L value for which you want $O764*T to return a : value. The :range and Lrange parameters are sets of know : and L values. 4s and e ample, let"s say that you are going on a diet, and you decide to keep track of your weight each day. Every day you enter the date into column 4 and the weight for that day in column 5. 4fter getting about &C days or so of measurements, you can use these data pairs to forecast when you will hit your target weight. If your target weight is &;C lbs., you could use the following formula%
=F#RE%AS&(1J , A0=A11, (0=(11)

The result is the anticipated date when you will reach the target weight. E cel calculates the +trend line+ (using linear regression) of the points in 4)%5&& (i.e., it assumes there is a linear relationship between the dates and the weights. (This trend line is the same as you would get from plotting the data pairs and adding a trend line to the chart.)

E/alute 'unction
4 user had cells with contents likeY 4&A )&Q;NQMNQ)8Q2& 4)A )&R)8 42A &CCE&C 43A &CCE&CR(&CR&CQ&C) 48A &CCE&CR&CR&CQ&C 0one of these cells had an e9ual sign and as such the cells were seen as Te t by E cel. The person wanted to leave the original cell contents intact and use 6olumn 5 to return the result of the e9uations. The usual suspect of A +A+F4& was tried in cell 5& but only resulted in 5& showing A)&Q;NQMNQ)8Q2& and 0OT evaluating the formula. It was at this point the word EJ4-.4TE came into my mind. 4t first I tried AEJ4-.4TE(4&). E cel did not like this and came back with an error message +That $unction is not valid+. 4fter this, the penny dropped fully I remembered how it had to be done. *ee the steps below

&) *elect cell 5& )) >o to InsertB0ameB1efine 2) Type the name 7esult (can be any valid range name) 3) In the 7efers to% bo type% AEJ4-.4TE(Z4&) 8) 6lick 4dd then O<. It is very important to note that I selected cell 5& and used a 7elative 7ow reference for Z4&. I then simply entered A7esult into cell 5& and copied it down and it workedI It even obeys the use of ,arenthesis as in the case of% &CCE&CR(&CR&CQ&C) 4 user had cells with contents likeY 4&A )&Q;NQMNQ)8Q2& 4)A )&R)8 42A &CCE&C 43A &CCE&CR(&CR&CQ&C) 48A &CCE&CR&CR&CQ&C 0one of these cells had an e9ual sign and as such the cells were seen as Te t by E cel. The person wanted to leave the original cell contents intact and use 6olumn 5 to return the result of the e9uations. The usual suspect of A +A+F4& was tried in cell 5& but only resulted in 5& showing A)&Q;NQMNQ)8Q2& and 0OT evaluating the formula. It was at this point the word EJ4-.4TE came into my mind. 4t first I tried AEJ4-.4TE(4&). E cel did not like this and came back with an error message +That $unction is not valid+. 4fter this, the penny dropped fully I remembered how it had to be done. *ee the steps below &) *elect cell 5& )) >o to InsertB0ameB1efine 2) Type the name 7esult (can be any valid range name) 3) In the 7efers to% bo type% AEJ4-.4TE(Z4&) 8) 6lick 4dd then O<. It is very important to note that I selected cell 5& and used a 7elative 7ow reference for Z4&. I then simply entered A7esult into cell 5& and copied it down and it workedI It even obeys the use of ,arenthesis as in the case of% &CCE&CR(&CR&CQ&C) ,nyway, a newsletter subscriber (named .raham .idney) emailed me and showed me yet another way. /n fact, his way is even easier0 ,ll you need to do is enter 1 2123,! into 4!, copy down to 45, then select 4!-45 and &opy, then *dit67aste )pecial ' 8alues. Thanks to .raham for this very %uick and easy way.

E$cel DSum 'unction

In E cel, the DSum function sums the numbers in a column or database that meets a given criteria. The synta for the DSum function is%

1*um( range, field, criteria ) range is the range of cells that you want to apply the criteria against. field is the column to sum the values. :ou can either specify the numerical position of the column in the list or the column label in double 9uotation marks. criteria is the range of cells that contains your criteria.

$or e ample% -et"s take a look at an e ample%

5ased on the E cel spreadsheet above% A1*um(43%1M, +.nit 6ost+, 4&%5)) A1*um(43%1M, 2, 4&%5)) A1*um(43%1M, +@uantity+, 4&%4)) A1*um(43%1M, ), 4&%4)) Using Name3 2anges :ou can also use a named range in the 1*um function. $or e ample, we"ve created a named range called orders that refers to *heet&IZ4Z3%Z1ZM. would return ?.NN would return ?.NN would return )C would return )C

Then we"ve entered the following data in E cel%

5ased on the E cel spreadsheet above% A1*um(orders, +Total 6ost+, 4&%5)) A1*um(orders, 3, 4&%5)) would return ;C.MM would return ;C.MM

To view named ranges% .nder the Insert menu, select 0ame B 1efine.

A 14JE74>E(42%6N, 2, E2%E3) A 16O.0T(42%6N,+4ge+, E2%$3)

3).;? )

in cell 1&& in cell 1&)

C"ange 'or!ulas to (alues


)on #e *ru+n (last update /1 march >??9) 5o to the Excel tips page

Instead of PasteSpecial PasteValues) I use the 2alue property in the examples. &ee the Excel help if you want to use 7aste&pecial.

T"+s ,+ll c"ange all t"e cells +n t"e Act+(e-"eet to (alues &ub 3aluesE1() (ith Acti2e&heet.Csed4ange .3alue . .3alue End (ith End &ub

T"+s ,+ll c"ange only t"e Current)eg+on o' t"e Act+(eCell to (alues &ub 3aluesE>() (ith Acti2e%ell.%urrent4egion .3alue . .3alue End (ith End &ub

T"+s ,+ll c"ange all cells +n a range to (alues

his will not wor! correct on a range with more then one Area. &ub 3aluesE/() 4ange(1A1"-11).3alue . 4ange(1A1"-11).3alue End &ub For a range ,+t" !ore t"en Area use t"+s &ub 3aluesE,() -im smallrng As 4ange +or Each smallrng In 4ange(1a1"c1?)e1>"g161).Areas smallrng.3alue . smallrng.3alue 0ext End &ub T"+s ,+ll c"ange so!e cells +n t"e Act+(ecell ro,

his will change the cells in the columns A"- to 2alues In the Acti2e%ell.4ow &ub 3aluesE9() (ith Acti2e&heet.4ange(%ells(Acti2e%ell.4ow) 1A1)) %ells(Acti2e%ell.4ow) 1-1)) .3alue . .3alue End (ith End &ub T"+s ,+ll c"ange a )o, or )o,s to (alues &ub 3aluesE@() 4ows(111).3alue . 4ows(111).3alue End &ub &ub 3aluesE6() 4ows(11"/1).3alue . 4ows(11"/1).3alue End &ub T"+s ,+ll c"ange a Colu!n or Colu!ns to (alues &ub 3aluesE<() %olumns(1A1).3alue . %olumns(1A1).3alue End &ub

&ub 3aluesE;() %olumns(1A"%1).3alue . %olumns(1A"%1).3alue End &ub T"+s ,+ll c"ange t"e select+on ,+t" one or !ore areas to .alues &ub 3aluesE1?() -im smallrng As 4ange +or Each smallrng In &election.Areas smallrng.3alue . smallrng.3alue 0ext End &ub

Kome

E cel Tips

*ample *preadsheets

E$cel ;; Worksheet 'unctions ;; VLookup


*elect a -ocation for a -ookup Table 6reate a -ookup table J-OO<., $unction 4rguments 6reate a J-ookup formula 6reate a J-ookup formula for a range of values 6ombine I$ and J-OO<., Troubleshoot the J-OO<., formula In a workbook, you can create a table that stores information about your products, or employees, or other data you want to refer to fre9uently. $rom other cells in the workbook, you can use formulas to look up data from the master table. Select a Location for a Lookup 1able It"s a good idea to store each lookup table on a separate worksheet in the workbook. Then, as you add and delete rows in the lookup tables, you won"t accidentally add or delete rows in any other table. In this e ample, the lookup table is on a sheet named Products. Create a Lookup 1able -ookup formulas can work vertically, looking for 4 ) 4)2 2 5&3 3 4)? 8 638 ; 5
,aper -amp 1esk ,encil

1ownload sample workbook

6
8.CC &8.CC ?8.CC C.8C

& Co3e Pro3uct Price

values down a column, or they can work horiGontally, looking for values across a row. In this e ample, the information will be stored vertically, with values down a column. &. Enter the headings in the first row ). The first column should contain the uni9ue key values on which you will base the lookup. In this e ample, you can find the price for a specific product code. 2. If you have other data on the worksheet, leave at least one blank row at the bottom of the table, and one blank column at the right of the table, to separate the lookup table from the other data. 0ote% To make it easier to refer to the table, you can name the range. There are instructions here% 0aming a 7ange VL88AUP 'unction )rguments The J-OO<., function has four arguments%

&. lookupG/alue% That value do you want to look up# In this e ample, the product code is in cell 4?, and you want to find its product name. ). tableGarra-% !here is the lookup table# If you use an absolute reference (Z4Z)%Z6Z8), instead of a relative reference (4)%68), it will be easier to copy to formula to other cells. Or, name the lookup table, and refer to it by name. 2. colGin3e$Gnum% !hich column has the value you want returned# In this e ample, the product names are in the second column of the lookup table. 3. HrangeGlookupI% 1o you want an e act match# Is an appro imate match okay# If you use T7.E as the last argument, or omit the last argument, an appro imate match can be returned. This e ample has $4-*E as the last argument, so if the product code is not found, the result will be P0E4. (0ote% E cel is rather forgiving, and will accept C instead of $4-*E, and & instead of T7.E.)

Create a VLookup formula

Once you have created the lookup table, you can create other formulas in the workbook, and pull information from the product list. $or e ample, to prepare an invoice, you can enter a product code, and formulas will get the product name or price from the product table. In this e ample, the invoice is created on a sheet named Invoice. The J-OO<., formula should find an e act match for the product code, and return the product name. &. *elect the Invoice sheet ). Enter product code 4)2 in cell 4? 2. In cell 5?, start the J-OO<., formula% AVL88AUP( 3. 6lick on cell 4? to enter its reference. 8. Type a comma, to end the first argument ;. *elect the ,roducts sheet ?. *elect cells 4)%68 (the product list) M. ,ress the $3 key, to change the cell references to absolute. The formula should now look like this% %VL88AUP()J*Pro3uctsKL)L" LCL: N. Type a comma to end the second argument. &C. Type a ", which is the column in the lookup table that contains the ,roduct name. &&. Type a comma to end the third argument. &). Type ')LSE, to specify that an e act match for the product code is found, and add the closing bracket. &2. The formula should now look like this% %VL88AUP()J*Pro3uctsKL)L" LCL:*"*')LSE, &3. ,ress the Enter key to complete the formula. The product name will be displayed. Note% To return the product price, create a J-OO<., formula that refers to column 2 of the lookup table. $or e ample, enter the following formula in cell 6?% %VL88AUP()J*Pro3uctsKL)L" LCL:*C*')LSE,

Create a VLookup formula for a range of /alues In some situations, an appro imate match is preferred, so several values will return the same result. $or e ample, when grading student papers, all papers with a grade of M8 or over should receive an 4 grade. In this e ample, the lookup table is created on a sheet named Grades. To create the lookup table, enter the minimum score for each grade in column 4. Enter the matching >rade in column 5. Sort the Scores in )scen3ing or3er@ 6ells 4)%5; were named .rade9ist. The scores are entered on a sheet named Re ort Card, where a J-OO<., formula calculates the grade. &. On the 7eport 6ard sheet, in cell 53, enter the score ??. ). In cell 63, enter the J-OO<., formula% AJ-OO<.,(53,>rade-ist,)) 2. ,ress the Enter key, and the grade for English is returned.

4 & ) 2 3 8 ;
Score C 8C ;C ?8 M8

5
Mra3e $ 1 6 5 4

bine &' an3 VL88AUP can use an I$ formula with J-ookup to return e act values if found, and an empty string if not found. . On the Invoice sheet, in cell 4M, enter the product code 4)M. If the J-ookup formula in cell 5M has $4-*E as the fourth argu NNO), because there is no e act match for the product code in the lookup table. . !rap the J-ookup formula with an I$ formula (in this e ample the product list has been named)% %&'(&SN)(VL88AUP()P*Pro3uctList*"*')LSE,,*DD*VL88AUP()P*Pro3uctList*"*')LSE,, . ,ress the Enter key, and cell appears blank. 5ecause no e act match was found, the J-ookup formula returned an P0E4. The converted this to an empty string.

ember that E cel performs the deepest nested function first, so looking at the formula above, you will see%

The first thing E cel does is perform the first J-OO<., (since that"s the one that is nested deepest) Then it performs the I*04 function on the result of the J-OO<., to see if the J-OO<., gave a P0E4 error or not. The I* returns a value of true if it sees the P0E4 error and a value of false if it doesn"t

Then E cel performs the I$ function on the result of the I*04 function. If it sees a +true+, it returns nothing (which is what th +false+, it returns the result of the J-OO<., function, which is what the last J-OO<., function is telling it to do if the val

he formula below is drafted in a slightly different way. In it in first vlookup it is asking to retrieve value from first column of tab e t vlookup asks it to retrieve the value from second column of table array.

her pointer for suppressing NNO) error

88AUP(lookupG/alue*tableGarra-*colGin3e$Gnum*rangeGlookup, n!e"looku can be TR#E or $AL%E& if omitted t'e default is TR#E

88AUP 0ill 0ork 0ith a list 0here the table arguments are sorte3* an3 -ou 0ill get the closest match to a table argument e3 -our lookup /alue@ sorte3 lists use 12UE or 3efault for a QcloseQ match,

88AUP 0ill 0ork 0ith a list 0here the arguments are unor3ere3* an3 -ou either get an e$act match or fail 0ith NNO)K@ ether sorte3 or not 0hen an Qe$actQ match is require3 so is the use of ')LSE,

uppress NO) errors &SN)(VL88AUP(@@@*@@@*@@@*'alse,,*D&tem not foun3D*VL88AUP(@@@*@@@*@@@*'alse,,

use of NV)LUEK error is a 6ero /alue for colGin3e$Gnum /alue in the function@

ot mi$ cells 3efine3 as numbers 0ith cells 3efine3 as te$t in the argument column of -our table@ Some tips on 3eterminin al content of -our 3ata@ .our table must be consistent* but -our lookup /alue can be force3 to look like the table b- using ese tricks (Peo S?oblom C++C;+!;!:,@
=1)OOKUC(TE0T(A1,:00000:),T,F7.,2,FA)SE) 64 =1)OOKUC(A1+0,T,F7.,2,FA)SE)

lookup table contains any blank cells, a J-OO<., formula will return a Gero, instead of a blank cell. :ou can use nested I$s t ts, and the empty cell results. $or e ample% &'(&SN)(VL88AUP()P*Pro3uctList*"*')LSE,,*DD* &'(VL88AUP()P*Pro3uctList*"*')LSE,%DD*DD* VL88AUP()P*Pro3uctList*"*')LSE,,,

1roubleshoot the VL88AUP formula :our J-OO<., formula may return an P0E4, even though the value you"re looking for appears to be in the lookup table. 1e$t /s@ Number 4 common cause for this error is that one of the values is a number, and the other is te t. $or e ample, the lookup table may contain 5!"C (te t), and the value to look up is !"C (a number). If possible, convert the te t to numbers, using one of the methods shown here% 6onvert Te t to 0umbers If you can"t convert the data, you can convert the lookup value within the J-OO<., formula% Lookup /alues are 1e$t* an3 the table contains Numbers If the lookup table contains numbers, and the value to look up is te t, use a formula similar to the following% %VL88AUP(==)J*Pro3uctsKL)L" LCL:*C*')LSE, The double unary (==) converts te t to a number, and will work correctly even if the lookup values are numbers. Lookup /alues are Numbers* an3 the table contains 1e$t If the lookup table contains te t, and the value to look up is numeric, use a formula similar to the following% %VL88AUP()J E DD,*Pro3uctsKL)L" LCL:*C*')LSE, O7 %VL88AUP(1EF1()J*D+++++D,*Pro3uctsKL)L" LCL:*C*')LSE, The TELT function converts a number to te t, and will work correctly even if the lookup values are te t. In the first e ample, the F operator creates a te t string from an unformatted

number. In the second e ample, a number formatted with leading Geros (e.g. CC&)2) would match a te t +number+ with leading Geros. Spaces in one /alue* an3 not the other 4nother potential cause for no matching value being found is a difference in spaces. One of the values may contain leading spaces (or trailing, or embedded spaces), and the other doesn"t. To test the values, you can use the -E0 function, to check the length of each value. $or e ample% %LEN()J, will return the number of characters in cell 4?. It should be e9ual to the number of characters in the matching cell in the lookup table. If possible, remove the unnecessary spaces, and the J-OO<., formula should work correctly. If you can"t remove the spaces, use the T7I' function in the J-OO<.,, to remove leading, trailing or duplicate spaces. $or e ample% %VL88AUP(12&#()J,*Pro3uctList*"*')LSE,

E$cel Easter Eggs


1his is ?ust one of the man- Easter Eggs -ou can get from EEMMS@C8#@ &f -ou like these kin3s of things* & recommen3 -ou go there an3 fin3 some more@ (1hese instructions come from this 0ebsite@,

6ar racing game%


5oot E$cel "+++ .nder file menu, do "*ave as !eb ,age". *ay ",ublish *heet" and "4dd Interactivity" *ave to some htm page on your drive. -oad the htm page with IE. :ou should have E cel in the middle of the page. *croll to row )CCC, column !6. *elect row )CCC, and tab so that !6 is the active column. Kold down *hiftQ6rtlQ4lt and click the Office logo in the upper=left.

If you have 1irectL, you will be playing what looks like spy hunter. .se the arrow keys to drive, space to fire, O to drop oil slicks, and when it gets dark, use K for your headlights.

0ote% 0ot everyone has been able to make this work and I"m researching why. $or e ample, it works when I try it at school using IE8, but not when I try it at home, using IE 8.8. 4t home, I get a 'icrosoft !eb 6omponents bo . (#) It"s possible it"s because I run ,ersonal !eb *erver (for $ront,age)## I also have the Office )k *7=& patch and maybe this is stopping it# Or, perhaps it"s because my home computer is on a cable modem network and therefore, always connected to the internet# 5ut, for those of you who can do it.....have funII If you have problems getting it to work and figure them out, let me know so I can pass the info onto others. $or those of you still using E$cel 9J, and haven"t yet found its Easter Egg, try this and you will get a flight simulator%

Open a new workbook ,ress $8 Enter LN?%-N? and press Enter ,ress Tab once, to move to column ' Kold 6ontrol and *hift, then right=click the 6hart !iGard icon on the *tandard toolbar

Вам также может понравиться