Calculate the number of months between two dates

advertisement
Calculate the number of months between two dates
To do this task, use the MONTH and YEAR functions.
Example
A
Date
1
2
3
6/9/2007
9/2/2007
12/10/2008
Formula
Description (Result)
=MONTH(A3)-MONTH(A2)
Months occurring between two dates in the same year (3)
4
=(YEAR(A4)-YEAR(A3))*12+MONTH(A4)-MONTH(A3)Months occurring between two dates over a year apart (15)
NOTE
To view the dates as numbers, select the cell and click Cells on the Format menu. Click the Number tab, and then click Number in the Category box.
Calculate the number of years between two dates
To do this task, use the YEAR function.
Example
A
Date
6/9/2007
6/4/2010
Formula
Description
(Result)
=YEAR(A3)YEAR(A2)
Years occurring
between two dates
(3)
Add or change the header or footer text in Page Layout view
Click the worksheet that you want to add headers or footers, or that contains headers or footers that you want to change.
1.
On the Insert tab, in the Text group, click Header & Footer.
NOTE
2.
Excel displays the worksheet in Page Layout view. You can also click Page Layout View
on the status bar to display this view.
Do one of the following:

To add a header or footer, click the left, center, or right header or footer text box at the top or the bottom of the worksheet page (under Header or
above Footer).

3.
To change a header or footer, click the header or footer text box at the top or the bottom of the worksheet page, and then select the text that you
want to change.
Type the new header or footer text.
NOTES


To start a new line in a header or footer text box, press Enter.

To include a single ampersand (&) in the text of a header or footer, use two ampersands. For example, to include "Subcontractors & Services" in a header, type
Subcontractors && Services.

To close the headers or footers, click anywhere in the worksheet. To close the headers or footers without keeping the changes that you made, press Esc.
To delete a portion of a header or footer, select the portion that you want to delete in the header or footer text box, and then press Delete or Backspace. You can
also click the text, and then press Backspace to delete the previous characters.
Add or change the header or footer text in the Page Setup
dialog box
1.
Click the worksheet or worksheets, chart sheet, or embedded chart to which you want to add headers or footers, or that contains headers or footers that you
want to change.
TO SELECT
A single sheet
DO THIS
Click the sheet tab.
If you don't see the tab that you want, click the tab scrolling buttons to display the tab, and then click the tab.
Two or more adjacent sheets
Click the tab for the first sheet. Then hold down Shift while you click the tab for the last sheet that you want to select.
Two or more nonadjacent sheets Click the tab for the first sheet. Then hold down Ctrl while you click the tabs of the other sheets that you want to select.
All sheets in a workbook
Right-click a sheet tab, and then click Select All Sheets on the shortcut menu.
2.
On the Page Layout tab, in the Page Setup group, click the Dialog Box Launcher
.
Excel displays the Page Setup dialog box.
TIP If you select a chart sheet or embedded chart, clicking Header & Footer in the Text group on the Insert tab also displays the Page Setup dialog
box.
3.
4.
5.
On the Header/Footer tab, click Custom Header or Custom Footer.
Click in the Left section, Center section, or Right section box, and then click the buttons to insert the header or footer information that you want in that
section.
To add or change the header or footer text, type additional text or edit the existing text in the Left section, Center section, or Right section box.


To start a new line in a section box, press Enter.

To include a single ampersand (&) in the text of a header or footer, use two ampersands. For example, to include "Subcontractors & Services" in a header, type
Subcontractors && Services.

