Академический Документы
Профессиональный Документы
Культура Документы
S YS T E M
brahim MEECAN
http://book.zambak.com
ISBN: 978-605-112-034-8
Printed in Turkey
D I ST RI B U TI O N
Srat Basm Reklamclk ve Eitim
Aralar San. Tic. A..
Cumhuriyet Mah.
Haminne emesi Sok. No. 13
34696 skdar / STANBUL
_______________________
Tel : +90-216 522 09 10 (pbx)
Fax : +90-216 443 98 39
http://book.zambak.com
1. Spreadsheet Basics
Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Resizing and auto sizing rows columns: . . . . . 24
Screen Elements and Definitions . . . . . . . . . . . . . 8
Parts of Excel Screen That
You Need to Know . . . . . . . . . . . . . . . . . . . . . . . 9
The Ribbon . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Contextual Tabs. . . . . . . . . . . . . . . . . . . . . . . . . 11
Accessing the Ribbon using your keyboard . . . . 12
The Shortcut menus and the Mini Toolbar . . . . . 12
Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Formatting Tools . . . . . . . . . . . . . . . . . . . . . . . . . 36
Mouse Pointers . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Cell Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Number . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Alignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Font . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
Borders . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
Fill . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
Protection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
Document Themes . . . . . . . . . . . . . . . . . . . . . . . . 42
Using Styles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
Using Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
What is table? . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Creating a table . . . . . . . . . . . . . . . . . . . . . . . . . 44
Table AutoFormat . . . . . . . . . . . . . . . . . . . . . . . 44
Simple Functions: . . . . . . . . . . . . . . . . . . . . . . . . . 70
Sum Function . . . . . . . . . . . . . . . . . . . . . . . . . . 71
Conditional Formatting . . . . . . . . . . . . . . . . . . . . . 45
Average Function . . . . . . . . . . . . . . . . . . . . . . . 72
Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
Practice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
Word Search Puzzle . . . . . . . . . . . . . . . . . . . . . . . 51
Count Function . . . . . . . . . . . . . . . . . . . . . . . . . 73
All in One: Subtotal . . . . . . . . . . . . . . . . . . . . . . 74
Using Functions and Formulas. . . . . . . . . . . . . . . 76
Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
Logical Functions . . . . . . . . . . . . . . . . . . . . . . . 84
Statistical Functions . . . . . . . . . . . . . . . . . . . . . 85
Text Functions . . . . . . . . . . . . . . . . . . . . . . . . . . 89
Lookup & Reference Functions. . . . . . . . . . . . . 90
Database Functions . . . . . . . . . . . . . . . . . . . . . 93
Chart Tab . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
Sheet Tab . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
Print Preview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
Normal view and Page Layout View . . . . . . . . . 58
6. Data Processing
Print Preview . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
Print . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
Print Range . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
Comment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
7. Charts
Inserting Charts . . . . . . . . . . . . . . . . . . . . . . . . . . 120
Chart Tools: Design Tab. . . . . . . . . . . . . . . . . . . . 121
8. Extra Options
Data Validation . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
Data Validation Allow Options . . . . . . . . . . . . . 134
9. Macros
SPREADSHEET BASICS
1.1 Overview
Microsoft Excel is a very effective spreadsheet program enabling the user to
make calculations, prepare charts and manage data easily. When you have
large amount of data, numbers and calculations (accountancy documents,
personal info, marks and other info in a school, etc), its very easy to process
and get outputs from your data with a spreadsheet program like Microsoft
Excel.
Formula bar
Tab list
Columns
Name box
Rows
Active cell
indicator
Row Numbers
Sheet tabs
scroll buttons
Sheet tabs
Status bar
Page zoom
Microsoft Excel
Description
Cell
Active cell indicator
Rows
Microsoft Excel is made up of small boxes that are called cells. Each cell can have different
properties and store different data. All cells have different addresses or names like E5,
which means the cell in column E and row 5.
The dark outline around the selected cell indicates the currently active cell where you enter
new data or formula
Rows are listed on the left of an Excel worksheet. There are 1.048.576 rows and each row
contains 16.384 horizontally adjacent cells. You can click on a row number to select the
entire row.
Columns
Columns are represented by letters ranging from A to XFDone for each of the 16,384
columns in the worksheet. And these values (16,384 columns, 1,048,576 rows) cannot be
changed.
Worksheet
A worksheet contains both rows and columns (214 x 220 = 234 or 17.179.869.184 cells).
Having more rows and columns doesnt mean that you can actually use them all. If you
attempted to fill up all of the cells in a worksheet, you would soon run out of memory. The
advantage of having more rows and columns is the flexibility it provides.
Workbook
Each Excel file is called a workbook. A workbook is made up of worksheets. Each worksheet
is like a paper in the file (Workbook) that contains all formulas, links, and data in a tabular
format. Theoretically, a workbook can have as many worksheets as you want, but its not
suggested that you store too much information in a workbook. Its better to store it in different
but related files.
This button gives lots of options for working with your document or Excel in general.
Formula bar
When you enter information or formulas into cells, they appear here.
Name box
Displays the active cell address or the name of the selected cell, range, or object.
Change the way the worksheet is displayed: Page break preview, Page layout, Normal.
Tab list
Ribbon
The main location to find Excel commands. Clicking an item in the Tab list changes the
ribbon thats displayed.
Sheet tabs
Each of these tabs represents a different page (sheet) in the workbook. A workbook can
have any number of sheets, and each sheet has its name displayed.
Sheet tab scroll buttons These buttons let you scroll the sheet tabs to display tabs that arent visible.
Status bar
This bar displays various messages as well as the status of the Num Lock, Caps Lock, and
Scroll Lock keys on your keyboard. It also shows summary information about the selected
range of cells. Right-click the status bar to change the information thats displayed.
Zoom control
Spreadsheet Basics
1.3
The Ribbon
The Ribbon is one of the significant changes since Office 2007. We dont
have two different parts any more to access our commands; the Ribbon
combines the ease of toolbars together with functionality of menus.
Accessing the commands in the Ribbon is faster. The Ribbon is arranged into
groups of related commands. Heres a quick overview of Excel tabs.
Home: Youll probably spend most of your time with the Home tab selected.
This tab contains the basic Clipboard commands, formatting commands,
style commands, and commands to insert and delete rows or columns, plus
an assortment of worksheet editing commands
Insert: Select this tab when you need to insert something in a worksheet a
table, a diagram, a chart, a symbol, and so on.
Page Layout: This tab contains commands that affect the overall appearance
of your worksheet, including settings that deal with printing.
Formulas: Use this tab to insert a formula, name a range, access the formula
auditing tools, or control how Excel performs calculations.
Data: Excels data-related commands are on this tab.
Review: This tab contains tools to check spelling, translate words, add
comments, or protect sheets.
10
Microsoft Excel
View: The View tab contains commands that control various aspects of how
a sheet is viewed. Some commands on this tab are also available in the
status bar.
Developer: This tab isnt visible by default. It contains commands that are
useful for programmers. To display the Developer tab, open Excel options
from Office button and then select Customize Ribbon. Place a check mark
next to Developer Tab.
Add-Ins: This tab is visible only if youve loaded a workbook or add-in that
customizes the menu or toolbars. Because menus and toolbars are no longer
available in Excel, these customizations appear in the Add-Ins tab.
If you dont like to see this wide-spread toolbars all the time, you can (un)hide
them any time using Ctrl+F1 (or double click on any tab name). When the
commands are hidden, you can still access them, by just clicking on the tab
name.
Spreadsheet Basics
11
You dont need to hold down Alt key to access key tips. Just click Alt key
once then you can see and select your shortcut key.
Figure 1.6b:
Excel 2003 shortcut keys
Because new menus contain different shortcut keys, if you are used to
Excel 2003 shortcut keys, you can still access them. When you press a
shortcut key from Office 2003, it starts catching your shortcut key
sequence. And at the end, it executes the command. For example, in
Office 2003, Alt+O+C+H hides the selected columns. (Figure 1.6b)
Figure 1.7:
The Shortcut menus and Mini toolbar
If you dont like to see Mini toolbar every time you right click,
you can turn it off from the Office button Excel Options.
Uncheck the Show Mini Toolbar on selection option from
General tab.
Figure 1.8: Show/Hide Mini toolbar
12
Microsoft Excel
Spreadsheet Basics
Excel 2003
65.536
256
1 Gbytes
56
3
16
Excel 2007
1.048.576
16.384
Maximum allowed
4,3 billion
64
100
Excel 2010
1.048.576
16.384
Maximum allowed
4,3 billion
64
100
1.000
32.767
32.767
4.000
1.000
64.000
8.192
64.000
8.192
13
1.8
In this section, you will create a monthly growth project for a baby. Her mother
wants to see and analyze her growth. Every month, she kept height and
weight info in an Excel workbook.
The Baby Growth project will consist of three columns of information. Column
A will contain the month names, column B will store the height info and finally
column C will store the weight. You start by entering some descriptive titles
into the worksheet. Heres how to begin:
Move the active cell pointer to A1 and write Months then press enter
Write Height into B1 and Weight in C1
Then go to A2 and write the birth month of the baby: July
Figure a
When you drag your mouse down, youll see that itll write all the series of
the months until the cell at which you drop your mouse.
Next to months write the height and weight info into the cells as in the
figure on the next page.
Figure b
14
Microsoft Excel
Spreadsheet Basics
15
16
Microsoft Excel
Questions
1. What kind of program is Microsoft Excel?
a. Word processing
a. <Ctrl+F5>
b. Spreadsheet
c. Database
d. Graphics
d. <Ctrl+S>
b. Menu bar
b. xlsb
c. xlsx
d. exe
d. Status bar
1
3. Which of the following commands is not in
the Home tab?
a. Print Preview
b. Merge and center
b. 4
c. 5
d. 7
c. Copy
d. Increase font size
8. Which icon is used to print a worksheet or
chart?
4. Which of the following displays the cell
name?
a. 1
b. 8
c. 9
d. None
a. Formula bar
b. Status bar
c. Ribbon
d. Name box
Spreadsheet Basics
b. 3
c. 5
d. 6
17
b. 7
c. 8
d. 9
FALSE
d. 16384
18
Microsoft Excel
20
Microsoft Excel
21
On all of these options, after you reach to the end of a column or row, if you
again press the same key, the active cell goes automatically to the beginning
of the next column or row.
When you enter information in the same column Excel provides an easy tool:
AutoComplete. When you enter an item in a list Excel checks the rows above
it. If there is another item starting with the same characters, it completes the
rest of the word for you. If you want to enter a different word just continue. But,
if you want to enter the suggested word here, just press enter.
Example 2.1: Prepare your class list for informatics marks. Select the marks
as a range and enter marks for all students using Ctrl+Enter.
22
Microsoft Excel
3 1/2 and then press Enter. When you select the cell, 3.5 appears in the
Formula bar, and the cell entry appears as a fraction.
If you have a fraction only (for example, 18), you must enter a zero first, like
this: 0 1/8otherwise, Excel will likely assume that youre entering a date.
Figure 2.4:
Entering numbers with fractions
When you select the cell and look at the Formula bar, you see 0.125. In the
cell, you see 18.
23
2.3
If you select multiple rows (columns) with either the CTRL or SHIFT keys, and
then you change the height of one row, MS. Excel automatically applies the
same height to all other selected rows.
For auto sizing rows or columns, after you select your range, move your
mouse pointer to the right border of a row or column, when you see the
Resize mouse pointer, double click on it. You can also AutoFit the column
width for only the selected range: Home Cells Format AutoFit Column
Width.
To set the row height precisely, select the rows first and then select Row
Height from Format group. It will show you an input box. Instead of trying an
approximate value, you can write a fix value in pixels for the height or width.
When hiding rows or columns, they physically exist but their height or width is
made zero, so that they are not visible. Using the Resize mouse pointer, you
can set the width of a column to zero and hide it. Or, from the popup menu,
you can select the Hide command to do the same operation. Later, they can
be shown, using Format Hide & Unhide button in Cells group in Home Tab.
24
Microsoft Excel
When inserting cells, the process is similar to deletion. In order to add / open
new physical space, some cells need to be moved. You can move right, or
down, or you can insert an entire row or column. If you insert a row then all
the rows will be moved one down. If your last row contains data, it will ask you
to move this data into a different location or clear it and try again.
b. Rows or columns
There is another method to delete rows. After selecting the rows heading that
you want to delete, right click the selected area and select Delete. It will
directly delete the selected rows or columns.
Figure 2.8:
Paste special dialog box
Figure 2.9:
Paste special button options
25
1. None: No operation
2. Add: the source value is arithmetically added to the destination.
3. Subtract: The source value is subtracted from the destination.
4. Multiply: Multiplies the source and destination values.
5. Divide: Divides the destination by the source value.
Skip blanks: It doesnt paste anything over the destination if the source cell
is empty.
Transpose: Shifts the vertical and horizontal orientation of the cell range. If
your cells are horizontally adjacent, it will rotate them to a vertical list.
Paste Link: Pastes the cell link formula to the destination so that when you
change the source, the destination is also changed.
This option lets you Move or Copy the selected worksheet to a different
location in the same file or in another file. To Move or Copy a worksheet, right
click on its name, then select Move or Copy The Move or Copy dialog box
will open. From To Book: combo box 1 , you can select to which workbook
3
Figure 2.11: Move or copy
worksheet dialog box
26
to copy. If you check Create a copy 3 , the source worksheet will be copied
to the new location. Otherwise, it will be moved to.
The list box in the middle 2 shows the worksheets of the selected
workbook. The source worksheet will be inserted before the selected sheet.
Microsoft Excel
27
In order to not permit others to see and make changes on your hidden
sheets, you need to protect your workbook from: Review Changes
Protect workbook, and click the Structure option in the dialog box.
We have another hide option since Excel 2007.
Display the Properties window from the Developer Controls tab.
Select the sheet that you want to fully hide from the combobox above.
Then Select Veryhidden option from the options.
Be careful that the sheets cannot be shown using these normal ways.
Because they are made very hidden and will not appear any more in the
Properties window. But, you can unhide those using macros that well discuss
in Chapter 9, using following statement:
Figure 2.14: Sheet properties
ActiveWorkBook.WorkSheets(Sheet1).Visible = True
28
Microsoft Excel
Questions
1. Without using the mouse or the arrow
keys, what is the fastest way of getting to
cell A1 in a spreadsheet?
a. <Home>
b. <Shift+Home>
c. <Ctrl+Home>
d. <Alt+Home>
a. ALT or SHIFT
c. SHIFT or CTRL
b. ALT or CTRL
b. F2
c. F3
d. F4
a. <Ctrl+X>
b. <Alt+V>
c. <Ctrl+B>
d. <Ctrl+A>
b. Row
c. Column
d. Gridline
b. II, III
c. II, III, IV
d. I, II, III, IV
30
Microsoft Excel
31
N C H
E G
R O K
Y W F
C O
U M N N R
O H U
O O
B O P
D N
G P
H O R
O N
N G Q S
O R M A
D
K
Y W F M X W P W C H C
B M V
O E
G C W N
D C
B Q P
K O
N O B
V
Words
Clues
SCROLLING
32
Microsoft Excel
Practice
Use the next Figure for the questions 1 through 4.
1. Height of the rows in the table is 12.75. Change them to 15.
2. As shown in the figure, range B2:E2 is the title of the table. Move this
range to the bottom of the table.
3. Delete the 4th and 7th rows at the same time.
4. Add 3 columns between columns D and E.
33
11. How can you add the records from Table-2 to Table-1 to produce Table-3.
12. Sometimes you need to change the direction of your lists from vertical to horizontal or vice versa. Show
how you can change the list in Table 1 as in Table 2.
13. For the figure below, change the column widths of A, C, and E simultaneously. Then, Auto fit all the
columns at the same time.
34
Microsoft Excel
Example 3.1:
a. Before wrap text
36
Microsoft Excel
Right-click on the selected range and choose Format Cells from the
popup menu.
Press the Ctrl+1 shortcut key.
3.2.1 Number
Number formatting refers to the process of changing the appearance of
values contained in cells. For faster and easier processing purposes, Excel
keeps some other types as numbers in the cells.
For example dates are kept in the cells as numbers. Time info is kept as a
fractional number. But, with this formatting option, when showing this number,
Excel shows us a date or time info. This is called Number Formatting. In the
following sections, you see how to use many of Excels formatting options to
quickly improve the appearance of your worksheets.
Formatting Documents
37
Category: Select the desired format from the Category box. Each item forms
a special formatting on the selected cells.
Sample: The next figure shows how the selected number format looks.
Figure 3.6: Formatting date
Selected Category
Details of the
selected format
More Information
38
Microsoft Excel
Special: Contains four additional number formats (Zip Code, Zip Code
+4, Phone Number, and Social Security Number).
Custom: Enables you to define custom number formats that arent
included in any other category.
If you see
in a
cell, it usually means that your
column width is not enough to
show the formatted text.
4. Click OK.
3.2.2 Alignment
Alignment changes the horizontal or vertical alignment of cell contents,
based on options you choose.
Horizontal: Select an option in the horizontal list box 1 to change the
horizontal alignment of cell contents. Changing the alignment of data does
not change the data or the type.
Vertical: Select an option in the vertical list box 2 to change the vertical
alignment of cell contents.
1
2
3
5
Indent: 3 Puts distance between the left edge of cell and your text. Each
increment in the indent box is equivalent to the width of one character.
Figure 3.8: Alignment Tab
Formatting Documents
39
Text Control: 4 You can adjust how you want the text to appear in the cell.
Wrap Text into multiple lines: The number of wrapped lines depends on the
width of the column and the length of the cell content. Shrink to fit: If you
check this option Excel will automatically reduce the font size so that all data
in the selected cell fits within the column. If you change the column width the
character size is adjusted automatically, but the applied font size is not
changed. Merge cells: Joins two or more selected cells into a single cell, or
unmerges the merged cells. This is often used to create labels that span
multiple columns.
Orientation: 5 You can change the text orientation in selected cells.
Degree: You can enter a number to change text orientation. Use a positive
number in the degree box to rotate the selected text from bottom left corner
to upper right. Use a negative number in the degree box to rotate the selected
text from the upper left to the bottom right corner in the cell.
3.2.3 Font
Font: select a font name to change the font of the selected cell text.
Font style: select a font style of the selected cell text.
Size: select a font size for the selected cell text. You can type any number
between 1 and 409 to change the size.
Underline: select an underline type format to apply to the selected cell text.
Color: select a color from the list to apply to the selected cell text.
Effects: select effects to apply from the Effects group box.
Strikethrough: draws a line through the selected text.
Superscript: changes the format of the selected text to superscript Eg. x2
Subscript: changes the format of the selected text to subscript Eg. H2O
Figure 3.9: Font Tab
3.2.4 Borders
3
1
2
Presets: Apply a border style using the Presets options 1 or remove an old
border style.
Line Style: Choose a border Line Style 3 , then click the border to which you
want to apply the new line style.
Line Color: 4 Select a color from the list to change the line color.
Border: You can add/remove any Border lines 2 by clicking on them. The
new lines will have the color and style you selected.
40
Microsoft Excel
3.2.5 Fill
In Excel 2007, we have some improvements in the Fill Tab. In Excel 2003, we
could use simple colors. But now, you are also able to use two color gradient
fill effects and patterns. Like in the other Office objects, each cell background
can be filled with patterns and effects. Secondly, you are not limited like in
Excel 2003. You can use theme colors or one of the more than 16 million
unique colors.
3.2.6 Protection
Before protecting the sheet, first, you should Lock/Unlock necessary cells
from the Format cells dialog box. In the Protection tab, we have two
properties.
Locked: Prevents the selected cells from being changed, moved, resized, or
deleted. Locking cells has no effect unless the sheet is protected.
Hidden: If you check this option you will hide a formula in a cell, so that it
doesnt appear in the formula bar when the cell is selected. Hiding cells has
no effect unless the sheet is protected.
After that, you can protect a sheet from the Home Tab Cells Format
Protect Sheet. When you click protect sheet, it will open a dialog box for
you. In this dialog box, mainly, it asks you two questions:
1. Password
Example 3.3:
Select the range of the cells that you want to unlock. Then uncheck the
Locked check box from the Protection tab in the Format cells dialog box.
When you select Protect sheet from the Home tab, all cells are protected
except for the ones you unlocked.
Formatting Documents
41
Borders
Alignment
Pattern
Protection (locked and hidden)
42
Microsoft Excel
In order to apply a cell style, after you select your destination range, you click:
Home Tab Styles group Cell Styles. It will show you the options as in
Figure 3.16. You select the style that you want to apply.
Using the New Cell Style button you can open the Style dialog box and
create new styles from the selected cell formats. If you want to make further
changes in your format use the Format button under the Style Name box.
Because these subjects (Themes and Styles) much involved in design, you
can have a detailed reading from our MS. Word book.
Formatting Documents
43
1
Figure 3.17a: Inserting a Table
group. When you place active cell indicator 5 in a table range 6 and click
this button, Excel will automatically determine the table range and open the
Create Table dialog box.
6
5
If you want to change the table
name, you can change it from
the Name Manager in the
Formulas tab.
4
Figure 3.17b: Create table dialog box
The table address will appear in the edit box 2 . If this is not the correct table
range, just erase it and using your mouse indicate the new address. If your
table already has headers, you check the My table has headers check box
3 . And click OK 4 . Excel defines this range as a Table and gives a name
to it.
3.6.3 Table AutoFormat
AutoFormat is a built-in collection of formats: font sizes, patterns, and
alignments which you can quickly apply to a table. AutoFormat lets you select
from hundreds of different preset formats.
In Excel 2003, we had very few options for Table AutoFormat; there were 16
predefined Table AutoFormat options there. Now, working with tables is easier
than ever. All you need is to decide the best table color and design for your
document. The designers of Excel, probably, realized that such tables are
widely used in Excel, and theyve taken the concept to a new professional
level. They placed hundreds of professional table color and design options.
44
Microsoft Excel
You can easily toggle the display of the tables header row and totals row.
Removing duplicate entries is easy.
Autofiltering and sorting options have been expanded.
If you create a chart from a table, the chart will always reflect the data in
the tableeven if you add new rows.
If you scroll a table downwards so that the header row is no longer visible,
the table headers now are displayed where the worksheet column letters
would be.
Example 3.4:
Prepare the following table for a Real Estate Agency, and format it.
Formatting Documents
45
Example 3.5:
Now prepare the Conditional formatting as follows.
If mark is 5 Light red fill with dark red text
If mark is 2 Light yellow fill with dark yellow text
Figure 3.22: Table Conditional
Formatting
1. Select the cell or cell range you want to apply conditional formatting to
2. Select the Greater Than Conditional Formatting button from the Home
Tab (Figure 3.21)
3. Enter the condition as in the Figure 3.23.
In Office 2003, you could have up to three conditions. But since Office 2007,
you can have (theoretically) an unlimited number of conditional formatting.
You can apply more than one condition to the same range. To avoid problems
pay attention to not to conflict your conditions.
46
Microsoft Excel
Questions
1. Which of the following is used to write
multiple lines in a cell?
a. Shrink to fit
b. Wrap text
c. Merge cells
d. Orientation
b. Alignment
c. Underline
d. Patterns
FALSE
b. Hidden
c. Read only
d. Shared
b. Entire Text
a. =(equal)
b. " (quote)
c. 57%
d. 350
c. ' (apostrophe)
d. _ (underscore)
Formatting Documents
47
48
Microsoft Excel
Practice
1. Make the following table. You may use different contact and company names.
Formatting Documents
49
50
Microsoft Excel
Clues
Explanation
Formatting Documents
51
Project
1. Surprise your parents, by finding out the day of the week they were born?
2. Write down a chemical expression in an Excel sheet.
3. Perform the following using the figure below.
a.
b.
Resize column A so that you can see all data within cells A7 through A10.
c.
Change the font of the title to Times New Roman. (A1, A3)
Make the worksheet title bold; change its color to dark blue and size to 14 pt.
d.
e.
Center the column headings (from Quarter 1 to Total) and amounts, and then apply bold formatting.
f.
g.
Pay attention to Text Orientation, background color, font color, merge cells, text alignment, number category,
borders...
52
Microsoft Excel
6
Figure 4.1: Page layout tab
1
2
5
3
54
Microsoft Excel
Figure 4.4a
Center on page: Centers the data on the page vertically, horizontally, or both.
Figure 4.4b:
Print margins in Page Layout tab
Figure 4.5b:
Header and Footer margins
55
Figure 4.6b
56
Microsoft Excel
Sheet Options: 4 You can decide what to print from your document:
Gridlines, Comments, Cell errors, etc.
Breaks: You can insert/ remove page breaks.
Print Order: Choose order of the pages in printing.
57
Page view
buttons
Figure 4.13:
Workbook views in the View tab
In the Page Layout View, you can change the layout and format of data the
way that you can in the Normal view. This new Page Layout view works similar
to Print Preview and ensures no surprises when its time to print your work.
Even better, the Page Layout view includes click and type page headers
and footerswhich is much more intuitive than the old method. Unlike the
standard print preview, Page Layout view is fully functional in terms of
spreadsheet editing.
Note: The Page Layout view is useful to get your data ready for printing. Page
breaks are more easily adjusted in the Page Break Preview view. For an exact
preview of how the data will be printed, you can preview the worksheet pages
in the Print Preview view.
58
Microsoft Excel
3
4
1
4.3 Print
After you finish processing your document, you generally
want to print the document. To open Print window, click
Print from the Office button, or
press <Ctrl+P> from the keyboard.
We dont have a print button any more in the Home tab or
in another toolbar. But, we have Quick print for the Quick
Access Toolbar. If you use the Quick Print button from the
QAT, it will not open the print window but will send the
entire worksheet directly to the printer.
59
Microsoft has a cool feature: Document Image Writer. With the help of this
feature you can save your page as a picture and print it later. It provides black
and white 300dpi tiff format or MDI format for color outputs.
If you want to print from a local or a network printer, first of all, you must install
it properly. You can see how to install a printer from the Windows XP/Vista
book of this series. After you install your printer and plug all the cables in
properly, select a printer from the Printer Name combo box at the top of the
Print window. When printing, it is strongly recommended to follow this order;
1. Firstly, give a final check and save your document
2. Adjust page setup properties
3. Adjust printer properties
4. Send to the printer
Because all printers have different properties, the Properties page will be
different for each printer. In general they have a page for Layout (page
orientation, page order, paper size, etc.) and another for Print quality.
60
Microsoft Excel
Questions
1. Which of the following options is not
located in the Page Setup dialog box?
a. Page Orientation
b. Margins
c. Header / Footer
d. Page Break Preview
b. Scaling
c. Paper size
d. Print quality
b. Margins
c. Resolution
d. Orientation
b. Print Quality
c. Measurement
d. Margins
61
a. Active sheet(s)
b. Print area
b. Entire workbook
c. Date button
d. Chart tab
d. Zoom button
62
c. Draft quality
d. Printing quality
Microsoft Excel
Words
Clues
LANDSCAPE
Page orientation in which the page width exceeds the page length.
A function that allows you to add the numbers in multiple cells.
To be the right size or shape.
It is used to display series of numeric data in a graphical format.
One or more lines of text that appear at the bottom of every page of a document.
To take out a copy of your document on a paper
The horizontal and vertical lines on the spreadsheet.
Text that appears at the top of every page of a document when it is printed.
Area between the edge of a page and the written or printed text.
The orientation of a page in which the longer dimension is vertical.
Comparing data with known information (patterns, ranges, check digits) to verify that
the data is correct.
63
Project
1. Make a nice looking table which has the names and surnames of your classmates
with their grades in Informatics lesson. Then show a print out to your teacher.
2. Find and write down the results of a General Assessment Test in your
school in an Excel worksheet.
64
a.
b.
Assuming you have multiple pages, on the top of each page you
must have the same title. Solve this problem in this project.
Microsoft Excel
To Refer to
Use
A10
A1:E1
A1:E5
5:5
5:10
H:H
H:J
5.2
Linking Worksheets
You can think that Instead of gathering all the data in a single workbook, why
do I need to link worksheets, or workbooks? There can be many reasons:
In R1C1 style R and C represent
Rows and columns. The number
written after R is the Row number
and the same for the column.
The D2 cell in A1 Reference style
means R2C4 in this style.
66
Microsoft Excel
If you want to have a link to the A1 cell in Sheet1 from sheet2, you first write
the sheet name followed by an exclamation mark and write the cell address
in the destination cell:
=Sheet1!A1
If you want to have a link to the A1 cell in Sheet1 in the Plans.xlsx workbook
from another workbook, you
first write the workbook name in square brackets,
=[Plans.xlsx]Sheet1!A1
5.3
To write a formula, you must start with an equal sign =. Then, using
references, numeric values and arithmetic operators, you can write your own
formulas. (You can see the cell reference name in Name Box on the left of
Formula Bar).
67
Example 5.1:
You have a worksheet that lists exams for students. Write a formula for your
teacher that calculates each students average.
Name Box
Formula Bar
Active Cell
Exam3 is F4.
= (D4+E4+F4)/3
Operator
Meaning
/
*
Addition
Subtraction
Division
Multiplication
Percentage
(Divides number
by 100)
To the power
%
^
Example Result
=3+2
=3-2
=3/2
=3*2
5
1
1.5
6
=50%
0.5
=3^2
After you press the ENTER key, it will display the average of
the first student. Now, you can copy this formula to other
students. When you copy and paste formulas, Excel will
automatically make the necessary changes in formulas for
every row and column references. For the second student
the Exams are stored in the 5th row and the formula will be
= (D5+E5+F5)/3
Operator
Meaning
=
>
<
Equal sign
Greater than
Less than
Greater than or
equal to
Less than or
equal to
Is not equal to
>=
<=
<>
Example Result
=3=2
=3>2
=3<2
=3>=2
TRUE
=3<2
FALSE
=3<>2
TRUE
68
FALSE
TRUE
FALSE
Operator
Meaning
Example
Result
Range
A2:C7
space
Microsoft Excel
Example 5.2
Your math teacher needs some help. He wants you to prepare an
Excel sheet in which he will write the students marks. He has two
written exams and a final exam. When calculating the semester
average, written exams weigh 25 % each and the final exam weighs
50%. Help him prepare an Excel sheet like the following one.
Figure 5.4: Average with Final Exam
A1
Sometimes, you want an address not to change when you copy it to another
location. In such conditions, you add the $ sign to the front of the column or
row reference. Being able to place the $ sign to the front of a row or a
column separately provides flexibility.
Example 5.3
Computing the cumulative sum (year to date) is one of the problems that you
might face.
Solution:
As you see in the figure next, we have monthly amounts in column B. And, in
column C, we have the year to date amount. In C2 cell, we can use the
formula
Figure 5.5:
Computing cummulative sum
=SUM($B$2:B2)
In this formula the starting address is an absolute reference, but, final
address is a relative one. So, when you copy this formula to other cells in the
same row, itll keep the start cell the same, but, the final cell will be the next
one.
69
Example 5.4
In an Excel worksheet, you have exchange rates and your
expenses. Because you are a foreign company in this
country, you pay in Euro but all of your budget is built on
USD. So, for every payment you convert from Euro to
USD. You place exchange rates at the top of the page and
you write your formula to convert the payment into USD.
Solution:
You will study more complicated conversions later. For
now, we will only explain converting Euro to USD. In this
case the USD conversion cell has to be an absolute
reference and will not change from one payment to
another: $B$8.
The payment cell has to be a relative address, because, every conversion will
take its left cell as a payment. D11 contains the payment for the first
operation, D12 for the second payment, and D13 for the third one.
Then the formula for the first payment in column E becomes
=D11 * $B$8
Now your formula is ready.
When you copy this formula to other payments, the USD exchange rate cell
will be an absolute reference but the payment cell will be relative and change
automatically for every copy.
The formula for the second payment will be come
=D12 * $B$8
=D13 * $B$8
=D14 * $B$8
5.4
Simple Functions:
70
Microsoft Excel
There are three main parts in this window. If you remember the
function name, write it in the Search for a function box. If you
know the function name and category for sure, you can first
select the category 1 and then select the function from the
Select a function list box 2 . Below the list box 3 , a brief usage
and explanation is shown. There is also a link for help 4 , for the
current function at the bottom left corner of the dialog box.
4
Figure 5.8: Insert Function Dialog Box
Example 5.5
If your Excel worksheet contains the data shown in Figure 5.9, the following
formulas give the results described in the table.
Formula
Description
Result
=SUM(3, 12)
15
=SUM(A2:A4)
40
55
21
DATA
-5
15
30
'5
TRUE
71
DATA
Formula
Description
Result
10
=AVERAGE(A2:A4)
27
=AVERAGE(A2:A6; 5)
10
Example 5.6
You start working in the sales department of the SURAT Company which sells
computer peripherals and devices. Your boss wants you to prepare reports
for every quarter. In this report you will have a list of products. Your task is to
prepare the sum and average of each quarter. You also need to prepare the
sum and average of each product. The list will be similar to the following:
A
H
Reseller
Quarter 1
Quarter 2
Quarter 3
Quarter 4
Annual
Total
Company
Average
Sony Computers
500
500
600
700
2300
575
Compaq Computers
300
350
300
300
1250
312,5
Dell Computers
600
600
500
620
2320
580
Toshiba Computers
600
650
680
700
2630
657,5
Acer Computers
1200
1100
1100
1150
4550
1137,5
13050
652,5
Id
Reseller
TOTAL
3200
3200
3180
3470
AVERAGE
640
640
639
694
72
Microsoft Excel
Example 5.7
According to the Figure 5.12, write the necessary formulas into
cells F11 and F12 to find the highest and the lowest averages.
Solution:
Figure 5.12: Using Max and Min functions
Description
Result
=Count (A2:A8)
=Count (A5:A8)
=Count (A5:A8,2)
A
1
DATA
Sales
12.08.2008
4
5
19
22.24
TRUE
#DIV/O!
73
Example 5.8
Your teacher wants to keep track of class attendance in an Excel workbook.
The table will contain names and dates. If a student is absent from school for
a day, he writes the number of lessons the student missed. He wants you to
write a formula to count the number of days that the students have not
attended. In another formula write the total of missed hours.
A
...
...
Total
Days
Total
Hours
...
...
...
...
21
...
...
Rob Brooks
Raymond Camden
Michael Dinowitz
Adam Churvis
Shlomy Gantz
Paul Hastings
19.09.2010
18.09.2010
Id
17.09.2010
16.09.2010
1
7
74
Microsoft Excel
Function Number
Function Number
Function
101
AVERAGE
102
COUNT
103
COUNTA
104
MAX
105
MIN
106
PRODUCT
107
STDEV
108
STDEVP
109
SUM
10
110
VAR
11
111
VARP
Function numbers have two variants: the first type includes the hidden
rows/columns where the other ignores them.
=SUBTOTAL(function_num, ref1, ref2, ...)
Example 5.9
Here is how you could solve the previous example with this function.
Solution:
For the first student, in cell Y3, write the formula =SUBTOTAL(102, C3:X3)
and for the total hours skipped, in cell Z3, write = SUBTOTAL(109,C3:X3).
Here, we use function numbers 102 and 109. You could also use 2 and 9, its
up to your project design. The difference is that 109 excludes the hidden
rows (if any), 9 doesnt pay any attention to hidden rows. And now, copy
these formulas for the other students.
75
You already know how to open the Insert Function Window (from
the button 1 in the Formulas Tab). When you select a function
6
Figure 5.17: Insert Function dialog box
Parameters
(Function Arguments)
Current Function
Function
description
Financial
Text
Logical
Information
Statistical
Engineering
Current Parameter
description
Compatibility
76
Microsoft Excel
Example 5.10
=Now ()
07/15/2009 15:00
5.5.1.3 Today()
Shows current date. If the cell format was General before the function was
entered, the result is formatted as a date.
Example 5.11
=Today ()
07/15/2009
77
Example 5.12
Your cousin was born on March 17, 2009 and you wonder, how old is she,
now?
Figure 5.19: Arithmetic operations
with dates
Solution:
Just write her birthday in a cell (A1) and write the current day in another cell
(B1). Then, in a third cell (C1) write =B1-A1
This will subtract the first day from the second one (today). But, because both
inputs are date formatted, the result might be automatically formatted as
date. Just change the cell format to Number Format.
Calculating Time difference is the same. If two cells contain time information
and you subtract one from another the result will give the difference between
them.
This can be helpful for you to calculate extra work time in a week for staff in a
company.
5.5.1.5 Summing the Times that exceed 24
Hours (Optional)
When calculating the sum operations, if you dont pay
attention you might have wrong answers.
The problem is because of the number format which is set to
General Format and it automatically takes the date format.
78
Microsoft Excel
5.5.1.6 DateDif()
You may notice that this function does not appear in the drop-down function
list for the Date & Time category, nor does it appear in the Insert Function
dialog box. Therefore, when you use this function, you must always enter it
manually.
DATEDIF is a handy function that calculates the number of days, months, or
years between two dates. The function takes three arguments: start date, end
date, and a code that represents the interested time unit. The following table
displays some valid codes for the third argument. (You must enclose the
codes in double quotation marks.)
Unit Code
Returns
Example 5.13
Your elder cousin was born on June 17, 1993 and you wonder how old is he?
Solution:
When we want to calculate the months, years or days difference between any
two dates, DateDif is the best. Here, we just provide the start date, end date
and the code.
=DateDif(A3, B3, "y")
After you copy this formula to the following cells, this will create a series of
dates with seven days difference between them.
79
The Year function returns the year of a date. Similarly, the Month function
returns the month of a date. So, we can divide the date value in A5 into Year,
Month and Day information separately. Then, you add 1 to the Month. Finally,
you form the new Date information.
=Date(Year(A5), Month(A5)+1, Day(A5))
You can use the same logic when counting by years.
returns 2
=ABS(-2)
returns 2
=ABS(-2.345)
returns 2.345
Example 5.15
When you subtract times, if somehow the date or time gives negative value,
Excel cannot show the result. It shows full of hashes in the cell.
80
If you really intend to have such a result, no problem, go on. But if you want
to see simply the time difference between any two times, you can use the
ABS function to avoid such problems.
Microsoft Excel
5.5.2.2 Pi()
Gives the value of Pi with an accuracy of 15 digits
Example 5.16
=Pi()
returns 3.14159265358979
5.5.2.3 Radians()
It converts degrees into radians. Trigonometric functions use radians as
arguments. E.g. Because, following the Sin function, it waits for the argument
in radians, when you write =Sin(30), it will not produce your desired result.
You should convert 30 into radians first.
Example 5.17
=Sin(Radians(30))
returns 0.5
5.5.2.4 Degrees()
Converts radians into degrees
Example 5.18
=Degrees(Pi())
returns 180
=Degrees(Pi()/3)
returns 60
5.5.2.5 Sin()
Returns the sine of a given angle. If your argument is in degrees, multiply it
by PI()/180 or use the radians function to convert it into radians. You can also
use the cosine function in the same way.
Example 5.19
=Sin(Radians(30))
returns 0.5
=Sin(30*Pi()/180)
returns 0.5
=Cos(Radians(60))
returns 0.5
=Cos(60*Pi()/180)
returns 0.5
81
5.5.2.6 Fact()
Returns the factorial of a number. n factorial is the product of the numbers 1
through n. n! = 1*2*3**n.
Example 5.20
=Fact(5)
returns 120
=1*2*3*4*5
returns 120
5.5.2.7 Int()
Rounds the given real number down to the nearest integer
Example 5.21
=Int(2.768)
returns 2
=Int(-2.768)
returns -3
5.5.2.8 Mod()
Returns the remainder after a number is divided by a divisor. The result has
the same sign as the divisor.
Example 5.22
=Mod(23,5)
returns 3
5.5.2.9 Power()
Returns the result of a number raised to a power
Example 5.23
=Power(2,4)
5.5.2.10 Product()
Multiplies the numbers within the given range
82
Example 5.24
According to next Figure, the following formulas give the results shown below
=Product(A1:A4)
returns 16
=Product(B1:B4)
returns 12
=Product(A1:B4)
returns 192
Microsoft Excel
5.5.2.11 Round()
Rounds a number to the specified number of digits
=Round (number, num_digits)
Number: is the number you want to round.
Num_digits: specifies the number of digits to which you want to round. If
Num_digits is greater than 0 (zero), then Number is rounded to the specified
number of decimal places. If Num_digits is 0, then Number is rounded to the
nearest integer. If Num_digits is less than 0, then Number is rounded to the
left of the decimal point.
Example 5.25
=Round(56.538,-3)
=Round(56.538,0)
57
=Round(56.538,-2)
100
=Round(56.538,1)
56.5
=Round(56.538,-1)
60
=Round(56.538,2)
56.54
5.5.2.12 Trunc()
Its similar to Round function. But, Trunc removes the digits after the specified
number of digits from the fractional part
=Trunc (number, num_digits)
Number: is the number you want to truncate.
Num_digits: is a number specifying the precision of the truncation. The
default value for Num_digits is 0 (zero).
Example 5.26
=Trunc(253.268569,3)
returns 253.268
=Trunc(253.268569,2)
returns 253.26
5.5.2.13 SumIf()
Calculates the sum of the numbers within the range according to the given
criteria
=SUMIF (range, criteria, sum_range)
Range: Is the range of cells you want to be manipulated.
Criteria: Is the criteria in the form of a number, expression, or text that defines
which cells are to be added.
Criterion can be
a direct number
a text
Book
an expression
>=5
83
Example 5.28
A
Ages
2
4
1
8
4
5
3
RESULT
1
2
3
4
5
6
7
8
9
B
Cost
23
54
76
45
98
34
27
126
Write a formula to calculate the sum of the numbers in the range B2:B8 where
the ages in A2:A8 is less than 4.
Solution:
Write this formula in cell B9 =SumIf (A2:A8, "<4", B2:B8)
5.5.2.14 Sqrt()
Returns the square root of a number
Example 5.29
= Sqrt(4)
returns 2
= Sqrt(25634)
returns 160.1062147
84
And(LT1, LT2,) checks if all the arguments (Logical Tests) are true. It
returns TRUE if all are true.
Or(LT1, LT2,)) checks if any of the arguments are true. It returns TRUE
if any argument is true, and returns FALSE if all are false.
Not() changes False to True or True to False.
Microsoft Excel
5.5.3.2 If()
If-statement is one of the most commonly used logical functions. It checks a
boolean-expression to decide a result and returns one of the values
according to the result.
Usage : If(LT, Value_if_true, Value_if_false)
Example 5.30
Write a formula that decides if a student has passed or failed. The results that
are less than or equal to 4 means that he/she failed, and any (integer) result
which is greater than 4 means that he passed.
Solution:
The formula will be written in E1 and itll test if the value in D1 is less than or
equal to 4. (D1<=4)
If that logical test is true itll return the first value (Failed), otherwise itll return
the second value (Passed). So the final formula is:
=IF(D1<=4,"Failed","Passed")
5.5.4.1 Count()
Counts the number of cells that contain a number in the given range
=Count(value1, value2, value3,.)
Example 5.31
According to Figure 5.27, find the number of students
who take Phy.Edu lesson.
Solution:
Write this formula in cell E11 =Count(E2:E10)
85
5.5.4.2 CountBlank()
Its similar to the Count function. But, it counts the number of empty cells in
the selected range.
CountBlank(range)
5.5.4.3 CountA()
Counts the number of cells that are not empty within the selected range.
=CountA(value1,value2,...)
5.5.4.4 CountIf()
Counts the number of cells within the selected range that comply with the
given criteria.
=CountIf(range, criteria)
Here are some examples of CountIf functions:
=COUNTIF(Data,12)
=COUNTIF(Data,<0)
=COUNTIF(Data,<>0)
=COUNTIF(Data,A1)
=COUNTIF(Data,>&A1)
=COUNTIF(Data,*)
=COUNTIF(Data,budget)
Returns the number of cells containing the single word budget (not case sensitive)
=COUNTIF(Data,*budget*)
Returns the number of cells containing the text budget anywhere within the text
=COUNTIF(Data,A*)
Returns the number of cells containing text that begins with the letter A
=COUNTIF(Data,TODAY())
=COUNTIF(Data,>&AVERAGE(Data))
Returns the number of cells with a value greater than the average
=COUNTIF(Data,TRUE)
=COUNTIF(Data,#N/A)
For using multiple criteria Excel provided a new function series: AverageIfs, SumIfs, CountIfs are some of them.
=COUNTIFS(Data, ">10", Data, "<20")
Example 5.32
According to Figure 5.27, write the necessary formula in cell F11 to find out the
number of students whose Phy.Edu. average is greater than or equal to 9.
Solution:
Write the formula in cell F11 = CountIf (E2:E10; ">= 9")
86
Microsoft Excel
5.5.4.5 Median()
Median is the middlemost number in a list. So to get it, first, we need to put
items in order.
Example 5.33
The Simpson family drove through 7 states on their summer vacation. The
price for gasoline varied from state to state. They stored their prices in a
workbook. What was the median gasoline price paid?
Solution:
If you put the items in order, you get:
$1.79, $1.84, $1.84, $1.84, $1.96, $1.96, $2.11. The result is 1.84,
because its the 4th (middle) element.
Figure 5.28: Median of a list
5.5.4.6 Mode()
The Mode of a set of data is the value in the set that occurs most often.
Example 5.34
On a cold winter day in January, the temperature for 9 cities is
recorded. What is the mode of these temperatures?
Solution:
If you put the items in order, you get:
-8, -3, -1, 0, 0, 0, 4, 5, 12. As you see 0 repeats 3 times whichs the mode of
these series.
Example 5.35
Lets say that, North Elementary school (NES) has a higher average than
South Elementary school (SES). Your first reaction might be to say that the
kids at NES are smarter.
87
But a bigger standard deviation for one school tells you that there are
relatively more kids at that school towards one extreme or the other. By asking
a few more questions, you might find that mean was skewed up because the
school district sends all of the gifted kids to NES. Or, that SES scores were
dragged down because of the students who recently have been
mainstreamed from special education classes and have all been sent to SES.
To make the question clear, I made the first 4 marks for both schools
the same. Only the last two marks change. As you see from the
example, the last 2 students from class NES have closer marks to
their friends. On the other hand, the last 2 students from SES are
very low. If you check only the general average, you will think that
the kids at NES are smarter. But actually, Standard deviation 7
shows that students in NES have all closer results. But, 26 tells that
there is big gap with some students in SES where you can
understand the reason when you have further analysis.
Figure 5.30: STDEV function
5.5.4.8 Correlation
Correlation is a statistical technique that can show whether and how strongly
pairs of variables are related.
CORREL(array1,array2)
Closer to zero means that there is a weak or no relation.
Closer to 1 means that there is a strong relation.
Closer to minus one means strong negative relation between variables.
Example 5.36
In a biology study, you have searched the Age and blood
pressure relation among people. You recorded your data in a
worksheet and you want to search whether there is a relation
between age and blood pressure.
On Figure 5.31, the result 0.89 says that there is a strong
positive relation between blood pressure and age. (When
age increases mostly the blood pressure increases too.)
In another research, you want to determine if there is a
relation between the number of absences and the final
grade. The result is -0.945, a strong negative relation, which
tells that when absence increases final grade mostly
decreases.
88
Microsoft Excel
5.5.5.2 Find()
Finds one text string (find_text) within another text string (within_text), and
returns the starting position of find_text, from the first character of within_text.
You can also use Search to find one text string within another, but unlike
Search, Find is case sensitive and doesnt allow wildcard characters.
=Find(find_text, within_text, start_num)
Find_text: is the text you want to find.
Within_text: is the text containing the text you want to find.
Start_num: specifies the character at which to start the search.
5.5.5.3 Len()
Returns the number of characters in a text string
=Len(text)
5.5.5.4 Left()
Returns the first character or characters in a text string, based on the number
of characters you specify from the left.
=Left(text, num_chars)
5.5.5.5 Right()
Returns the last character or characters in a text string, based on the number
of characters you specify from the right.
=Right(text, num_chars)
Text: is the text string containing the characters you want to extract.
Num_chars: specifies the number of characters you want to extract.
89
Example 5.37
According to the Figure 5.32, write these formulas into suitable cells, and
examine the results.
=Find( " ",C3)
=Len(C3)
=LEFT(C3,C7)
=RIGHT(C3,C8-C7)
=MID(C3,C7+1,15)
90
Microsoft Excel
Example 5.38
In order to improve the Excel document that you have given to your math
teacher, now, you can prepare another formula, which defines the letter
grades for students. If the average of a student is lower than 60, it will write
F and so on. Your teacher has provided the Letter Grade conversion table in
the range J3:K9.
91
5.5.6.3 Index()
Index and Match functions (instead of vlookup) can be used in collaboration
to return values from tables. Index function returns a value (or the reference
to a value) from/within a range. Match function Returns the relative position of
an item in a range that matches a specified value in a specified order.
Usage: INDEX(array, row_num, [column_num])
Example 5.39
Data
Apples
Bananas
Data
Lemons
Pears
=INDEX(A2:B3,2,2)
=INDEX(A2:B3,2,1)
5.5.6.4 Match()
MATCH function can be used instead of the LOOKUP functions when you
need the position of an item in a range instead of the item itself. It returns the
relative position of an item in an array that matches a specified value in a
specified order.
Example 5.40
1
2
3
4
5
6
7
8
A
Product
Bananas
Oranges
Apples
Pears
Find in the
List
B
Count
25
38
40
41
Oranges
2
According to table next, find the position of the item specified in the cell B7
(Oranges).
Product list is in A2:A5. The item that we are searching for is in B7. And match
type is 0 (zero), because we search for an exact match.
Finally we write the formula in B8
=MATCH(B7,A2:A5,0)
And it will return 2, because Oranges is in the second cell in our search range.
5.5.6.5 Using Defined Names
There is another method to dereference two way lookups: using Defined
names. You provide a name for each row and column of the table. A quick
way to do this is to select the table and choose Formulas Defined Names
Create From Selection.
In the Create Names from Selection dialog box, select the Top Row and
Left Column check boxes. After creating the names, you can use a simple
formula, such as:
Example 5.41
QTR1_ is the name of the range B2:B5. West is the name of the range B4:E4.
Then the formula
=QTR1_ West
92
Microsoft Excel
Name
Todd Rafferty
Date
Lesson
Hours Motivated
FALSE
Lesson
Maths
Maths
Chemistry
Informatics
Informatics
Physics
Physics
Physics
Physics
Chemistry
Hours Motivated
2
TRUE
2
FALSE
2
TRUE
2
TRUE
2
FALSE
1
TRUE
2
FALSE
1
TRUE
2
TRUE
2
FALSE
RESULT
4
DATABASE
Class
11A
11A
11A
11A
11A
11A
11A
11A
11A
11A
Name
David Shadovitz
Todd Rafferty
Pablo Varando
Brendan Hara
Pete Thomas
Todd Rafferty
Todd Rafferty
Simon Horwith
David Shadovitz
David Shadovitz
Date
2/17/2003
2/17/2004
2/18/2004
2/19/2004
2/20/2004
2/21/2004
2/24/2004
2/25/2004
2/26/2004
2/27/2004
93
94
Microsoft Excel
Questions
1. If cell A5 contains a formula which
produces 25, what can be the
formula in A5?
a. =Sum (A1:A4)
b. =Min (A1:A4)
c. =Average (A1:A4)
1
2
3
4
5
A
10
20
30
40
?
a. 800
b. 68
1
2
3
4
A
100
200
400
800
B
12
22
68
21
C
128
601
288
204
c. 601
D
20
60
80
97
d. 288
d. =Count (A1:A4)
b. =Sum (A1:A4)
c. =Average (A1:A4)
d. =Max (A1:A4)
b. !
c. $
d. ?
b. List
c. Max
d. Count
A
1
10
2
20
3 January
4
5 #VALUE!
a. 26,8
A
B
C
5
2
5
3
1
7
=AVERAGE(A2:B3)+SUM(A2:B3)
b. 3,8
c. 16
d. 20
FALSE
95
a. 40,1
b. 40
c. 39,92
d. 39
Functions
Definitions
Min
Max
Average
Sum
15.
B
4
64
a. 0
a. = B1*B1*B1
b. = B2*B2*B2
c. = A1*A1*A1
d. = Cube(B1)
b. 7
c. 1
d. 2
1
2
3
4
a. 2
96
A
Id
1
2
3
B
Name
Andrew
Thomas
Laura
b. Andrew
C
D
Surname 1st Term
Jackson
3
Ericsson
4
Callahan
5
c. Ericsson
d. 4
Microsoft Excel
Project
1. According to the figure next write the necessary
formulas to
1
2
3
4
5
6
7
8
9
10
11
12
13
B
Tree Star Trade Company
Employee
City
Selena Bainum
Berlin
Raymond Camden
Mexico
Paul Hastings
Moscow
Kevin Schmidt
London
Pete Thomas
Istanbul
Nicholas Tunney
Madrid
C
Salary
$ 1520
$ 2500
$ 1800
$ 3200
$ 5210
$ 850
?
?
?
?
2. Your father is running a small business. Some companies buy some products and
they give some checks. Your father stores due dates and amounts of these
checks in a worksheet.
When he has to pay cash, he uses the same worksheet to see if the amount of
money that he is going to collect is enough or not.
Write a function in B14, so that, it will take the Sum of the Amounts (B2:B11), if
the date in column B is less than the Due Date (B13).
in F7 to calculate xy
A
6
2
3
4
5
6
7
x
-8
B
C
D
E
F
7
8
9
10
11
Write the multiplication of the numbers above using
product function.
Formula
ABS
Formula
Y
256
SQRT
Enter base (X)
2
Formula Enter power (Y)
3
Y
Formula
X
97
A
B
4. In an apartment building, you have 5 floors and 5
1
Apartment #
Entrance #
different entrances. On each floor, there are three
2
43
?
apartments. Write a formula that will take an
apartment number from cell A2 and show the floor and entrance numbers in cells B2 and C2.
C
Floor #
?
Degree
0
10
20
30
40
50
60
70
80
90
C
D
Mini Trigonometric Table
Radian
Sinus
Cosine
E
Tangent
A
ID
1
2
3
4
5
B
Students
Raymond Camden
Paul Hastings
Kevin Schmidt
Pete Thomas
Nicholas Tunney
C
Grades
2.460
3.689
3.840
3.118
2.060
D
Int
?
E
Round
?
F
Trunc
?
7. Write a formula which can calculate the total salary of the employees in the city given by cell C2.
1
2
3
4
5
6
7
8
9
10
11
98
A
Id
B
Employee
C
City
London
Total salary of employees live in given city?
1
Kevin Schmidt
New York
2
David `Shadovitz
London
3
Pete Thomas
London
4
Nicholas Tunney
New York
5
Kevin Schmidt
London
6
David Shadovitz
New York
7
Pete Thomas
London
8
Nicholas Tunney
London
D
Salary
400
400
400
350
400
615
540
1000
Microsoft Excel
1
2
3
4
5
6
7
8
9
1
2
3
4
5
6
7
8
9
10
11
A
Name & Surname
Samuel Neff
Brendan Hara
Jeremy Petersen
Todd Rafferty
Kevin Schmidt
David Shadovitz
Pete Thomas
Nicholas Tunney
B
Length
11
12
15
13
13
15
11
15
C
Space
D
Name
Samuel
Brendan
Jeremy
Todd
Kevin
David
Pete
Nicholas
E
Surname
Neff
Hara
Petersen
Rafferty
Schmidt
Shadovitz
Thomas
Tunney
Id
1
2
3
4
5
Name
Samuel
Brendan
Jeremy
Todd
Kevin
C
D
E
F
G
EXAMINATION RESULTS
Surname Maths Physics chemistry AVERAGE
Neff
5
5
5
5
Hara
3
2
4
3
Peterson
2
4
3
3
Rafferty
4
5
3
4
Schmidt
3
4
5
4
Enter Id:
Name
Todd
4
Surname
Rafferty
99
11. Write the necessary formulas into range C9:C12 that will read the class name from C7 and show the requested
class list in the cells.
A
1
2
3
4
5
6
7
B
11A
Index
Name and
surname
1
Simon harwith
2
Stephen Milligan
3
Samuel Neff
4
David Shadavitz
Enter Class:
Index
9
10
11
12
1
2
3
4
C
D
11B
11C
Name and
Name and
surname
surname
Pete Thomas
Selene Bainum
Nicholas Tunney
Geoff Bowers
Jochem Dieten
Rob Brooks
Pablo Varanda
Raymond Camden
11C
Name and
surname
Selene Bainum
Geoff Bowers
Rob Brooks
Raymond Camden
E
11D
Name and
surname
Hanna Moos
Bab Hanks
Martin Sammer
Victoria Ashworth
13. In exchange offices, everyday, money from many different currencies are
exchanged. Because they are afraid of making mistakes, they decided to
have an exchange program. In this document, the first part will have a table
of conversion from all other currencies into a base one. (In this figure, the
base currency is TL.) They want to write exchange currencies in cells A12 and
B12. When they write the amount of the first currency into A13, they want to
see the converted value in B13.
100
1
2
3
4
5
6
7
8
9
10
11
12
13
A
B
EXCHANGE RATES
Currencles
TL
Dollar
1.38
Euro
1.82
TL
1
Pound
2.57
Ruble
0.47
Yen
1.5
Dinar
1.3
From
Dollar
10
To
Euro
7.58
Microsoft Excel
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
B
C
D
E
F
The Results of the Informatics Olympiad
Name and
1st 2nd
Rank
Country
TOTAL
Surname
Day Day
4
Slena Bainum
England
140 120
260
8
Geoff Bowers
France
150 80
230
3
Rab Brooks
England
120 150
270
9
Raymond Camden Switzerland
210
210
6
Adam Churvis
Germany
150 100
250
12
Michael Dinowitz
USA
180
180
1
Shlomy Gants
Germany
180 155
335
14
Paul Hastings
USA
100
100
11
Alexandra Kim
Korea
52 150
202
9
Viktoria Shay
Korea
210
210
2
Olga Nam
Korea
85 200
285
7
Brendan Hara
Spain
240
240
13
Jeremy Peterson
England
50 120
170
14
Todd Rafferty
Switzerland
100
100
4
Kevin Schmidt
England
80 180
260
6
How many contestants are absent on the 1st Day?
nd
15
How many contestants are there on the 2 Day?
Number of the
Country
Korea
3
Contestants
15. A cellular base-station is located at the coordinates (x1, y1) and it has a transmit range of r . A person using
a mobile phone is located at the coordinates (x2,y2).
Write a function that gets (x1,y1), (x2,y2) coordinates and the radius of the transmitter and then decides if the
mobile phone is in use or not . If the phone works, the message will be The phone is working in this location,
otherwise, The phone is out of range. Note: Use the If function.
1
2
3
A
x1:
y1:
r*
B
100
100
50
C
D
x2:
60
y2:
40
The phone is out of rance
101
16. In the following sheet, the actual username and password are stored in C1 and
C2. If the correct user name and password are entered in B1 and B2, the
message in A3 will be Welcome to the Matrix; otherwise, Incorrect user name
or password.
A
B
1 User Name: admin
2 Password:
x-man
3 Welcome to The Matrix
17. Prepare the frequency chart of the exam results of 4 Classes. You can use the CountIfs function to count the
number of cells between low and high values.
18. In a sheet you keep the Extra work hours of your staff. Write a
function in E5 that gives the total hours for the person written in
E2 cell.
102
Microsoft Excel
DATA PROCESSING
In most cases, the vision and prestige of your company is much more
important than the money you spend on technology. If you dont spend
enough money and time for data processing, or for technology, it will most
probably cost more. The small mistakes that you make can damage your
company image a lot. Especially, when working with huge lists and lots of
numbers, fast and accurate results need proper investments.
6.2
Sorting
104
Microsoft Excel
Finally, Select Sort A to Z (or Sort Z to A) button from Home Editing. You
can also right click on the selected range and select an option from the Sort
list. But, for a better and more accurate result, it is suggested to use the
Custom Sort dialog box.
Example 6.1:
Put the list below in the Date order.
Class Name Surname
11A
11A
11A
11A
11A
11A
David
David
David
David
Pablo
Todd
Shadovitz
Shadovitz
Shadovitz
Watson
Varando
Rafferty
Date
Lesson
Hours Motivated
2/19/2007
Maths
3/2/2007 Chemistry
3/2/2007 Informatics
2/26/2007
Physics
2/19/2007 Chemistry
2/22/2007
Physics
2
2
1
2
2
2
TRUE
FALSE
TRUE
TRUE
TRUE
FALSE
To do this:
Firstly select the list including the header row
Using your Tab and Enter keys activate the Date title
Then Right click on the list and select Sort Sort Oldest to Newest
(Figure 6.1) from the popup menu
2
3
Data Processing
105
Click on the Sort by down arrow to select the column you want (Class).
From the Sort On combo box (the second one), select either to sort
according to cell values, or cell color etc. (Values)
From the Order combo box (the third one), select sorting order (A to Z)
If you want to use more than one criterion, you can use the Add Level
button for more criteria.
Click My Data has headers to exclude/include the first row from the sort.
If you want to remove a sorting level, first activate it and use the Delete
Level button
Using the Options button, for the column, selected in the Sort by box, you can
also specify a case-sensitive sort and sort either from top to bottom or from
left to right. In Excel 2003, we could use only 3 levels of sorting criteria. Now,
it supports 64 levels of criteria and more options in every criterion.
Example 6.2:
Data is sorted according to the Date field. Put the list below in the Name order.
Class Name Surname
Date
Lesson
Hours Motivated
11A
David
Shadovitz
2/19/2007
Maths
TRUE
11A
Pablo
Varando
2/26/2007
Chemistry
TRUE
11A
Todd
Rafferty
2/26/2007
Physics
FALSE
11A
David
Watson
2/26/2007
Physics
TRUE
11A
David
Shadovitz
3/2/2007
Chemistry
FALSE
11A
David
Shadovitz
3/2/2007
Informatics
TRUE
Firstly, if you sort it using Quick Sort option by Name, youll get:
Class Name Surname
Date
Lesson
Hours Motivated
11A
David
Shadovitz
2/19/2007
Maths
TRUE
11A
David
Watson
2/26/2007
Chemistry
TRUE
11A
David
Shadovitz
3/2/2007
Physics
FALSE
11A
David
Shadovitz
3/2/2007
Physics
TRUE
11A
Pablo
Varando
2/19/2007
Chemistry
TRUE
11A
Todd
Rafferty
2/22/2007
Physics
FALSE
106
Microsoft Excel
But as you see from the list above, just sorting according to one field will not
resolve your problems in may cases. Here, David Watsons absence is listed
in the middle of the absences from David Shadovitz. So, its not the desired
result. We should sort the list using two criteria, for this purpose: First by
Name; then by Surname.
1
2
To do this:
Date
Lesson
Hours Motivated
11A
David
Shadovitz
2/19/2007
Maths
TRUE
11A
David
Shadovitz
3/2/2007
Chemistry
FALSE
11A
David
Shadovitz
3/2/2007
Informatics
TRUE
11A
David
Watson
2/26/2007
Physics
TRUE
11A
Pablo
Varando
2/19/2007
Chemistry
TRUE
11A
Todd
Rafferty
2/22/2007
Physics
FALSE
Data Processing
107
6.3 Filtering
Filtering is a quick and easy way to find and work with a subset in a data list.
A filtered list displays only the rows that meet the criteria you specify for a list.
Microsoft Excel provides two commands for filtering lists:
2
3
7
6
arrows, Excel lists all unique column items 6 , and you select the ones to be
listed. (According to the figure, only Chemistry and Informatics lessons are
to be listed.)
Above the Filter by selection 6 , we have the Text Filters List 7 .
Here, you have many quick filter options, Like: Begins With, Ends With,
Contains, etc. This option 7 changes according to field type. Because,
we currently try to filter according to Lesson field, it shows Text Filters
options. When you select Date field, it will show Date filter options, etc.
108
Microsoft Excel
Yet another faster way exists. Right click on the item that you want to filter and
from the popup menu, select Filter by selected cells value or any other
appropriate option. But with this method, you can filter according to one
value. For more complex filtering, you should use the other methods.
Operator
Meaning
Example 6.3:
Condition
Range
Data Range
Copy to
Data Processing
109
110
Microsoft Excel
If the consolidation involves other workbooks, you can use external reference
formulas to perform your consolidation discussed in Chapter 5. For example,
if you want to add the values in cell B2 from Sheet1 in two workbooks (named
East and West); you can use the following formula:
=[East.xlsx]Sheet1!B2+[West.xlsx]Sheet1!B2
You can include any number of external references in this formula, up to the
8,000-character limit for a formula. However, if you use many external
references, such a formula can be quite lengthy and confusing when you edit
it. If the worksheets that youre consolidating arent laid out the same, you
can still use formulas, but you need to ensure that each formula refers to the
correct cell.
Your assistant director heard about your fame from the teachers and now he
is asking a solution to gather marks from teachers into a worksheet.
Solution: He wants to prepare a list like in the Figure 6.15 and distribute it to
teachers. Every teacher will fill in his part and return it back to him.
Select an empty worksheet and click the Consolidate button. Itll open the
Consolidate dialog box Figure 6.16).
Data Processing
1
2
3
111
112
Microsoft Excel
When you click over this empty range, Excel opens the Pivot Table Task
pane on the right.
From this pane, you can insert or remove fields to the Pivot table or if
necessary change properties.
Example 6.5:
Sports Qtr
In a sport center, the big boss wants to summarize the incomes from different
fields to produce quick results. The table next shows the sample data. He
wants to see and compare the summary according to Field, Qtr and Sports
Sums.
Solution: Insert the Pivot Table. Choose Amount and Field from the fields List.
Golf
Golf
Tennis
Tennis
Tennis
Tennis
Golf
Qtr3
Qtr4
Qtr3
Qtr4
Qtr3
Qtr4
Qtr3
Amount Field
$1,500
$2,000
$600
$1,500
$4,070
$5,000
$6,340
North
North
North
South
South
West
South
Data Processing
113
With another click you can show: Summary according to Sports and Qtr.
Deselect the Sports from the field list.
114
Microsoft Excel
Questions
1. You can filter according to colors.
TRUE
FALSE
FALSE
a. 5
b. 2
c. 3
d. 4
b. Auto filtering
c. Filtering
d. Sorting
b. Filter
c. Short
d. Pivot Tables
Data Processing
a. Validation
b. Auto filter
c. Conditional formatting
d. Auto series
115
d. All of them
b. Filtering
c. Spelling
d. Subtotals
b. 3, 4, 5, 9 10
c. 9, 10
d. 6, 7, 8
FALSE
116
a. Count
b. Average
c. StdDev
d. VLookUp
Microsoft Excel
Project
1. Create a table including your friends names, surnames, birthdates, cities, addresses, etc. Copy this table onto
two more sheets. On the second sheet sort the friends table according to birthday order. On the third sheet
rearrange your friends according to their Cities and then addresses.
2. Collect different price lists from the companies in your town, for the same device. Create a custom list as shown
below, and sort the list according to the price in ascending order so that you can have a good reference of
cheaper prices.
3. Create the table in the following figure and then make the following
arrangements on the table by using Auto Filter.
Determine the most successful salesperson that carries out the best
sale.
Put the sales people in order according to their regions and sales.
4. For the figure next, write a criterion to list only the students
from class 10.
Data Processing
117
5. Use the table below and prepare the following Pivot Chart
Sports Qtr
Golf
Golf
Tennis
Tennis
Tennis
Tennis
Golf
Qtr3
Qtr4
Qtr3
Qtr4
Qtr3
Qtr4
Qtr3
Amount Field
$1,500
$2,000
$600
$1,500
$4,070
$5,000
$6,340
North
North
North
South
South
West
South
6. Collect the data from Golf and Tennis worksheets into a new workbook (Mc.Watson07.xlsx).
Golf
118
Tennis
Field
Qtr
Amount
Field
Qtr
Amount
North
South
South
West
Qtr3
Qtr4
Qtr3
Qtr4
$600
$1,500
$4,070
$5,000
North
North
South
Qtr3
Qtr4
Qtr3
$1,500
$2,000
$6,340
Microsoft Excel
CHARTS
After you process your data, you take outputs. Printing and Charts are the two
most common output forms of Excel. In Chapter 4, you studied Printing and
Page Setup. In this chapter, you are going to prepare Charts from your data.
Numbers can definitely present a lot of information, but most people get lost
in too many numbers. Especially, when presenting data to a crowd. People
are more interested in visual and graphical representations and they are
much easier to remember. For example, with a graphical chart, as in Figure
7.1, you can easily see whether your company sales are increasing or
decreasing, without having to analyze any number.
For your geography class, the data sheet for Istanbul city monthly weather
statistics has been given as in the Figure 7.2. And you are asked to prepare
a chart for this.
Solution:
First, select the data range A1:B12,
Then click Insert Charts Column 3d Clustered Cylinder.
Figure 7.3:
Charts group icons in the Insert Tab
Figure 7.4:
Istanbul city Monthly Weather Statistics
First view of your chart is ready. And now, you can make further
improvements on it.
120
Microsoft Excel
Charts
121
122
Microsoft Excel
Most of the tools in the Layout were -in a wayhidden in the previous Excel versions. We didnt
have them right away on the toolbars or in the
menus. You needed to have a little bit of experience
to reach them. But now, they are in front of us and
waiting for more tuning.
For example, for the previous example, we selected
Layout6 from the Chart Design Chart Layouts. By
default, it has Y-axis title but it doesnt have X-axis
title. You can change these by clicking Axis Titles
button from the Chart Layout Tools tab. To complete
our example, I added X-axis title as in Figure 7.13.
After adding the title -as you move or process other
Excel objects- you can move or format this title, too.
Or, if you want you can show more options and
make further changes.
Charts
123
6. Data Table: A grid that contains the numeric data used to create the chart.
The data table usually is attached to the category axis of the chart and
replaces the tick-mark labels on the category axis. Choose to display the
chart data in a data table.
The Show data table option displays the value for each data series in a
grid below the chart. This option is not available for pie, XY (scatter),
doughnut, bubble, radar, or surface charts.
Click the Show legend keys option to display legend keys, with the
assigned format and color for each plotted series, next to series label in
the data table.
124
Microsoft Excel
Example 7.2:
Your math teacher heard about Charts and he wants to prepare a chart for
his lesson. He has two exams and an average column. Now, help him
prepare this chart.
Students
Kevin Schmidt
Todd Rafferty
David Shadovitz
Pete Thomas
Pablo Varando
Average
Exam1
Exam2
Average
100
91
80
86
55
82
60
100
40
70
45
63
85
97
64
81
52
76
Solution:
Select the range and click Insert Charts Column Clustered Cylinder.
Then, insert the Chart Title using: Chart Tools Layout Labels Chart Title
Above Chart. Also change Primary Horizontal Axis style using: Chart Tools
Layout Axes Primary Horizontal Axis More Options Alignment
Custom Angle=0.
Charts
125
You can use your imagination and productivity to prepare nice looking charts
using fill effects. Just show the Format Chart dialog box (Figure 7.17c) from
Chart Tools Layout CurrentSelection Chart Elements combo
box.When you click on any chart object, the Format Chart dialog box allows
you to edit the properties of that object.
Figure 7.17: Changing the format using the Current Selection tools in Chart Layout
Tools tab.
This dialog box has many different options for changing the appearance of
the chart. You can place one of your pictures as a background; use gradient
fill effects; etc. The Shadow and Round corners options will definitely give a
nice look to your charts. Finally, using Chart Tools Format WordArt
Styles, you can modify the title text you used in your chart.
Now, you have finished modifying your chart. Here is the final look of our
chart. But, I believe you can prepare better charts with your good imagination.
126
Microsoft Excel
Questions
1. If you want to show the percentages of a
whole in a chart, what type of chart would
you prefer?
a. Line chart
b. Bar chart
c. Pie chart
d. Bubble chart
a. Home
b. Page Layout
c. Formulas
d. Insert
b. Source Data
c. Chart Layouts
d. Chart Type
b. Scatter
c. Pie
d. Surface
FALSE
b. Sometimes
c. No
d. It depends
Charts
II. Column
NAME
GRADE
John S.
Jack W.
Adreea T.
Bob C.
80
65
92
76
III. Pie
IV. Cone
a. III
b. I-III
c. III-IV
d. I-III-IV
127
Project
1. What type of chart would work best to represent the information in this worksheet?
A
1
2
3
4
5
6
7
B
C
D
E
Surat Co. Stores
Quarterly Sales Report
Quarter 1 Quarter 2 Quarter 3 Quarter 4
TV
4510
5000
12000
35000
Computer
5620
6000
4000
8000
Washing Machines
7840
8500
4700
10000
Walkman
800
2000
2500
3000
2. Use the Chart Wizard to create a chart that plots the cell range A4:E7. Title the Chart Quarterly Sales and
place the chart in a separate sheet.
3. Click the legend to select it and change the font size used in the legend to 12 pt.
4. Make the legend taller by about 0.5 taller, and drag it to the bottom right of the chart.
5. Change the chart type to a 3-D Bar chart.
6. Change the color of the Walkman series to light green.
7. Use the drawing toolbar to add an arrow that points to the largest number in the chart and add a textbox at
the other end of the arrow that says Super!
8. Change the chart data source so that only the totals for each component (cell range F4:F7) are plotted in the
chart.
128
Microsoft Excel
Practice
1. Make the following chart according to the Market Shares for automobiles in your country.
Charts
129
Words
Clues
AXES
130
Microsoft Excel
EXTRA OPTIONS
For different situations, we need to use different tools. And, there are many
tools in MS. Excel that facilitate data processing. It is very difficult to include
all Excel tools in such a small book. Therefore we are going to briefly explain
some useful tools and commands in this chapter.
1
2
3
4
5
6
7
8
9
A
ID
1
2
3
4
5
6
7
8
B
Name
Stephen Milligan
Samuel Neff
Brendan Hara
Jeremy Petersen
Todd Rafferty
Kevin Schmidt
David Shadovitz
Pete Thomas
C
Exam 1
9
5
7
9
10
9
10
8
D
Exam 2
8
6
10
7
10
10
8
7
E
Average
8.5
5.5
8.5
8
10
9.5
9
7.5
132
Microsoft Excel
Input Message:
You can enter a title and an input message that will be
displayed when you select the cell(s) in the range. If you
clear the check box, Input Message will be disabled.
Error Alert:
You can also enter a title and an error message that will
be displayed when someone enters an incorrect value.
There are three options; Stop, Warning, and Information
in the Style drop down menu.
Stop: Prevents you from entering an incorrect value.
Warning and Information: displays the error
message and asks if you are sure or not. If you say
OK, itll accept the value.
If you clear the check box at the top, the error alert will
be disabled.
Extra Options
133
While working with large worksheets, you sometimes, need to see different
parts at the same time. It can be difficult to go forward and backward
continuously. Microsoft Excel offers you two different options for such
situations: Freeze and Split.
134
Microsoft Excel
Select the cell where you want the screen to split and click the Split
button from View Window tab
To set only the horizontal pane, drag the split box (located above the
vertical scrollbar) down.
To set only the vertical pane, drag the split box (located to the right of the
horizontal scrollbar) left.
How to freeze;
Select the top-left most cell that will not be a part of the frozen panes.
From View tab Window, choose Freeze Panes (Figure 8.10).
To unfreeze it back, choose Unfreeze Panes from View Window tab.
Note: Tables automatically show the titles in place of column headings. In the
figure below, you can see column G, but other columns contain Table titles.
Figure 8.10: Freeze Panes
Extra Options
135
Example 8.2:
For example, to freeze the top row and the left column in the Figure 8.12,
select the cell C2, and then click Freeze Panes from View Window tab.
Thick lines will appear on the intersecting corner of the selected cell
representing the freezing point. Later on, while scrolling down or right the
Name and Surname columns, together with the column headings (Exam1,
Exam2, etc.) line will remain visible while the rest of the sheet moves.
Thick lines
continue all the
row and column
8.3
Microsoft Excel can create an outline for your data to let you show and hide
levels of details with a single mouse click. Firstly, your data should be proper
for outlining. That means, as in Figure 8.14, you should have all the formula
cells at the same columns and/or rows properly. If your formulas are not
placed in the same columns or rows, you can still use Auto Outline but it may
not produce your intended result.
If you want to use Auto Outline, firstly, you should have data that is grouped
like: Company, Division, Department, Budget Category, Budget Item, etc.
Then, you should design your formulas as in that order so that it can easily
be outlined. Here is an example:
136
Microsoft Excel
Example 8.3:
We have a list of classes, and each class has a list of lessons. At the end of
each lesson, we have an average formula for each lesson and a General
Average formula at the end. Now, if you want to create an outline for this
table.
You click somewhere in the table, then all you need to do is to click Auto
Outline from Data Outline Group tab.
Extra Options
137
Example 8.4:
If you dont want to use Auto outline or you dont want to outline the entire
table, you can outline only the parts that you wish. For example, you can
group columns B, C and D together.
Before applying Group and Outline, first, select any range of cells from
columns B to C. After that, select Group from Data Outline Group tab.
The Group dialogue window will be displayed. Select the Columns radio
button and Press OK.
After you press the OK button, you group columns B, C and D together. You
can show or hide these columns using the minus or plus buttons above the
column headings.
Example 8.5:
If you have vertical groups like class names, you can add the formulas
automatically using SubTotals button from Data Outline.
Select the entire table first, and then, use SubTotals button. It will show you
the SubTotal dialog box.
138
Microsoft Excel
From the At each change in box select the Class, then select the Average
function and select the columns that you add into Subtotal list. It will
automatically create the outline and all necessary formulas for you.
8.5
Comment
Extra Options
139
4. Click anywhere outside the comment area when you are finished.
To Delete a Comment:
1. Right-click the cell that contains the comment you want to delete.
2. Select Delete Comment from the popup menu.
140
Finally, press the Change Shape button and select the new shape.
Microsoft Excel
8.6 Tracking
Microsoft Excel can maintain and display information about how a worksheet
has been changed. Change Tracking logs details about workbook changes
each time you save a workbook. You can use this history to understand what
changes were made, and accept or reject changes. This capability is
particularly useful when several users edit a workbook. It is also useful when
you submit a workbook to reviewers for comments, and then want to merge
input into one copy, deciding which changes and comments to keep.
Itll open the Highlight Changes dialog box. Select the Track changes while
editing check box. This will activate the When, Who and Where boxes. Select
the necessary information for these boxes. For the address in the Where box,
click in the box first, then, without closing the dialog box, go and select the
range that you want to keep tracking. Excel will automatically write the
selected range address there. After you finish all, click OK.
This will start sharing your workbook and in your taskbar, your filename will
include the [Shared] word in brackets.
Extra Options
141
You can adjust more options in the Advanced tab. Track Changes: Specifies
whether to maintain the change history when you share the workbook.
Update Changes: Specifies how long you want to see changes from other
users. Conflicting changes between users: Specifies how you want to review
conflicting changes when you save the shared workbook.
142
Microsoft Excel
Include in personal view: specifies personal printing and filtering options for
the shared workbook. If you select one or both of the options below, your
choices are independently saved with your copy of the shared workbook.
After you share the workbook you can check who changed the document.
Itll show each change in the dialog box and on the sheet, and ask you to
Accept or Reject.
Untracked changes
Not all the changes are tracked. So be careful when you make the following
changes.
Change sheet names
Insert or delete worksheets
Format cells or data
Hide or unhide rows or columns
Add or change comments
Cells that change because a formula calculates a new value
Unsaved changes
Extra Options
143
8.7
Options Window
You can open the Options window from the Excel Options button in the Office
Menu. The Options window is like the headquarters of Microsoft Excel. It
provides flexibility according to user demands, which is very important in user
interface and user friendly environments. The options window contains
hundreds of different options for the user interface.
The good side of this new Excel Options is that, different than the older
versions, you can reach all options from a single dialog box. In this Options
window, there are 10 pages including: General, Formulas, Save, Advanced,
etc.
Figure 8.28:
Office Menu Excel Options
The General Tab contains mostly visual options. You can change color
scheme, show/hide the Mini toolbar and activate or deactivate Enable Live
Preview. With the help of Live Preview, when pointing to various formatting
choices, you can instantly see how those choices would appear on selected
text and objects. You also have different Screen tip options.
There are also default workbook properties when creating a new one. We
have font, default number of sheets for a new workbook, default view style,
etc. options for new workbooks.
144
Microsoft Excel
Extra Options
145
R1C1 reference style: You can switch between A1 and R1C1 reference
styles. In the A1 reference style rows are referenced by numbers and columns
are referenced by letters. But, the R1C1 style refers to both, rows and
columns, directly by numbers in your references. The R1C1 reference style
might be easier to use when you have complex macros and formulas.
Formula AutoComplete: providing tools help you to write your formulas
easily.
Use table names in formulas: When you use formulas that reference a table,
this option makes it easier to work.
Use GetPivotTable functions for PivotTable references: Determines the type
of cell reference that is created for a PivotTable cell
Error Checking
Enable background error checking: Select to have Excel check cells for
errors when idle. If a cell is found to have an error, the cell is flagged with an
indicator in the upper left corner of the cell.
146
Microsoft Excel
You can add, create new or remove your custom dictionaries. Or, you can
add edit them. There are also options for: checking for repeated words,
ignoring words in UPPERCASE, etc.
appearance
of
the
Extra Options
147
Custom Lists
Using this option, other than regular numerical
ones, you can create your own lists. You
commonly use the day or month lists. After you
define something as a list, you can
automatically fill a series of days, months,
etc by using Fill Series option.
First, write your series in cells in a worksheet.
Then, open the Custom Lists from Options
148
Microsoft Excel
Extra Options
149
Questions
1. validation criteria allow the user
to enter anything in the cell.
a. Decimal
b. Any value
c. List
d. Custom
b. Date
c. Time
d. Text Length
NOT DEFINED
b. In Office menu
FALSE
FALSE
NOT DEFINED
c. In View tab
d. In QAT
9. The Horizontal scroll bar cannot be seen
on this worksheet.
TRUE
FALSE
NOT DEFINED
FALSE
b. F8
c. F7
d. F9
FALSE
NOT DEFINED
FALSE
NOT DEFINED
Microsoft Excel
Practice
1. The City police department wants a computerized system
to accept visas. In order to avoid mistakes, they want to
keep the lists for countries and cities in separate ranges.
So, any input that is in this list will be accepted as valid
input. The police department wants Microsoft Excel to warn
for any other inputs.
Extra Options
151
9. AutoCorrect options
7. Color scheme
Tab
General
Formulas
Proofing
Save
Advanced
Commands
Font Size
Project
1. Find and change the default font properties in your Excel environment.
2. Prepare a questionnaire for your friends and put it in an Excel workbook. Start Tracking changes on the
document and give this diskette to 5 friends. After you take the diskette back, prepare charts for every
question in it and present the results of your survey to the class.
3. Prepare a workbook for your class that includes a column for Registration date. Use Excels Data Validation
feature to restrict entering any date later than 7/7/2009
4. Use the Freeze command to make the title row and names columns always visible.
5. Find and add your countrys language dictionary to the spelling options.
6. Put a password in your Excel workbook to open and modify.
152
Microsoft Excel
MACROS
154
Microsoft Excel
Macros
155
For beginners, recording macro is easier. You can record macro from the
Code in Developer tab. When you select Record Macro, Itll show the
Record Macro dialog box.
In this window, you can give your macro a name in the Macro name box and
then give a shortcut key for your macro. Because many programmers forget
the details about their programs after some time, its a good idea to give brief
information about the macro for later use. After you click OK, Record Macro
button will change to Stop recording.
And, Excelll start recording your actions. All your mouse clicks, cell
operations and other Excel commands will be stored in the macro until you
press Stop recording button.
Example 9.1:
Your brother prepares a document for his school homework. In his document,
he uses Delete cells command frequently. He wants you to do something to
simplify this process. He wants, every time he selects a range then presses a
shortcut key, the selected range to be deleted and the other cells to be
moved to left.
Solution:
Select the range that you want to delete.
Select Record Macro from Developer Tab
Write your macro name in the dialog box and
give a shortcut for your macro (Ctrl+Shift+D)
Press OK.
Now, it starts recording all your commands. So,
Right click on the selected area
Select Delete from popup menu.
It will ask you to move the cells up or left.
Select left and press OK
Press Stop Recording button to stop the process.
156
Microsoft Excel
You can see your macro using the Macros command in the Developer
tab. This will open the main window for Macros. You can do all operations
related to Macros from here, Figure 9.5. You can Run, Delete, Edit or Create
other macros from this window. When you press Edit button here, itll open
Microsoft Visual Basic Editor, Figure 9.6.
Insert User
Form
Run, Pause or
Opens Properties Window
Stop Macros Project Explorer Object Browser
Project
Explorer
Figure 9.5: Macros dialog box
Here is
your Macro.
Properties
window
The header of
subprogram
Explanation /
User Comments
Sub Macro1()
' Macro1 Macro
' Macro recorded 08.04.2009
'
' Keyboard Shortcut: Ctrl+Shift+D
'
Actual code
Macros
Selection.Delete Shift:=xlToLeft
End Sub
157
Now, your macro is ready to use. Any time you press Ctrl+Shift+D keys, it will
delete selected range of cells and move the right cells to the left.
Example 9.2:
We dont have a cube function in Excel, but, you can create it.
Open an empty Excel sheet.
Go to Developer Tab and click Macros. This will open the Macros window
which is initially empty.
Write Cube in the Macro Name box
Then click the Create button. This will open the VB Editor and create your
sub procedure.
158
Microsoft Excel
Parameter(s)
Function header
After your
calculations, you
return a result to
the name of the
function.
Figure 9.7:
Using VB functions in Excel
Then in your Excel sheet, you can use it as your other predefined
functions.
Macros
159
Worksheets(1)
Worksheets("Sheet1")
But using index number can be sometimes problematic, if you add and
remove worksheet, so, it is not suggested. Using a period as a separator, you
refer to an object in your VBA code by specifying its position in the object
hierarchy.
Application.Workbooks("Book1.xlsx").Worksheets("Sheet1").Range("A1")
You can omit default references. So, if you simply use Range("D3") when
youre in Sheet2, Excel uses the D3 cell of that worksheet from the active
workbook.
Range("C1:D3") = 5
Range("A:A") = 3
Range("5:5") = 4
The result is assigned to the variable: Name. And, you can use it in your
further processes.
You can show your messages using a windows dialog box.
MsgBox ("Hello World!")
Using &sign- ampersand sign-, you can concatenate two strings (add one
string to the end of another). When you execute the following command
Result =Range("C1") & "A"
second string (A) will be added to the end of first one. So, if Range ("C1")
contains "5", the Result becomes "5A".
160
Microsoft Excel
Statement
End if
Example 9.3:
You want to decide, according to his average, if a student has passed or
failed. The students pass if their average is greater than or equal to 5. Student
average is in D1 and you want to write the result to D2.
Sub Passes()
If Range("D1") < 5 Then
Result = "Failed"
Else
Result = "Passed"
End If
Range("D2") = Result
End Sub
Example 9.4:
In example 9.1, we had a sub procedure to delete selected cells. Now, add a
message, whether the user is sure to delete. If he presses yes, the selected
cells will be deleted.
Sub Macro1()
Name = InputBox("Enter your name please..:")
Selection.Delete Shift:=xlToLeft
End If
End Sub
Macros
161
Example 9.5:
Here is a function to calculate N!
Function NFactorial(Num As Integer)
Result = 1
For x = 1 To Num
Figure 9.11:
Using Functions in Excel
Result = Result * x
Next x
NFactorial = Result
End Function
162
Microsoft Excel
Student's
Name
Todd Williams
TRUE
FALSE
TRUE
TRUE
TRUE
TRUE
10
TRUE
11
TRUE
12
TRUE
13 10
TRUE
David OConner
Simon White
Shear Gambol
Alan Norman
Abraham Adair
Dave Ones
10
Active
Student
Order
14
Macros
163
Total correct formula in D14 is another formula. It uses the COUNTIF function
to count the number of TRUEs
=COUNTIF(D4:D13,TRUE)
The cell E4 will contain the active student order. So, the name and the result
will be copied into that row in the columns G and H. In the example above,
Todd Williams will be saved in the 7th row in columns F, G and H. These are
the formulas that will remain throughout all macro runs.
When recording, you can show
both the Excel window and VB
Editor at the same time to watch
your recording.
164
Microsoft Excel
Sub Macro1()
'
' Macro1 Macro
' Macro recorded 7/20/2009
'
' Keyboard Shortcut: Ctrl+Shift+P
'
Range("E4").Select
'Copy order
Selection.Copy
Range("F7").Select
Selection.PasteSpecial Paste:=xlPasteValues
Range("C1").Select
'Copy name
Selection.Copy
Range("G7").Select
Selection.PasteSpecial Paste:=xlPasteValues
Range("D14").Select
'Copy result
Selection.Copy
Range("H7").Select
Selection.PasteSpecial Paste:=xlPasteValues
Range("E4").Select
'Assigns the new value for order
ActiveCell.FormulaR1C1 = "8"
Range("C1").Select
Selection.ClearContents
Range("B4:B13").Select
Selection.ClearContents
Range("C1 ").Select
End Sub
Record finished but we need some modifications in this code. First of all, this
macro will always write the results to the 7th row. So, we need to modify the
resulting row order. For this purpose we can use a variable for the RowOrder.
Well take the RowOrder from E4 with,
RowOrder = Range("E4")
Then, instead of writing the result always to G7, we can concatenate and form
the new address as,
Range("G" & RowOrder)
Macros
165
Secondly, we dont have to copy paste every time. Instead, we can directly
assign the source value to the destination.
Range("G" & RowOrder) = Range("C1")
Range("E4") = RowOrder + 1
Range("B4:B13") = ""
Range("C1") = ""
Range("C1").Select
End Sub
166
Microsoft Excel
Solution:
The project is based on a simple idea: Paste Special. But using loops and
selection structures (If Then) makes it a little bit difficult. Here is the algorithm:
First, clear old data: the lesson and class averages, Range(C3:F4)
Get the Class and Student names from A3 and B3
Get the Number of students (LastSt) from A6
Start a loop from the 7th row until the LastSt number
Check if the current student (in the first case, Range(A7)) is from the
same class. If YES:
Copy the range CRowNumber:FRowNumber (e.g. C7:F7)
And use paste special with Operation:=xlAdd over the Range(C4:F4)
Check again to see if this is the student you are searching for
In this record macro, we want Excel to show us how to add the value of a cell
range onto another. So,
Macros
167
1. Sub GetData()
2. ' Getdata Macro
'Select source
Selection.Copy
'Copy
Range("C4").Select
'Select destination
:=False, Transpose:=False
Application.CutCopyMode = False
End Sub
Now, you learnt how to add a range onto another range. In this code, we can
skip the transpose and skipblanks parts, because we are not using them. So,
we only need to write:
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlAdd
Now, we are ready to write the entire code. To make it easy, your teachers
placed the number of students in the A6 cell. First, we get the data: Name
and Class information, from the cells A3 and B3
CName = Range("A3") ' Get Class Name from the cell A3
StName = Range("B3")' Get Student Name from the cell B3
LastSt = Range("A6")' Get The number of Students from the cell A6
StNum = 0 ' Because, we take the class average, we need to
' count the number of students in the class
Range("C4:F4") = "" ' Clear the range for the current operation
After we get initial data and prepare our result part for run, we can start
searching from the first until the last student. To repeat commands or a code,
we studied that we can use FOR NEXT loop structure from Basic
Programming Language.
For x = 1 To N
The code here will be repeated N times
Next x
168
Microsoft Excel
StName = Range("B3")
LastSt = Range("A6")
StNum = 0
Range("C4:F4") = ""
For x = 1 To LastSt
' y is the row order that contains current student name
y = 6 + x
If Range("A" & y) = CName Then
' If Class Name is the same as the current line info then
' Increment the number of students in the class
StNum = StNum + 1
'Copy this line to average part
Range("C" & y & ":F" & y).Select
Selection.Copy
Range("C4").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlAdd
' By saying Operation:=xlAdd we take
' the sum of each subject when pasting
' If current name is the same as the searching name (StName) then
If Range("B" & y) = StName Then
Range("C3").Select
Selection.PasteSpecial Paste:=xlPasteValues
' Paste the results also for this student onto Range("C3:F3)
End If
End If
Next x
'Calculate the averages
If StNum<> 0 Then
Range("C4") = Range("C4") / StNum
Range("D4") = Range("D4") / StNum
Range("E4") = Range("E4") / StNum
Range("F4") = Range("F4") / StNum
End If
Application.CutCopyMode = False
Range("C3").Select
End Sub
Macros
169
7. Group box
2. Combo box
8. Label
3. Check Box
9. Scroll bar
4. Spinner
5. List Box
6. Radio Button
Writing code is very easy with these controls. Now, well study Form Controls
and using them with Macros.
9.5.1 Button
When you select the Button tool, itll let you draw the size and place of the
button. After you define the place, it automatically opens the Assign Macro
window and asks you the name of macro to associate with this button. You
can
write a new macro name and press the New button
Figure 9.17: Assign Macro dialog box
Figure 9.18:
Combo box Format Control
170
Input range defines the items thatll appear in the list box. Cell link defines the
cell that will have the result of the selection. Using the Drop down lines box;
you can define the number of lines in the drop down list.
Microsoft Excel
When you select an item from the list, its order appears in the cell link (G1).
Vice versa, if you write a number into the linked cell that item is selected in
the combo box.
Similar to buttons and other Form Control items, you can assign macro to
drop down combo boxes. This macro will be automatically called every time
you change the value in the combo box. You can use the same methods,
which we described for buttons, to assign a macro.
Check box is usually used in true/false questions. You can find many samples
of check box in many programs. Except the initial state, check box has two
possible states; selected or unselected. For the initial state, there is the third
option: Mixed which means State is not available (not true but also not
false).
Same as the combo boxes, from the Format control Control tab, you can
assign a cell link and define other status options. Linked cell will contain
TRUE value, if the check box is checked. Otherwise itll have FALSE.
Option button also has the Assign macro option and Format Controls. In the
Control tab, it has cell link, value and 3-D effect options.
Example 9.6:
The accountant in your fathers company is using Excel worksheets in his
balances. He has difficulties in his balances. So, he wants to automate his
balance operations. As its shown on the next page, he designed two main
panes. The first part is for entering data starting from the third row. The
second part is beneath it and is the database that keeps all records. At the
top, he wants to see the total amount.
Macros
171
A
1
2
3
4
5
6
7
8
9
10
11
12
13
Expense Type
Amount
10
9
8
7
6
5
4
3
Expense Type
5
6
3
3
1
4
3
Figure 9.21a
C
D
TOTAL EXPENSES
6295
Date
Explanation
Date
16-May
16-May
16-May
16-May
16-May
16-May
16-May
Explanation
Amount
Seminar in Boston
2500
Seminar in California
380
A computer for accountancy
650
A computer for Secretary
650
John Clayton
1500
100 kg White paint
115
A new table for the big hall
500
172
Because, if we take 7 as the start point, every time we insert new record to
the top of the list, start address of Sum formula will also move down and the
newly inserted record will not be included in the formula.
Microsoft Excel
Now, we know what to do clearly, and all this can be recorded from the Macro
recorder. But for incrementation, you need to change the formula,
Range("A4") = Range("A4") + 1
Otherwise, the number youve written will be shown as a direct value and will
be repeated every time.
Sub Save()
'
' Save Macro
' Keyboard Shortcut: Ctrl+Shift+S
'
Range("A4:E4").Select
'Select
Selection.Copy
'Copy
Range("A7:E7").Select
'Select destination
Selection.Insert Shift:=xlDown
'insert
Range("A4") = Range("A4") + 1
'Increment A4
Range("C4:E4") = ""
End Sub
Example 9.7:
Your math teacher is organizing a contest throughout the school.
Because there are many students participating, he doesnt want to read
answer sheets one by one. He wants to use a macro to enter the answers
and check. To simplify the process for you, he doesnt want to keep the
individual result details in the computer. After you design this level, he
can ask once more to upgrade it :)
In the table, he has the correct answers in the C column. And a formula
in column D; giving +8 points, if the answer is correct; zero points, if
there is no answer( left blank); otherwise -1. For now, he wants option
buttons. Every time he clicks on an answer (option) button, that answer
will be put into students answers table in Column B.
Analysis and solution
After we design our worksheet and insert 5 option buttons, we can select
a cell as a cell link (for example C2). This selected cell link is
automatically applied for all the option buttons. (Note: The selected
option buttons number is shown in the cell link. So, you should pay
attention that the caption (visible text) over the first option button is A,
and on the second one is B, etc.) Students answers will appear in
column B; column C will have correct answers and column D will have
the result for every question.
Macros
173
In D19 we have a sum formula to calculate the current students total points.
When checking the student result for the first question, well check if B4=C4
or not. If it is, then, the result is 8. Otherwise, well have another If to check
whether the cell B4 is empty or not. If B4 is empty then the result is 0,
otherwise the result is -1. So, the formula is clear then;
=IF(C4=B4,8,IF(B4="",0, -1))
The main program is actually with option buttons. Every time, we click on an
option button, we want the answer we click to appear in the cell that Question
Number -in the cell D1- gives.
For example, when Question number in D1 is 11 and we click C, we want the
Macro to
write C in Question 11s place (cell B14)
and increment the Question Number to 12.
answer
answer
answer
answer
answer
=
=
=
=
=
1
2
3
4
5
Then
Then
Then
Then
Then
Result
Result
Result
Result
Result
=
=
=
=
=
"A"
"B"
"C"
"D"
""
QN = Range("D1")
Range("B" & QN+3) = Result
QN = QN + 1
Range("D1") = QN
If QN > 15 Then
res = Range("D19")
174
Microsoft Excel
Insert UserForm
button
Using the Insert UserForm button, you can insert Forms that have the
same properties as the Visual Basic environment.
User Form contains nearly similar toolbox. These tools have Visual Basic
environment properties, and have some more functions comparing with
Form Controls. After you design your Form using controls and arrange
their properties, you can show or hide it any time from any macro in the
workbook using the commands
Userform1.Show
UserForm1.Hide
Here Userform1 is the name of the form and it can be changed from the
Properties window. Similarly, in order to hide the user form, you can
assign the command Userform1.hide to a button.
Figure 9.24: Inserting UserForms
Example 9.8:
A nation-wide company wants to prepare a questionnaire for their future
product. In the questionnaire there are 10 questions with 5 multiple choices
each. Because of the high expenses the administration decided not to buy
an optical reader for just one questionnaire, and they want you to write a
macro that will take all the data into an Excel workbook for analyses.
Macros
175
Your task is to read and concatenate all 10 answers of each interviewer into
a cell and all questionnaires into a column. In order to simplify the process,
you decided to use option buttons. First you will be asked to enter some
specific data; pollster id and number of children in the family. Then, for the 10
multiple choice questions, every time you click on an option button A, B, C,
D, or E, it will concatenate the current choice to the end of the answers of the
current examinee. After that, itll increment the answer number by one. After
the 10th answer, we want Macro to ask you whether to save the data or not. If
you accept to save, the data will be stored in a special column otherwise the
data will be cleared.
Analysis and Solution: Before starting macros, first, you design the
worksheet. Youll have 5 option buttons for answers, and a combo box for
pollsters. You can have two macros. The first macro is Answers() which is
assigned to the option buttons. The second macro, Save, will be called from
the Answers() macro after processing question number 10. You can select the
cell link for the Option buttons: E4 and for Combo box: E5. E3 and E6 are
Questionnaire and Question numbers and will be changed from the macros.
The process; first, you are going to select the Pollster and write the number
of children into the B5 cell. Now, you are ready to enter the answers. Every
time you click on an option button its number will appear in the linked cell E4.
So, using E4, you can see which option button has been clicked.
If E4 is 1 then the converted result A will be added to the end of the Result,
If E4 is 2 then the converted result B will be added to the end of the Result, or
If E4 is 5 then the converted result E will be added to the end of the Result,.
Then the code can be like,
If Range("E3") = 1 then Result = Result & "A"
176
Microsoft Excel
Concatenation operator (&) is used to add the second string to the end of the
first one. So, if the Result is DDBC and we concatenate A, the new value
for the result will be DDBCA.
After we assign the proper letter to the end of the Resulting string, we
increment the Question number and save it to the cell E5. You check, every
time, whether the question numbers greater than 10 or not. If its greater,
then, you call the Save sub program; otherwise, we put the new value of
Question back to E5.
Sub Answers()
Answer = Range("E4")
QN = Range("E3") + 3
Question = Range("E6")
Result = Range("J" & QN)
'Convert the Answer into letter
If Answer = 1 Then Result = Result
If Answer = 2 Then Result = Result
If Answer = 3 Then Result = Result
If Answer = 4 Then Result = Result
If Answer = 5 Then Result = Result
Question = Question + 1
Range("E6") = Question
Range("J" & QN) = Result
If Question > 10 Then Call Save
End Sub
"A"
"B"
"C"
"D"
"E"
'Increment the Question number and
'Store back into E6
'Store current answers in column J
'If we finish all questions ask for saving
In the Subprogram Save, first we ask whether the user wants to save or not.
If he clicks the OK button, C will get the result 1, otherwise 2. If C is 1 then,
we save our data and increment QN by one. Otherwise, we clear our data
resetting the Question number to 1 and QN will remain the same.
Sub Save()
C = MsgBox("Do you want to Save?", vbOKCancel, "Warning") 'Ask for saving
Question = Range("E6")
'Get Question Number
QN = Range("E3") + 3
'Get Questionnaire Number
Result = Range("J" & QN) 'Get Answers
If C = vbOK Then
'You clicked OK and you want to save
Range("G" & QN) = QN - 3
'Put Questionnaire number into column G
Range("H" & QN) = Range("E5")
'Put PollsterID into column H
Range("I" & QN) = Range("B5")
'Put Number of children into column I
Range("J" & QN) = Result
'Put Answers into column J
Range("E3") = Range("E3") + 1
'Increment the Questionnaire number
Else
'You cancel
Range("H" & QN & ":J" & QN) = "" 'Clear written data
End If
Range("E6") = 1 'Reset Question Number
End Sub
Macros
177
Questions
1. If Range("A1") has 5 in it, what does the
following statement do?
ClassName =Range("A1") & "A"
b. Formula
c. Macro
d. User Form
b. Calculate Salary
c. FirstofAprilJokes
d. 2ndExpense
178
b. Check box
c. Button
d. Popup menu
b. Alt+F11
c. Ctrl+M
d. Ctrl+F5
b. Input range
c. Selected Item
a. Ctrl+F5
b. Alt+F7
c. Alt+F11
d. Ctrl+F12
Project
1. Mr. John Lions, Accountant of the MiCows Company, is
having difficulty with lots of calculations. He asked for
some help from the boss. And the boss selected you
for the job. Mr. John, to help you, numbered the
expenses. So, in a data board, he keeps the list starting
from the 11th row. From time to time, he wants, when he
runs the macro, to calculate the sum of each expense
type to be written to the summary list at the top.
3. Now, you are ready to write the previous project that you
prepared for your science teachers. This time they ask
for some combo boxes from you to simplify the
selections.
Your teachers will keep the class names in a separate
range of cells. There will be two separate combo boxes;
one for class names and another for students in the
selected class. Any time they select a class from the
combo box, the second combo box items will be
updated and will have the student list in the new class. When they select any student from the student combo
box, it will show the information on the selected student and averages for the selected class.
Macros
179
Practice
1. In Chapter 5 you prepared a formula for your teacher which takes 25% of two
exams and 50% of the final. Now, you are ready to prepare a function for him
2. Write a function to convert USD into Turkish Liras. Your function will take the amount
of dollars and exchange rate as parameters, and then calculate and return the
converted value.
3. Write a function to calculate the area of a circle with the given radius.
180
Microsoft Excel
E N T E R TA I N M E N T
Find the phrase by filling in the blanks below.
Homework
1. Create a new workbook and save it as Macro-1.xlsm
2. Select Developer tab Code Record New Macro from the menu.
3. In the Macro name box type Enter_Address,
4. Click OK to start recording.
5. Type your name, address, and phone number in the following format:
6. Click the cell that contains your name and make it bold.
7. Click the Stop button.
8. Clear the address information you just entered and try running your macro. You can modify this Macro to put
your signature to the end of your documents.
Macros
181
Chapter 1
1
A
2
A-C
3
A
4
D
5
A
6
C
7
D
8
D
9
B
10
A
11
C
12
B
13
B
14
C
15 FALSE
Chapter 2
1
C
2
B
3
D
4
A
5
A
6
C
7
B
8
D
9
D
10
D
11
B
12
C
13
A
14
A
15
C
16
D
17
B
18
B
Chapter 3
1
B
2
A
3
FALSE
4
A
5
B
6
D
7
B-D
8
C
9
B
10
C
11
D
12
A
13
D
Chapter 4
1
D
2
B
3
D
4
B-C
5
B
6
C
7
D
8
A
9
A
10
C
Chapter 6
1
TRUE
2
FALSE
3
A
4
D
5
B
6
C
7
D
8
B
9
B
10
B
11 FALSE
12
D
13
D
14
B
Chapter 7
1
C
2
A-D
3
C
4
D
5
C
6
C
7
D
8
TRUE
9
B
Chapter 8
1
B
2
B
3
B
4
TRUE
5
D
6
D
7
FALSE
8
TRUE
9
TRUE
10 FALSE
11
TRUE
Chapter 9
1
D
2
A
3
C
4
A-B-D
5
C
6
D
7
A
8
A
9
C
10
C
11
A
Chapter 5
1
C
2
D
3
A
4
B
5
B
6
C
7
D
8
D
9
TRUE
10
D
11
A
12
C
13
C
14
15
D
16
B
Abs 80
Gridline
57, 123
Group
D
Data 110, 132, 137, 176
Data Validation 132
Autofit 24
H
Header 43, 45, 55, 107, 157
Hidden 11, 20, 27, 41, 75, 112
Hide 11, 24, 27, 41, 108, 136, 175
HLookUp 90, 91
I
If 83, 85, 174
Index 92, 159
Border 24, 40
Enter 21, 22
F2 23
Cell 9, 21, 23
File format 16
Fill 20, 24, 36, 41
Fill series 20, 148
Filter 108, 109
Column 8, 9, 13, 15
L
Left 21, 22, 60, 89, 135
Len 89, 90
Link 26, 66, 110
Logical 76, 84, 90
M
MMacro 16, 149, 154
Margin 36, 55
Match 90, 92, 94
Merge 36, 40, 141
Message box 160
Method 155
Mid 89, 90
Fraction 23, 38
Module 154
Freeze 134
Currency 38, 39
Today 77, 86
Sin 81
Name Manager 44
Skip blanks 26
NetWorkDays 80
Smart tags 20
Now 77
R
Relative 69, 91, 92
Spacebar 22
Split 122, 134
Standard Deviation 87, 88
U
Undo 13, 26
Unhide 24, 27, 143
V
VB Editor 155, 157, 164
Visual Basic 154, 157, 164, 175
Resize 20, 24
Page break 8, 58
Scale 54, 57
Scrolling 136
Template 16
Select 20
Zoom 8, 9, 58, 59
Statistical 85, 88
VLookUp 90
Worksheet 9, 26, 28
Wrap text 36, 40
Y
Year 69, 77, 80
References
Excel 2007 for Project Managers
Microsoft Inc.
Microsoft Press