To base a custom header or footer on an existing header or footer, click the header or footer in the Header or Footer box.
To delete a portion of a header or footer, select the portion that you want to delete in the section box and then press Delete or Backspace. You can also click the
text, and then press Backspace to delete the previous characters.
Add a built-in header or footer
Excel has many built-in headers and footers that you can use. For worksheets, you can work with headers and footers in Page Layout view. For other sheet types
such as chart sheets, or for embedded charts, you can work with the headers and footers in the Page Setup dialog box.
Add a built-in header or footer to a worksheet in Page Layout view
1.
2.
Click the worksheet to which you want to add a predefined header or footer.
On the Insert tab, in the Text group, click Header & Footer.
NOTE Excel displays the worksheet in Page Layout view. You can also click Page Layout View
3.
on the status bar to display this view.
Click the left, center, or right header or footer text box at the top or the bottom of the worksheet page.
TIP Clicking any text box selects the header or footer and displays the Header and Footer Tools, adding the Design tab.
4.
On the Design tab, in the Header & Footer group, click Header or Footer, and then click the predefined header or footer that you want.
Add a built-in header or footer to a chart
1.
2.
Click the chart sheet or embedded chart to which you want to add a predefined header or footer.
On the Insert tab, in the Text group, click Header & Footer.
NOTE
3.
Excel displays the Page Setup dialog box.
Click the predefined header or footer that you want to use in the Header or Footer box.
Add built-in elements in a header or footer
Instead of picking a built-in header or footer, you can just choose a built-in element. Many (Page Number, File Name, Current Date, etc.) are found in the ribbon.
For worksheets, you can work with headers and footers in Page Layout view. For other sheet types such as chart sheets, or for embedded charts, you can work
with headers and footers in the Page Setup dialog box.
Insert built-in header and footer elements for a worksheet
1.
2.
Click the worksheet to which you want to add specific header or footer elements.
On the Insert tab, in the Text group, click Header & Footer.
NOTE Excel displays the worksheet in Page Layout view. You can also click Page Layout View
3.
on the status bar to display this view.
Click the left, center, or right header or footer text box at the top or the bottom of the worksheet page.
TIP Clicking any text box selects the header or footer and displays the Header and Footer Tools, adding the Design tab.
4.
On the Design tab, in the Header & Footer Elements group, click the elements that you want.
Insert built-in header and footer elements for a chart
1.
2.
Click the chart sheet or embedded chart to which you want to add a predefined header or footer.
On the Insert tab, in the Text group, click Header & Footer.
NOTE Excel displays the Page Setup dialog box.
3.
4.
Click Custom Header or Custom Footer.
Use the buttons in the Header or Footer dialog box to insert specific header and footer elements.
TIP When you rest the mouse pointer on a button, a ScreenTip displays the name of the element that the button inserts.
Choose header and footer options
For worksheets, you can work with headers and footers in Page Layout view. For other sheet types such as chart sheets, or for embedded charts, you can work
with headers and footers in the Page Setup dialog box.
Choose the header and footer options for a worksheet
1.
2.
Click the worksheet for which you want to choose header and footer options.
On the Insert tab, in the Text group, click Header & Footer.
NOTE Excel displays the worksheet in Page Layout view. You can also click Page Layout View
3.
on the status bar to display this view.
Click the left, center, or right header or footer text box at the top or the bottom of the worksheet page.
TIP Clicking any text box selects the header or footer and displays the Header and Footer Tools, adding the Design tab.
4.
On the Design tab, in the Options group, check one or more of the following:

To remove headers and footers from the first printed page, select the Different First Page check box.
To specify that the headers and footers on odd-numbered pages should differ from those on even-numbered pages, select the Different Odd & Even Pages
check box.

To specify whether the headers and footers should use the same font size and scaling as the worksheet, select the Scale with Document check box.
TIP To make the font size and scaling of the headers or footers independent of the worksheet scaling, which helps create a consistent display across multiple
pages, clear this check box.

To make sure the header or footer margin is aligned with the left and right margins of the worksheet, select the Align with Page Margins check box.
TIP To set the left and right margins of the headers and footers to a specific value that is independent of the left and right margins of the
worksheet, clear this check box.
Choose the header and footer options for a chart
1.
2.
Click the chart sheet or embedded chart to which you want to add a predefined header or footer.
On the Insert tab, in the Text group, click Header & Footer.
NOTE Excel displays the Page Setup dialog box.
3.
Select one or more of the following:

To remove headers and footers from the first printed page, select the Different first page check box.
To specify that the headers and footers on odd-numbered pages should differ from those on even-numbered pages, select the Different odd & even pages
check box.

To specify whether the headers and footers should use the same font size and scaling as the worksheet, select the Scale with document check box.
TIP To make the font size and scaling of the headers or footers independent of the worksheet scaling, which helps create a consistent display across multiple
pages, clear the Scale with Document check box.

To guarantee that the header or footer margin is aligned with the left and right margins of the worksheet, select the Align with page margins check box.
TIP To set the left and right margins of the headers and footers to a specific value that is independent of the left and right margins of the
worksheet, clear this check box.
Close headers and footers
To close the header and footer, you must switch from Page Layout view to Normal view.

On the View tab, in the Workbook Views group, click Normal.
TIP You can also click Normal
on the status bar.
Remove the header or footer text from a worksheet
1.
On the Insert tab, in the Text group, click Header & Footer.
NOTE
2.
Excel displays the worksheet in Page Layout view. You can also click Page Layout View
Click the left, center, or right header or footer text box at the top or the bottom of the worksheet page.
on the status bar to display this view.
TIP Clicking any text box selects the header or footer and displays the Header and Footer Tools, adding the Design tab.
3.
Press Delete or Backspace.
NOTE If you want to delete headers and footers for several worksheets instantly, select the worksheets, and then open the Page Setup dialog box. To
delete all headers and footers instantly, on the Header/Footer tab, select (none) in the Header or Footer box.
Create a new workbook
Excel documents are called workbooks. Each workbook has sheets, typically called spreadsheets. You can add as many sheets as you want to a workbook, or you
can create new workbooks to keep your data separate.
1.
2.
Click File > New.
Under New, click the Blank workbook.
Enter your data
1.
Click an empty cell. For example, cell A1 on a new sheet.
Cells are referenced by their location in the row and column on the sheet, so cell A1 is in the first row of column A.
2.
3.
Type text or a number in the cell.
Press Enter or Tab to move to the next cell.
Use AutoSum to add your data
When you’ve entered numbers in your sheet, you might want to add them up. A fast way to do that is by using AutoSum.
1.
2.
Select the cell to the right or below the numbers you want to add.
Click Home > AutoSum, or press Alt+=.
AutoSum adds up the numbers and shows the result in the cell you selected.
Create a simple formula
Adding numbers is just one of the things you can do, but Excel can do other math too. Try some simple formulas to add, subtract, multiply or divide your numbers.
1.
2.
Pick a cell and type an equal sign (=). That tells Excel that this cell will contain a formula.
Type a combination of numbers and calculation operators, like the plus sign (+) for addition, the minus sign (-) for subtraction, the asterisk (*) for multiplication, or
the forward slash (/) for division.
For example, enter =2+4, =4-2, =2*4, or =4/2.
3.
Press Enter. That runs the calculation.
You can also press Ctrl+Enter if you want the cursor to stay on the active cell.
Apply a number format
To distinguish between different types of numbers, add a format, like currency, percentages, or dates.
1.
2.
Select the cells that have numbers you want to format.
Click Home > Arrow next to General.
3.
Pick a number format.
If you don’t see the number format you’re looking for, click More Number Formats.
Put your data in a table
A simple way to access a lot of Excel’s power is to put your data in a table. That lets you quickly filter or sort your data for starters.
1.
Select your data by clicking the first cell and dragging to the last cell in your data.
To use the keyboard, hold down Shift while you press the arrow keys to select your data.
2.
Click the Quick Analysis button
in the bottom-right corner of the selection.
3.
Click Tables, move your cursor to the Table button so you can see how your data will look. If you like what you see, click the button.
4.
Now you can play with your data: Filter to see only the data you want, or sort it to go from, say, largest to smallest. Click the arrow
in the table header of a
column.
To filter data, uncheck the Select All box to clear all check marks, and then check the boxes of the data you want to show in your table.
5.
6.
To sort the data, click Sort A to Z or Sort Z to A.
Show totals for your numbers
Quick Analysis tools let you total your numbers quickly. Whether it’s a sum, average, or count you want, Excel shows the calculation results right below or next to
your numbers.
1.
Select the cells that contain numbers you want to add or count.
2.
3.
Click the Quick Analysis button
in the bottom-right corner of the selection.
Click Totals, move your cursor across the buttons to see the calculation results for your data, and then click the button to apply the totals.
Add meaning to your data
Conditional formatting or sparklines can highlight your most important data or show data trends. Use the Quick Analysis tool for a Live Preview to try it out.
1.
Select the data you want to examine more closely.
2.
3.
Click the Quick Analysis button
that appears in the lower-right corner of your selection.
Explore the options on the Formatting and Sparklines tabs to see how they affect your data.
For example, pick a color scale in the Formatting gallery to differentiate high, medium, and low temperatures.
4.
When you like what you see, click that option.
Learn more about how to apply conditional formatting or analyze trends in data using sparklines.
Top of Page
Show your data in a chart
The Quick Analysis tool recommends the right chart for your data and gives you a visual presentation in just a few clicks.
1.
Select the cells that contain the data you want to show in a chart.
2.
3.
Click the Quick Analysis button
that appears in the lower-right corner of your selection.
Click Charts, move across the recommended charts to see which one looks best for your data, and then click the one that you want.
NOTE
Excel shows different charts in this gallery, depending on what’s recommended for your data.
Use AutoFill
Sometimes you need to enter a lot of repetitive information in Excel, such as dates, and it can be really tedious. But AutoFill can help.
1.
2.
3.
Type the first date in the series.
Put the mouse pointer over the bottom right-hand corner of the cell until it’s a black plus sign.
Click and hold the left mouse button, and drag the plus sign over the cells you want to fill. And Excel fills in the series for you automatically using the AutoFill
feature.
Use Flash Fill
Or say you have information in Excel that isn’t formatted the way you need it to be, such as this list of names. And going through the entire list manually to correct
them is daunting. Here, Flash Fill can help.
1.
2.
3.
Type the first name the way you want it.
Start to type the next name, and Excel provides a preview of the names formatted the way you want.
Press Enter, and Flash Fill fills in the names for you.
The AVERAGEIF function syntax has the following arguments:


Range

Average_range
Required. One or more cells to average, including numbers or names, arrays, or references that contain numbers.
Criteria Required. The criteria in the form of a number, expression, cell reference, or text that defines which cells are averaged. For example, criteria can be
expressed as 32, "32", ">32", "apples", or B4.
Optional. The actual set of cells to average. If omitted, range is used.
Remarks






Cells in range that contain TRUE or FALSE are ignored.

Average_range does not have to be the same size and shape as range. The actual cells that are averaged are determined by using the top, left cell in average_range
as the beginning cell, and then including cells that correspond in size and shape to range. For example:
If a cell in average_range is an empty cell, AVERAGEIF ignores it.
If range is a blank or text value, AVERAGEIF returns the #DIV0! error value.
If a cell in criteria is empty, AVERAGEIF treats it as a 0 value.
If no cells in the range meet the criteria, AVERAGEIF returns the #DIV/0! error value.
You can use the wildcard characters, question mark (?) and asterisk (*), in criteria. A question mark matches any single character; an asterisk matches any sequence
of characters. If you want to find an actual question mark or asterisk, type a tilde (~) before the character.
IF RANGE IS
AND AVERAGE_RANGE IS
THEN THE ACTUAL CELLS EVALUATED ARE
A1:A5
B1:B5
B1:B5
A1:A5
B1:B3
B1:B5
A1:B4
C1:D4
C1:D4
A1:B4
C1:C2
C1:D4
NOTE The AVERAGEIF function measures central tendency, which is the location of the center of a group of numbers in a statistical distribution. The three most
common measures of central tendency are:

Average which is the arithmetic mean, and is calculated by adding a group of numbers and then dividing by the count of those numbers. For example, the
average of 2, 3, 3, 5, 7, and 10 is 30 divided by 6, which is 5.

Median which is the middle number of a group of numbers; that is, half the numbers have values that are greater than the median, and half the numbers have
values that are less than the median. For example, the median of 2, 3, 3, 5, 7, and 10 is 4.

Mode
which is the most frequently occurring number in a group of numbers. For example, the mode of 2, 3, 3, 5, 7, and 10 is 3.
For a symmetrical distribution of a group of numbers, these three measures of central tendency are all the same. For a skewed distribution of a group of numbers,
they can be different.
Example
Example: Averaging property values and commissions
1
2
3
4
5
A
B
Property Value
Commission
100,000
7,000
200,000
14,000
300,000
21,000
400,000
28,000
Formula
Description (result)
=AVERAGEIF(B2:B5,"<23000")
Average of all commissions less than 23,000 (14,000)
=AVERAGEIF(A2:A5,"<95000")
Average of all property values less than 95,000 (#DIV/0!)
6
7
8
=AVERAGEIF(A2:A5,">250000",B2:B5)Average of all commissions with a property value greater than 250,000 (24,500)
9
Example: Averaging profits from regional offices
A
1
B
Region
Profits (Thousands)
2
East
45,678
3
West
23,789
4
North
-4,789
5
South (New Office)
0
MidWest
9,678
Formula
Description (result)
=AVERAGEIF(A2:A6,"=*West",B2:B6)
Average of all profits for the West and MidWest regions (16,733.5)
6
7
8
=AVERAGEIF(A2:A6,"<>*(New Office)",B2:B6)Average of all profits for all regions excluding new offices (18,589)
9
IF function
Description
The IF function returns one value if a condition you specify evaluates to TRUE, and another value if that condition evaluates to FALSE. For example, the formula
=IF(A1>10,"Over 10","10 or less") returns "Over 10" if A1 is greater than 10, and "10 or less" if A1 is less than or equal to 10.
Syntax
IF(logical_test, [value_if_true], [value_if_false])
The IF function syntax has the following arguments.

Logical_test Required. Any value or expression that can be evaluated to TRUE or FALSE. For example, A10=100 is a logical expression; if the value in cell A10 is
equal to 100, the expression evaluates to TRUE. Otherwise, the expression evaluates to FALSE. This argument can use any comparison calculation operator.

Value_if_true Optional. The value that you want to be returned if the logical_test argument evaluates to TRUE. For example, if the value of this argument is the
text string "Within budget" and the logical_test argument evaluates to TRUE, the IF function returns the text "Within budget." If logical_test evaluates to TRUE and
the value_if_true argument is omitted (that is, there is only a comma following the logical_test argument), the IF function returns 0 (zero). To display the word
TRUE, use the logical value TRUE for the value_if_true argument.

Value_if_false Optional. The value that you want to be returned if the logical_test argument evaluates to FALSE. For example, if the value of this argument is the
text string "Over budget" and the logical_test argument evaluates to FALSE, the IF function returns the text "Over budget." If logical_test evaluates to FALSE and
the value_if_false argument is omitted, (that is, there is no comma following the value_if_true argument), the IF function returns the logical value FALSE. If
logical_test evaluates to FALSE and the value of the value_if_false argument is blank (that is, there is only a comma following the value_if_true argument), the IF
function returns the value 0 (zero).
Remarks

Up to 64 IF functions can be nested as Value_if_true and Value_if_false arguments to construct more elaborate tests. (See Example 3 for a sample of nested IF
functions.) Alternatively, to test many conditions, consider using the LOOKUP, VLOOKUP, HLOOKUP, or CHOOSE functions. (See Example 4 for a sample of the
LOOKUP function.)


If any of the arguments to IF are arrays, every element of the array is evaluated when the IF statement is carried out.
Excel provides additional functions that can be used to analyze your data based on a condition. For example, to count the number of occurrences of a string of text
or a number within a range of cells, use the COUNTIF or the COUNTIFS worksheet functions. To calculate a sum based on a string of text or a number within a range,
use the SUMIF or the SUMIFS worksheet functions.
Data
50
Formula
Description
Live
Result
=IF(A2<=100,"Within
budget","Over
budget")
If the number in cell A2 is less than
or equal to 100, the formula returns
"Within budget." Otherwise, the
function displays "Over budget."
=IF(A2=100,A2+B2,"")
If the number in cell A2 is equal to
100, A2 + B2 is calculated and
returned. Otherwise, empty text ("")
is returned.
=IF(3<1,"OK")
If the result is False and no
value_if_false argument is provided
for the False result, FALSE is
returned.
=IF(3<1,"OK",)
If the result is False and a blank
value_if_false argument is provided
for the False result (a comma
follows the value_if_true
argument), 0 is returned.
Within
budget
FALSE
0
Download