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

MO D U L A R

S YS T E M

MICROSOFT EXCEL 2010

brahim MEECAN

http://book.zambak.com

Copyright Srat Basm Reklamclk


ve Eitim Aralar San. Tic. A..
All rights reserved.
No part of this book may be
reproduced, stored in a retrieval
system, or transmitted in any form of
recording without the prior written
permission of the publisher.
Digital Assembly
Zambak Typesetting & Design
Editor
Osman AY
Proofreader
Andy MARTIN
Page Design
Serdal YILDIRIM
Edip TRK
Publisher
Srat Basm Reklamclk ve Eitim
Aralar San. Tic. A..
Printed by
alayan A.. Sarn Yolu zeri No:7
Gaziemir / Izmir, September 2009
Tel: +90-0-232-252 22 85
+90-0-232-522-20-96-97

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

"Microsoft, MSN, Microsoft Excel 2010, Microsoft Office 2010, and


Windows are either registered trademarks or trademarks of Microsoft
Corporation in the United States and/or other countries."

1. Spreadsheet Basics

Modifying Cell Contents . . . . . . . . . . . . . . . . . . 23


Cell, Row or Column Operations . . . . . . . . . . . . . 24

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

Hiding and Unhiding Cells . . . . . . . . . . . . . . . . 24


Deleting Inserting . . . . . . . . . . . . . . . . . . . . . . 24
Cut, copy, paste operations . . . . . . . . . . . . . . . . . 25
Paste Special. . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Worksheet Operations . . . . . . . . . . . . . . . . . . . . . 26
Deleting a worksheet: . . . . . . . . . . . . . . . . . . . . 26
Renaming a worksheet: . . . . . . . . . . . . . . . . . . 26

Customizing your Quick Access Toolbar . . . . . . . 13

Moving or copying a worksheet . . . . . . . . . . . . 26

Excel with the Numbers:. . . . . . . . . . . . . . . . . . . . 13

Inserting an empty worksheet. . . . . . . . . . . . . . 27

Your First Excel Application . . . . . . . . . . . . . . . . . 14

Selecting Multiple Worksheets . . . . . . . . . . . . . 27

Creating a New Workbook . . . . . . . . . . . . . . . . 14

Changing the active worksheet. . . . . . . . . . . . . 27

Filling in the month names . . . . . . . . . . . . . . . . 14

Hiding or Unhiding a worksheet . . . . . . . . . . . . 27

Applying table format . . . . . . . . . . . . . . . . . . . . 15

Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29

Creating a chart from your data . . . . . . . . . . . . 15


Saving your document . . . . . . . . . . . . . . . . . . . 16

Word Search Puzzle . . . . . . . . . . . . . . . . . . . . . . . 32


Practice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33

Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

3. Formatting Your Documents


2. Worksheet and Cell Operations

Formatting Tools . . . . . . . . . . . . . . . . . . . . . . . . . 36

Mouse Pointers . . . . . . . . . . . . . . . . . . . . . . . . . . 20

Using The Format Cells Dialog Box . . . . . . . . . . . 37

Cell Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . 21

Number . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37

Selecting a Cell or an Area . . . . . . . . . . . . . . . . 21

Alignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39

Entering data in a cell . . . . . . . . . . . . . . . . . . . . 21

Font . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40

Using arrow keys instead of pressing Enter . . . 21

Borders . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40

Moving Through a Selected Area . . . . . . . . . . . 22

Fill . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41

Selecting multiple cells, rows or columns . . . . 22

Protection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41

Entering data in an area . . . . . . . . . . . . . . . . . . 22

Document Themes . . . . . . . . . . . . . . . . . . . . . . . . 42

Entering numbers with fractions . . . . . . . . . . . . 23

Using Styles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42

Using Format Painter . . . . . . . . . . . . . . . . . . . . . . 43

Creating a link formula by pointing . . . . . . . . . . 67

Using Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43

Writing Your First Formula . . . . . . . . . . . . . . . . . . 67

What is table? . . . . . . . . . . . . . . . . . . . . . . . . . . 43

Operators in Excel Formulas. . . . . . . . . . . . . . . 68

Creating a table . . . . . . . . . . . . . . . . . . . . . . . . . 44

Absolute and Relative Reference . . . . . . . . . . . 69

Table AutoFormat . . . . . . . . . . . . . . . . . . . . . . . 44

Simple Functions: . . . . . . . . . . . . . . . . . . . . . . . . . 70

Some facilities for tables . . . . . . . . . . . . . . . . . 44

Sum Function . . . . . . . . . . . . . . . . . . . . . . . . . . 71

Conditional Formatting . . . . . . . . . . . . . . . . . . . . . 45

Average Function . . . . . . . . . . . . . . . . . . . . . . . 72

Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47

Max and Min Functions . . . . . . . . . . . . . . . . . . . 73

Practice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
Word Search Puzzle . . . . . . . . . . . . . . . . . . . . . . . 51

Count Function . . . . . . . . . . . . . . . . . . . . . . . . . 73
All in One: Subtotal . . . . . . . . . . . . . . . . . . . . . . 74
Using Functions and Formulas. . . . . . . . . . . . . . . 76

Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52

Date and Time Functions . . . . . . . . . . . . . . . . . 77


Math and Trigonometric Functions . . . . . . . . . . 80

4. Page Setup and Printing


Page Layout Tab . . . . . . . . . . . . . . . . . . . . . . . . . 54
Page Tab . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
Margins Tab . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
Header/Footer Tab. . . . . . . . . . . . . . . . . . . . . . . 56

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

Preparing Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . 104


Sorting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
Using Fast Sort . . . . . . . . . . . . . . . . . . . . . . . . . 104
Custom Sort . . . . . . . . . . . . . . . . . . . . . . . . . . . 105

Word Search Puzzle . . . . . . . . . . . . . . . . . . . . . . . 63


Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64

Custom Lists. . . . . . . . . . . . . . . . . . . . . . . . . . . 108


Filtering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
Quick Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108

5. Functions and Formulas


Understanding Functions and Formulas . . . . . . . 66
Linking Worksheets . . . . . . . . . . . . . . . . . . . . . . . 66

Advanced Filter. . . . . . . . . . . . . . . . . . . . . . . . . 109


Consolidating Worksheets . . . . . . . . . . . . . . . . 110
Consolidating worksheets by using formulas . 110
Using Consolidate Command . . . . . . . . . . . . . 111

Pivot Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112

Comment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139

Inserting Pivot Table . . . . . . . . . . . . . . . . . . . . . 112

To Insert a Comment: . . . . . . . . . . . . . . . . . . . . 140

Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115

To Format a Comment: . . . . . . . . . . . . . . . . . . 140

Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117

To change Comment Shape . . . . . . . . . . . . . . 140


Tracking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141

7. Charts
Inserting Charts . . . . . . . . . . . . . . . . . . . . . . . . . . 120
Chart Tools: Design Tab. . . . . . . . . . . . . . . . . . . . 121

How to Use Change Tracking . . . . . . . . . . . . . 141


Sharing a Workbook. . . . . . . . . . . . . . . . . . . . . 142
Display changes. . . . . . . . . . . . . . . . . . . . . . . . 143

Chart Layouts . . . . . . . . . . . . . . . . . . . . . . . . . . 121

Options Window . . . . . . . . . . . . . . . . . . . . . . . . . 144

Chart Types . . . . . . . . . . . . . . . . . . . . . . . . . . . 121

General Tab . . . . . . . . . . . . . . . . . . . . . . . . . . . 144

Chart Styles . . . . . . . . . . . . . . . . . . . . . . . . . . . 122

Formula options . . . . . . . . . . . . . . . . . . . . . . . . 145

Chart Tools: Layout Tab . . . . . . . . . . . . . . . . . . . . 123

Proofing Options . . . . . . . . . . . . . . . . . . . . . . . 146

Layout In Brief. . . . . . . . . . . . . . . . . . . . . . . . . . 123

Save Options . . . . . . . . . . . . . . . . . . . . . . . . . . 147

Chart Tools: Format Tab. . . . . . . . . . . . . . . . . . . . 124


Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
Practice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129

Advanced Options . . . . . . . . . . . . . . . . . . . . . . 147


Customize . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
Trust Center . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150

Word Search Puzzle . . . . . . . . . . . . . . . . . . . . . . . 130


Practice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152

8. Extra Options
Data Validation . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
Data Validation Allow Options . . . . . . . . . . . . . 134

9. Macros

Freeze and Split Panes . . . . . . . . . . . . . . . . . . . . 134

Before Starting Macros . . . . . . . . . . . . . . . . . . . . 154

Splitting Panes . . . . . . . . . . . . . . . . . . . . . . . . . 134

Displaying Developer Tab . . . . . . . . . . . . . . . . 154

Freezing Panes. . . . . . . . . . . . . . . . . . . . . . . . . 135

Some Definitions . . . . . . . . . . . . . . . . . . . . . . . 154

Displaying a workbook in more than


one window . . . . . . . . . . . . . . . . . . . . . . . . . . . 136

Security first . . . . . . . . . . . . . . . . . . . . . . . . . . . 155


Writing Your Macros. . . . . . . . . . . . . . . . . . . . . . . 156

Synchronous Scrolling two workbooks . . . . . . 136


Group and Outline . . . . . . . . . . . . . . . . . . . . . . . . 136
Using Watch window . . . . . . . . . . . . . . . . . . . . . . 139

Recording Macros . . . . . . . . . . . . . . . . . . . . . . 156


Writing Macros Manually . . . . . . . . . . . . . . . . . 158
Types of Macro Procedures . . . . . . . . . . . . . . . 158

Macro Language . . . . . . . . . . . . . . . . . . . . . . . . . 159


Excel Object Hierarchy. . . . . . . . . . . . . . . . . . . 159
Object Collections . . . . . . . . . . . . . . . . . . . . . . 159
Assigning value to a cell. . . . . . . . . . . . . . . . . . 160
Using Message Box and Input Box . . . . . . . . . 160
Concatenating Two Strings . . . . . . . . . . . . . . . 160
Using Basic Programming Language
in your macros . . . . . . . . . . . . . . . . . . . . . . . . . 160
Object Browser. . . . . . . . . . . . . . . . . . . . . . . . . 162
Ready for a bigger project? . . . . . . . . . . . . . . . . . 163
Want More? (Optional) . . . . . . . . . . . . . . . . . . . 166
Form Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
Button . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
Combo Box . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
Check Box . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
Option Button . . . . . . . . . . . . . . . . . . . . . . . . . . 171
Using User Forms . . . . . . . . . . . . . . . . . . . . . . . . 175
Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178
Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
Practice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180
Entertainment . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
Homework . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181

ANSWER KEY AND INDEX


Answer Key . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183

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.

1.2 Screen Elements and Definitions


Quick Access Toolbar
Office Button

Ribbon-The new style toolbar Application and window buttons

Formula bar

Tab list

Columns

Name box

Rows

Active cell
indicator
Row Numbers

Sheet tabs
scroll buttons

Sheet tabs

Status bar

Page view buttons

Page zoom

Figure 1.1: Screen Elements

Microsoft Excel

1.2.1 Parts of Excel Screen That You Need to Know


Name

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.

Application and window


These are standard window buttons that are used to minimize, maximize-restore and close.
buttons
Office button

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.

Page view buttons

Change the way the worksheet is displayed: Page break preview, Page layout, Normal.

Quick Access Toolbar

A toolbar that you customize to hold your own commonly-used commands.

Tab list

Commands that display a different ribbon, similar to a menu.

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

A scroller that lets you zoom your worksheet in and out.

Spreadsheet Basics

The Usage Areas of Excel


 Numeric processing: Create budgets, analyze results, and perform just
about any type of financial analysis.
 Creating charts: Create a wide variety of highly customizable charts.
 Organizing lists: Easy to use the row-and-column layout to store lists
efficiently.
 Data Conversions: Import and export data from/to a wide variety of
sources.
 Automating complex tasks: While storing data, also performs complex
tasks with a single mouse click using Excels macro capabilities.

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.

Figure 1 2: Home tab in the Ribbon

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.

The appearance of the commands on the


ribbon varies, depending on the width of Excel
window. When the window is too narrow to
display everything, the commands adapt and
may seem to be missing. But the commands
are still available. Figure 1.2 shows the Home
tab of the Ribbon with all controls fully visible.
Figure 1.3 shows the Ribbon when Excels
window is made narrower. Notice that some of
the descriptive text is gone, but the icons
remain.

Figure 1.3: The Ribbon when Excels window is made narrower

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.

Figure 1.4: The Ribbon when Ctrl+F1 is pressed

1.3.1 Contextual Tabs


Some other special tools appear
according to the selected items. These
are called Contextual tabs. For
example, when you select a picture the
Picture tools tab appear. Similarly, in
the figure next, because a chart is
selected, the Chart Tools tabs are
shown.

Spreadsheet Basics

Figure 1.5: Contextual tabs: Chart tools

11

1.4 Accessing the Ribbon using your keyboard


At first glance, you may think that the Ribbon is completely mouse-centric.
But in fact, the Ribbon is very keyboard friendly. The trick is to press the Alt
key to display the pop-up keytips. Each Ribbon control has a letter (or series
of letters) that you type to issue the command. After you press the associated
letters the commands are executed or related task window is opened.

Figure 1.6a: Accessing the Ribbon using your keyboard

 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)

1.5 The Shortcut menus and the Mini Toolbar


When you right click on any area, the shortcut menu is shown. The box above
the shortcut menu is known as the Mini toolbar and contains commonly used
tools from the Home tab. It doesnt contain any relevant command, just those
that are most commonly used for whatever is selected.
The Mini toolbar was designed to reduce the distance your mouse has to
travel around the screen. Its is especially useful when a tab other than Home
is selected.

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

1.6 Customizing your Quick Access Toolbar


By default, the Ribbon doesnt include all of the commands that are
available in Excel. You can add any command that you want to
have a quick access (that arent available by default in the Ribbon
or your most common commands) to QAT.
You could change all the toolbars and menu items in Office 2003.
But since Office 2007, you can customize only the Quick Access
Toolbar (QAT) and your custom tabs. Initially, QAT includes only:
Save, Undo and Redo commands.
To add these commands to QAT, just right click on QAT and select
Customize from the menu. It will open the Excel Options window.
Here you can select the commands from the left pane and add them in QAT.

Figure 1.9b: Using Custom tabs in the Ribbon

Figure 1.9a: Customizing QAT

Figure 1.9c: Customizing QAT

1.7 Excel with the Numbers:


Number of rows
Number of columns
Amount of memory used
Number of colors
Number of levels of sorting
Number of levels of undo
The total number of characters that can display in
a cell
Number of unique styles in a workbook
Maximum number of characters in a formula

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

Your First Excel Application

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.

1.8.1 Creating a New Workbook


Start Excel and make sure that you have an empty workbook displayed. To
create a new, blank workbook;
 press Office button and select New from the menu. Itll show you another
window with some options. Select Blank Workbook Finally click Create
button on the right.
 Or simply press Ctrl+N to open a new blank workbook.
Figure 1.10: Office button

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 1.11: Filling in series

1.8.2 Filling in the month names


 After you write the first month, Select A2 again and take your mouse
pointer to the bottom right corner of the active cell. You will see that your
mouse pointer changes into a black line plus sign.

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

1.8.3 Applying table format


 Select the entire table and click the Format as Table button from Styles
group in the Home tab. It will show you many different preformatted table
options.
 After you select one, it will ask you the location of Data for the table.
Because you selected the table before you start, just click OK.
 Now you have professionally designed a nice looking table.
Figure 1.12:
Format as Table dialog box

Figure 1.13: Applying table format

1.8.4 Creating a chart from your data


 Select the Months and Height columns.
 Click the Column button from the Charts group in the Insert menu. Then
select the 3-D Clustered Column from the list.
 Now select the Months and Weight columns and click Clustered Cylinder
in the Charts group in the Insert menu.
 Your charts are ready now

Figure 1.14: Chart Type and Subtype

Figure 1.15: Monthly Baby Growth Charts

Spreadsheet Basics

15

1.8.5 Saving your document


Now you finished and you can save your document.
 You can click on the Save button from the QAT.
 Or, you can click the Save button from the Office button
 Or, use Ctrl + S shortcut keys
 It will show you the Save As dialog box. Write the File name (Baby
Growth) and click the Save button on the bottom right corner.

Figure 1.16: Saving the document

Excels new file formats are


 XLSX: A workbook file that does not contain macros
 XLSM: A workbook file that contains macros
 XLTX: A workbook template file that does not contain macros
 XLTM: A workbook template file that contains macros
 XLSA: An add-in file
 XLSB: A binary file similar to the old XLS format but able to accommodate
the new features
 XLSK: A backup file

16

Microsoft Excel

Questions
1. What kind of program is Microsoft Excel?

5. Which is not the way of saving a workbook?

a. Word processing

a. <Ctrl+F5>

b. Spreadsheet

b. Click Save on the Home tab.

c. Database

c. Click Save from the Office button.

d. Graphics

d. <Ctrl+S>

2. You can reach all Excel commands from


the. (Choose all that apply)
a. Ribbon

6. What file extension will normally be used


for a file created by Microsoft Excel?
a. ppt

b. Menu bar

b. xlsb

c. xlsx

d. exe

c. Quick Access Toolbar


4

d. Status bar
1
3. Which of the following commands is not in
the Home tab?
a. Print Preview
b. Merge and center

Answer questions 7-10 according to this figure

7. Which is used to change cell alignments?


a. 1

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

9. Which icon is used to copy the format of


the cells?
a. 1

b. 3

c. 5

d. 6
17

10. Which icon is used to change border


style?
a. 5

b. 7

c. 8

d. 9

14. Can you use all Excel 2003 shortcuts in


Excel 2007?
a. Some of them
b. Most of them
c. All of them
d. None of them

11. How many rows are there in an Excel 2007


document?
a. 65536
b. 256
c. 1048576

15. You can change the commands in the


Ribbon.
TRUE 

FALSE 

d. 16384

12. How many columns are there in an Excel


2003 document?
a. 65536
b. 256
c. 1048576
d. 16384

13. What key is used to access Ribbon


commands?
a. Ctrl
b. Alt
c. Shift
d. Ctrl+Alt

18

Microsoft Excel

WORKSHEET AND CELL OPERATIONS


2.1 Mouse Pointers
There are different mouse pointers when working with Excel.

The Select mouse pointer is used to select a cell or


a range.

Select Column/Row is used to select rows or


columns.

Unhide (show) a hidden row or column.

Copy/Fill series When you see this type of mouse


pointer, and drag your mouse while right button
pressed, a popup menu similar to Figure 2.1 will
appear next to the last cell:
1. Copy cells: Copies and applies the format of the
source cell to destination cells
2. Fill series: While applying the source format,
automatically defines incrementation in the source,
and fills series.
3. Fill formatting only: Just applies the formatting of
the source cell(s) to the destination
4. Fill without formatting: Fill series or copy without
formatting.
Figure 2.1: Fill series popup menu

To activate Smart Tags, choose


the Office Excel Options and
click the Advanced Tab. Set
Show Paste Options in Cut
Copy Paste options.

20

Move mouse pointer is used to move a range. Select


the range that you want to move, then position your
mouse pointer over a cell corner. When you see this
type of mouse pointer drag it to the place that you
want to move to. If the destination cells have data in
them, Excel will prompt to overwrite.
Resize is used to resize columns or rows

Microsoft Excel

2.2 Cell Operations


2.2.1 Selecting a Cell or an Area
When you see the Select type of mouse pointer and click a cell, Microsoft
Excel makes it the Active cell. When you click a cell and drag the mouse to
another cell, all the cells between them will be selected as a range.
Press Ctrl+A on an empty area to select all the cells in a worksheet. If the
active cell indicator is in a list (table), Ctrl+A will only select the table.

2.2.2 Entering data in a cell


In order to enter data or formula in a cell, select it and type what you need
followed by Enter key. If you need to type multiple lines of text in the same
cell, press <Alt+Enter> at the end of each line.
By default, when you press the Enter key, Excel automatically moves the cell
pointer to the next cell down. To change this setting, choose Office Excel
Options and click the Advanced tab. The check box that controls this
behavior is labeled: After Pressing Enter, Move Selection. You can also
specify the direction in which the cell pointer moves (down, left, up, or right).
Your choice is completely a matter of personal preference.

If you want to cancel your data


entry and return the cell to the
previous state, press Esc key.

Figure 2.2: Moving selection, after entering data

2.2.3 Using arrow keys instead of pressing Enter


When youre finished making a cell entry, you can also use any of the
direction keys to complete the entry. Not surprisingly, these direction keys
take you in the direction that you indicate. For example, if youre entering data
in a row, press the right-arrow key rather than Enter. The other arrow keys
work as expected, and you can even use PgUp and PgDn.

Worksheet and Cell Operations

21

2.2.4 Moving Through a Selected Area


In order to move throughout a selected area, after entering the data or
formula, without changing the selected range, four combinations can be
used;
1. <Enter> : Normally; the active cell moves to the next cell down.
2. <Shift+Enter>: the cell above becomes the active cell.
3. <Tab> : the right cell becomes the active cell.
4. <Shift+Tab> : the left cell becomes the active cell.
You can also use the F8 key to
select a range. First, activate the
first cell of the selection and
press F8. Then, using your
keyboard or mouse, select the
last cell. Press F8 again to finish
selection.

Press [Ctrl + Spacebar] to select


the active column and [Shift +
Spacebar] to select the active
row.

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.

2.2.5 Selecting multiple cells, rows or columns


Using the SHIFT key and mouse (or with arrow keys), you can select multiple
consecutive cells, rows, or columns. For this, first you select the initial cell,
then hold down the SHIFT key, using arrow keys or mouse, select the final
cell. Excel will automatically select all the cells between the first and last
locations.
Using the CTRL key and left mouse click, you can select multiple cells from
different places. You can use the same method with rows or columns.

2.2.6 Entering data in an area


After you select your data range, using the four combinations that we
discussed in Section 2.2.4, you can move through and enter your data. In
place of ENTER, use <Ctrl+Enter> to fill all the selected range with the same
text.

Figure 2.3: AutoComplete

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

2.2.7 Entering numbers with fractions


To enter a fractional value into a cell, leave a space between the whole
number and the fraction. For example, to enter

(three and a half), enter

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.

2.2.8 Modifying Cell Contents


After you enter a value or text into a cell, you can modify it in several ways:
 Erase the cell contents
 Replace the cell contents with something else
 Edit the cell contents
To erase the contents just select the range of cells and press the Del button
on the keyboard. Or for replacing, just select the cell and type your new data.
But for modifying the contents we have something more to talk about.
If the cell contains only a few characters, replacing its contents by typing new
data is usually easier. But if the cell contains lengthy text or a complex formula
and you need to make only a slight modification, you probably want to edit
the cell rather than re-enter information. When you want to edit the contents
of a cell, you can use one of the following ways to enter cell-edit mode:
 Double-clicking the cell
 Selecting the cell and pressing F2
 Selecting the cell that you want to edit and then clicking inside the
Formula bar
enables you to edit the cell contents. You can use whichever method you
prefer. Some people find editing directly in the cell easier; others prefer to
use the Formula bar to edit a cell.

Worksheet and Cell Operations

23

2.3

Cell, Row or Column Operations

2.3.1 Resizing and auto sizing rows columns:


Using the Resize mouse pointer, you can change the width of columns and
height of rows. First select the column(s), then, when you see the Resize
mouse pointer drag to the width that you want to.
Figure 2.5a

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.

2.3.2 Hiding and Unhiding Cells


Figure 2.5b:
Resizing columns

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.

2.3.3 Deleting Inserting


a. A cell or a group of cells
When you want to delete a cell itself (not the content of that cell, all the cell
itself and contents physically) right click on it and select Delete from the
popup menu. Because the cell will be deleted physically, like a wall of bricks,
the space cannot be empty, other cells will fill in the space.
In this case, after deleting the selected range, you will have four options, in
order to fill the space. It will,
Figure 2.6: Delete dialog box

1. Shift cells left: move the cells on the right to left


2. Shift cells up: move the bottom cells up
3. Entire row: delete the entire row(s) and move all of the bottom rows up.
4. Entire column: delete the entire column(s).

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.7: Insert cells dialog box

2.4 Cut, copy, paste operations


Cut, Copy, and Paste operations are similar to other Windows applications.
After you select a range, right click on the selected area. From the popup
menu, select Cut or Copy. The cells are copied into the office clipboard and
ready to be pasted. Just select the starting cell of the destination, and then
from the popup menu select Paste. This will paste all data and formats of the
source to the destination.

2.4.1 Paste Special


Paste special is one of the most efficient features of Excel. In many
conditions, you cannot copy all: formats, data, formulas, etc. to the destination.
Sometimes, you want to copy only the values or formulas or comments. For
this purpose, Paste Special offers many useful options for users. Most of
them are clear in the meaning and dont need any further explanation.
1. All: Pastes all, which is the same as regular paste.
2. Formulas: Pastes just the formula while adjusting the formula according
to the destination (See Absolute and Relative Reference in Section 5.3.2).

Figure 2.8:
Paste special dialog box

3. Values: Pastes only the resulting values of formulas.


4. Formats: Paste only the format.
5. Comments: Paste only the comments.
6. All using Source theme: Pastes all cell contents in the document theme
formatting that is applied to the copied data.
Operation
When having numerical values, you can use Paste special to make arithmetic
operations. For example, you can copy a range over another range and
select the Multiply operation. Excel multiplies the values in the source and the
destination ranges and replaces the destination with the new values.

Worksheet and Cell Operations

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.

2.5 Worksheet Operations


2.5.1 Deleting a worksheet:
If you are sure to delete the Entire worksheet, right click on the worksheet
name then select Delete from the popup menu. There is no undo after you
delete a worksheet and you cannot get your data back, Excel will ask whether
you are sure to delete or not.

2.5.2 Renaming a worksheet:


In order to rename a worksheet, right click on the worksheet name and then
select Rename from the menu. Or you can also double click on the worksheet
name and make your change.
Figure 2.10: Deleting a worksheet

When renaming worksheets you should know these details:


 Sheet names can be up to 31 chars (characters)
 Spaces are allowed and each is counted as one char
 Following chars are not allowed in sheet names: (?) Question mark, (*)
Asterisk, (:) Column, (/) Slash, (\) Backslash

2.5.3 Moving or copying a worksheet


2

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

2.5.4 Inserting an empty worksheet


Sometimes, you may need a new worksheet. Right-click on a
worksheet name, and from the popup menu select Insert.
Excel will open the Insert window.
There are two tabs in this window. The general tab shows
general options: Dialog, Chart, Macro or Worksheet. If you
select the Worksheet option, it will insert an empty worksheet.
If you select the Chart option, it will show necessary tools to
prepare a chart and so on. The chart, macro and dialog box
options will be studied later.
The Spreadsheet solutions are ready to use, predesigned
Excel workbook templates. Like: Personal monthly budget,
etc. They are from MS. Office and you can find many more on
Office Online.

Figure 2.12: Insert dialog box

2.5.5 Selecting Multiple Worksheets


Similar to selecting multiple cells, using the CTRL and SHIFT keys you can
select multiple worksheets. When selecting an adjacent group of worksheets,
first select the starting worksheet. Then while holding down the SHIFT key,
select the last sheet of the adjacent list. All of the worksheets between these
two will be selected.
When selecting nonadjacent worksheets, select the first worksheet and then
hold down CTRL and click the other worksheets one by one.
After selecting multiple worksheets, your formatting and cell entries or
column row operations are applied to all selected sheets.

2.5.6 Changing the active worksheet

When you work on multiple


workbooks you can switch
between
workbooks
using
Ctrl+Tab or Ctrl+F6.

Using the <Ctrl+PgUp> or <Ctrl+PgDn> keys, you can activate different


sheets. Or, using the navigation buttons, you can move through the
worksheets and use the mouse to activate the worksheet that you want.
If you want to select multiple worksheets, hold down the CTRL or SHIFT keys
and use the Page Up or Page Down and Space bar keys.

2.5.7 Hiding or Unhiding a worksheet


Hiding sheets in some situations can be useful. When you design a workbook
and you dont want users to see your program details, you can hide it. You
can (un)hide worksheets from Home Cells Format Hide&Unhide. When
you select Hide, selected sheet(s) are hidden. Later, they can be shown from
the same place using the Unhide command. (Or, right click on the Sheet Tabs
and select Hide or Unhide.)

Worksheet and Cell Operations

Figure 2.13: Hiding sheets

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

If the Developer tabs not visible,


you can show it from Excel
Options Customize Ribbon.

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>

5. Which key combination is used to change


the active worksheet?
a. <Ctrl+Page Up>
b. <Shift+Page Up>
c. <Ctrl+Spacebar>
d. <Alt+Page Down>

2. How do you select an entire row?


a. View>Select>Row from the menu.
b. Click the Row heading.

6. To select multiple cells, which keys are


held down while clicking the mouse?

c. Hold down the CTRL key as you click


anywhere in the row.

a. ALT or SHIFT

d. Hold down the SHIFT key as you click


anywhere in the row.

c. SHIFT or CTRL

b. ALT or CTRL

d. ALT and SHIFT or CTRL


3. What is <Shift+Tab> used for?
a. Moves the active cell indicator one cell down.
b. Moves the active cell indicator one cell up.
c. Moves the active cell indicator one cell right.

7. Which key is used to modify data in a


selected cell?
a. F1

b. F2

c. F3

d. F4

d. Moves the active cell indicator one cell left.


8. To select all cells in a worksheet press,
4. To delete a column,
a. Right click on the column heading then
select Delete from the menu.

a. <Ctrl+X>

b. <Alt+V>

c. <Ctrl+B>

d. <Ctrl+A>

b. Click on a column name and then press the


DELETE key.

9. Which of the following is not a way to


complete a cell entry?

c. Select the cells which you want to delete,


and then press the delete key on the
keyboard.

a. Click the Enter button on the formula bar

d. Select the cells which you want to delete,


and then press <Ctrl+Spacebar>
Worksheet and Cell Operations

b. Press any arrow key on the keyboard


c. Press ENTER
d. Press INSERT
29

10. Which of the following is different from the


others?
a. Cell

b. Row

c. Column

d. Gridline

11. Which keystrokes must be used to copy


selected cells?
a. <Ctrl+X> and <Ctrl+V>
b. <Ctrl+C> and <Ctrl+V>
c. <Shift+V> and <Ctrl+C>
d. <Ctrl+Z> and <Ctrl+V>

14. Which of the following are true for


inserting a row?
I. Right-click the row heading where you
want to insert the new row and select
Insert from the popup menu.
II. Select the row heading where you want to
insert the new row then select Rows from
the Insert tab.
III. Right click on the cell where you want to
insert the new row, select Insert then
select the Entire row.
IV. Select the cell where you want to insert
the new row and select Home Cells
Insert Sheet Rows.
a. I, III, IV

b. II, III

c. II, III, IV

d. I, II, III, IV

12. What key combination is used when


entering a text in all the selected cells?
a. <Ctrl+Insert>
b. <Shift+Insert>
c. <Ctrl+Enter>
d. <Alt+Enter>

13. Which of the following is not a method for


adjusting the width of a column?
a. Double-click the column headers name.
b. Drag the column headers right border to
the left or right.
c. Select the column header and click the
Column Width button on Home Cells
Format.
d. Right click on the column header, select
Column Width from the popup menu, and
enter its new width.

30

15. Which of the followings is not a way of


deleting a column?
a. Right-click the column heading you want to
delete and select Delete from the popup
menu.
b. Select the column heading you want to
delete and click Delete from Home Cells.
c. Select the column heading you want to
delete and select the Delete Row button on
the Developer tab.
d. Select a cell in the column which you want
to delete, right click on it and select Delete
then select Entire column.

Microsoft Excel

16. If you extend the following series two cells


down while the first two cells are selected,
what are the new dates in the 3rd and 4th
rows?
A
1

Friday, October 01, 2004

Tuesday, October 05, 2004

a. Friday, October 01, 2005 - Tuesday,


October 05, 2006
b. Wednesday, October 06, 2004 - Thursday,
October 07, 2004
c. Friday, October 09, 2004 - Tuesday,
October 13, 2004
d. Saturday, October 09, 2004 - Wednesday,
October 13, 2004

17. To copy format of one cell and apply it to


another cell you would use:
a. The Copy Format and the Paste Format
commands from Home Styles.
b. The Format Painter button in the Home tab.
c. There is no way to copy and apply
formatting in Excelyou would have to do
it manually.
d. The Copy and Apply Formatting dialog box,
which is located under the Home Format
tab.

18. If you want to subtract the values in a range


from another range, what do you have to
use?
a. Shift+Enter
b. Paste Special
c. Entering numbers with fraction
d. F2

Worksheet and Cell Operations

31

Word Search Puzzle


S

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

Move on-screen text or images horizontally or vertically so new information appears


on one side of the screen as older information disappears from the other side.
The longest key on the keyboard.
The new style toolbar since Office 2007
A font style.
The basic unit of a worksheet into in which you enter data.
Its named with numbers and contains 16,384 cells.
Instruction.
Changing the color or style of text.
Something arranged across.
A font style.
It is named with letters and contains 1,048,576 cells.
A program which allows you to enter formulas in table format and then perform
calculations or create graphs.
Perpendicular to the horizon. Up and down.
Made up of sheets.
Default extension of an Excel document.

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.

5. Write numbers using the Fill Series command.


6. Change the active worksheet without using the mouse.
7. Type your name to all cells in the range A1: P20 using the fastest way.
8. As shown in the Figure below, can you turn yellow colored cells to blue at the same time?
9. Can you select all cells using the keyboard?
10. On the Figure right, Copy the cell C4 to C10 and Move the cell C6 to C11.

Worksheet and Cell Operations

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

FORMATTING YOUR DOCUMENTS


3.1 Formatting Tools
The old formatting toolbar has been integrated with the new Home tab. The
Formatting Tools here provide quick access to commonly used formatting
actions. When you put your mouse pointer over an icon, it is highlighted and
a descriptive tool tip appears.
The following are brief explanations for some common Home Tab Group
icons.

Selects font name size from drop down lists.


Increase or decrease font size
Font Styles: Bold, Italic or Underlined
Borders: Used to add / modify selected cell borders.
Fill Color: Used to change / apply fill color.
Figure 3.1: Font Group icons

Font Color: Used to change / apply font color.


Dialog Box Launcher: Opens the Format cell Dialog
box from which you can change all the properties of
the selected cells.
Applies vertical cell alignment to the selected range.
Change text direction in the selected range
Wrap text: Without changing the column width,
wraps the text from the end of the column to the next
row. See Example 3.1 below.
Applies horizontal cell alignment to the selected
range.
Decrease and Increase Indent: Changes the start
position of the text without changing the left margin.
Merge cells: Merges selected cell as if they are one
cell. Or, unmerges them back.

Figure 3.2: Alignment Group icons

Example 3.1:
a. Before wrap text

36

b. After wrap text

Microsoft Excel

Number Format: Choose how the values in a cell are


displayed: as a percentage, as a currency, as a date
or time, etc.
Quick access to the currency, percentage or comma
style formats.
Increase or decrease the number of floating point
digits.

Figure 3.3: Number group icons

Quick access to the Insert cells button


Quick access to the Delete cells button
Some quick format options like: Row height, Organize
sheets or Sheet protection

Figure 3.4: Cells group icons

3.2 Using The Format Cells Dialog Box


This section explains changing formats such as number formatting,
alignment, font, border, patterns and protection of a range of cells. In most
cases, the number formats that are accessible from the Number group on the
Home tab are just fine.
Sometimes, however, you want more control over how your values appear.
Excel offers great control over number formats through the use of the Format
Cells dialog box. For formatting numbers, you need to use the Number tab.
You can bring up the Format Cells dialog box in several ways. Start by
selecting the cell or cells that you want to format and then do the following:
 Choose Home Number and click the small dialog box launcher icon.
 Choose Home Number, click the Number Format drop-down list, and
select More Number Formats from the drop-down list.

Figure 3.5: Dialog box launcher

 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

Remember that number formatting


effects only the appearance, not
the value. Also remember that
the formatting is applied to the
selected cells. So, you should
select the destination cells,
before making any formatting
change.

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

Preview the selected


number formatting

The following are the number-format categories, along


with some general comments:
 General: The default format; it displays numbers
as integers, as decimals, or in scientific notation if
the value is too wide to fit in the cell.

Selected Category

 Number: Enables you to specify the number of


decimal places, whether to use a comma to
separate thousands, and how to display negative
numbers (with a minus sign, in red, in
parentheses, or in red and in parentheses). E.g.
Instead of 3.141593 you can define 2 decimal
places and it only shows 3.14.

Details of the
selected format

More Information

Figure 3.7: Number Formatting options

 Currency: Enables you to specify the number of


decimal places, whether to use a currency
symbol, and how to display negative numbers
(with a minus sign, in red, in parentheses, or in red
and in parentheses). This format always uses a
comma to separate thousands. E.g. $2,500.00

 Accounting: Differs from the Currency format in that the currency


symbols always line up vertically.
 Date: Enables you to choose from several different date formats: July 28,
2007, 7/28/07, etc.
 Time: Enables you to choose from several different time formats: 10:30,
10:30:00 AM, 14:30, etc.
 Percentage: Enables you to choose the number of decimal places and
always displays a percent sign: 25%
 Fraction: Enables you to choose from among nine fraction formats: 6 7/8
which is 6.875
 Scientific: Displays numbers in exponential notation (with an E):
2.00E+05 = 200,000; 2.05E+05 = 205,000. You can choose the number
of decimal places to display to the left of E.
 Text: When applied to a value, causes Excel to treat the value as text
(even if it looks like a number).

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.

Key Combination Formatting Applied


Ctrl+Shift+~ : General number format (that is AutoFormat)
Ctrl+Shift+$ : Currency format with two decimal places
Ctrl+Shift+% : Percentage format, with no decimal places
Ctrl+Shift+^ : Scientific notation number format, with two decimal places
Ctrl+Shift+# : Date format with the day, month, and year
Ctrl+Shift+@ : Time format with the hour, minute, and AM or PM
Ctrl+Shift+! : Two decimal places, thousands separator, and a hyphen for
negative values
Example 3.2: Do you wonder what day of the week you were born?
Solution: Excel will help you;
1. Type your birthday into B2, for example 12/6/1993. Note: Check your
system date format when entering the date. If this is not your date format,
Excel may treat it as text or something else.
2. Open the Format Cells Dialog box, and then click the Number tab.
3. Select Date then select Monday, December 06, 1993 from the type box.

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

Preview: shows how the selected text will appear.

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.

Figure 3.10: Border Tab

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.

Figure 3.11: Fill Tab

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

Figure 3.12: Format Cells


Protection

2. What to allow and protect.


By checking any of these options, you can allow users to use that property.
The people who know the password can unprotect and use all the properties
of the sheet. The people who dont know the password can use only what you
allowed.

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

Figure 3.13: Protect Sheet dialog


box

41

3.3 Document Themes


As all you know, professional designers first start their documents by color,
font and general designs. They spend their hours or days in design, after that,
they start booklet preparation. Not all people have that professional sense of
color and design; but they can be helped though.
In an effort to help users create more professional-looking documents, the
Office designers incorporated a concept known as document themes. Using
themes is an easy (and almost foolproof) way to specify the colors, fonts, and
a variety of graphic effects in a document. And best of all, changing the entire
look of your document is a breeze. A few mouse clicks is all it takes to apply
a different theme and change the look of your workbook.

Figure 3.14: Themes: Colors. Fonts,


Effects

Importantly, the concept of themes is incorporated into other Office apps.


Therefore, a company can easily create a standard look and feel for all its
documents. For all of that, you just prepare your document with Styles.

A theme applies to the


workbook. So, you cannot use
different themes for different
worksheets.

3.4 Using Styles


A Style is a collection of formats such as font size,
color, patterns, and alignment that you can predefine
and save as a group. Once you have defined and
saved a style, you can apply all of the formatting
elements at once. Note that this is a live preview- as
you move your mouse over a style, the selected cell
range temporarily displays the change. The real power
of styles is apparent when you change a component of
a style. All cells that use that named style automatically
incorporate the change.
A Style can contain any (or all) of the following
formatting attributes:
 Number
 Font (type, size, and color)
Figure 3.15 Using Styles

 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.

3.5 Using Format Painter


Here is another very efficient tool in MS. Excel: Format Painter. After you
design one of your cells to fit your needs, you can use the Format Painter to
apply the same format to others.

Figure 3.16: Using Styles

1. Select a source range


2. Click the Format Painter button on the Home Tab Clipboard Group
3. Click on the destination
With this, you can apply the source format to destination range only once.
After you select the range, if you double click on Format Painter icon, you can
apply the format more than once until you press the ESC key.

Another method to copy format is


to use Paste Special.

3.6 Using Tables


One of the most significant new features or changes came with the Excel
2007 was the tables logic. Excel, of course, has always been able to deal with
tables, but they accepted tables as columns and rows of data. But since
Excel 2007, it accepts tables as a special object and has special tools to
manipulate them.

3.6.1 What is table?


A table is just a rectangular range of cells that (usually) contains columns,
rows and headers. Each row in the table corresponds to a single entity. For
example, a row can contain information about a customer, a student, an
employee, or a product. Rows are also called Records.
Tables typically have a header row, at the top that describes the information
contained in each column. The items in this header row which are also called
Fields contain a specific piece of information which is the same for all the
records. For example, if each row contains information about an employee,
the columns can contain data such as name, employee number, hire date,
salary, department, etc. All of these are columns or fields of the table.

Formatting Documents

43

3.6.2 Creating a table


To create a table, we use the Table command 1 in Insert Tab Tables

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.

Figure 3.18: Table AutoFormat List

3.6.4 Some facilities for tables


Once you designate a particular range to be a table (using the Insert Tables
Table command), Excel provides you with some very efficient tools that
work with the table.
For example:
 You can apply attractive formatting with a single click.
 You can easily insert/change summary formulas in the tables total row.
 If each cell in a column contains the same formula, you can edit one of
the formulas, and the others change automatically.

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.

Figure 3.19: Table headers in the column headings place

Example 3.4:
Prepare the following table for a Real Estate Agency, and format it.

Figure 3.20: Real Estate Agency

3.7 Conditional Formatting


Conditional Formatting formats cells only if a condition is satisfied. For
example, you could use conditional formatting to display a student's mark
that is
 5(Excellent) in Light red fill with dark red text, and
 light yellow fill with dark yellow text if the students grade is 2(bad).
If the value of the cell changes and no longer meets the specified condition,
the cell returns to its original formatting.

Figure 3.21: Conditional Formatting

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.

Figure 3.23: Format Cells that are GREATER THAN

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

2. Which tab of the following adjusts the


selected text to superscript in the Format
Cell window?
a. Font

b. Alignment

c. Underline

d. Patterns

3. You can move a cell by dragging when the


CTRL key is held down.
TRUE 

FALSE 

6. Which of the following is not a way of


changing the font size?
a. Select the cell(s), Click on the triangle near
the Font Size from the Font group in the
Home tab. Finally choose a proper font size.
b. Select the cell(s) and right-click the
selection, select Format Cells from the
popup menu, click the Font tab, choose a
proper font size, and click OK.
c. Select the text and press Ctrl+Shift+F.
Choose a proper font size and click OK.
d. Select the text then select Format Column
width... Change the value and press OK.

7. You have four cells that you want to


combine into one. How can you do this?
(You can choose more than one)
a. Select the cells and click the Merge Cells
button in Page Layout Tab.
b. Right click on the cells and select Merge
Cells button from the Mini Toolbar.

4. Locked cells have no effect unless the


worksheet is .?
a. Protected

b. Hidden

c. Read only

d. Shared

5. Which of the following is not a numeric


value? (Choose all that apply)

c. Select the cells and click the Merge Cells


button in the Styles group in the Home Tab.
d. Select the cells and click the Merge Cells
button in the Alignment group in the Home
Tab.

8. Which symbol is used before a number to


make it a label?

a. May 10, 2001

b. Entire Text

a. =(equal)

b. " (quote)

c. 57%

d. 350

c. ' (apostrophe)

d. _ (underscore)

Formatting Documents

47

9. How can you rotate text in a cell?


a. Open the Format Cells Dialog box
Alignment tab. Select Text direction from
the combo box below.
b. Click the Home Tab Alignment group
Orientation button and select the desired
orientation.
c. Select the Home Tab Cells group
Format button Text Direction and write
the degrees in the box
d. Right-click the cell and select Text Direction
from the popup menu.
10. You want to change the dates in a
worksheet so that they appear as 21 Oct 04,
instead of 10/21/04. How can you do this?
a. Select the cells and click the Long Date
button on the Review tab.
b. You have to retype all the dates, as there is
no way to reformat them.
c. Select the cells and open the Format Cells
Dialog box, click the Number tab, select
Date from the Category list and select the
date format you want.
d. You need to call your system administrator
and have him or her install the Microsoft
Long Date patch for you.

12. To display additional decimal places in a


cell, click the ......... button in Home tab.
a. Increase Decimal
b. Percent Style
c. Increase Indent
d. Decrease Indent

13. Which of the following statements is not


true:
a. Clicking the Center button on Alignment
group centers the text or numbers within
the cell.
b. The Merge and Center button merges
several cells into a single larger cell and
centers the contents inside the cell.
c. You can change cell alignment by opening
the Format Cells Dialog box and clicking
the Alignment tab.
d. Cells can show, at most, 3 lines of text.

11. Which is not a method for applying boldface


to the selected cell range?
a. Open the Format Cells Dialog box, click the
Font tab, and select Bold from the Font
style list.
b. <Ctrl+B>.
c. Right-click the text and select Boldface
from the Mini toolbar.
d. Click the Bold button on Styles group in the
Format Tab.

48

Microsoft Excel

Practice
1. Make the following table. You may use different contact and company names.

2. Prepare this table.

3. Write the following expression in an Excel worksheet.

Formatting Documents

49

4. Try to prepare these tables by using Auto format.

5. Prepare the table on the right side


Reminder: Avoid writing the currency symbol directly. You will
use wrapping, merge cell and currency format. (You may
customize the currency symbol from the Windows Control
Panel)

6. Create the following table and apply conditional formatting as


shown in the figure. You can use your classmates names.
Reminder: If the average of a student is less than 3, the
background color is red, the font color is yellow. If any grade is
5, the background color is green, the font color is white.

50

Microsoft Excel

Word Search Puzzle

Clues

Explanation

AUTOFORMAT Applies a set of predefined formatting choices to worksheets and tables.


Money that is used by a country.
A set of letters, numerals, and shapes, which conform to a specific set of design
criteria.
The edge or margin of a range of cells.
Combining two or more cells.
Invisible.
The alignment of an object in relation to the cardinal directions.
Automatic moving of text to the subsequent line after the completion of the previous
one.
An artistic or decorative design created by the regular repetition of shapes.
A character or symbol printed partly below the base line of the text.
Reducing the size of content to fit it in a cell.
Horizontal line underneath something written.
The physical magnitude of the font.
A network resource exported by a server or workstation.

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.

Create the following table.

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.

Change the quarterly income amounts to currency formatting.

e.

Center the column headings (from Quarter 1 to Total) and amounts, and then apply bold formatting.

f.

Add a bottom border to the cell range: B10:F10.

g.

Merge the cell range A1:F1 into a single cell.

4. Prepare the following figure in Excel.

Pay attention to Text Orientation, background color, font color, merge cells, text alignment, number category,
borders...

52

Microsoft Excel

PAGE SETUP AND PRINTING


4.1 Page Layout Tab
You can use the Page Layout Tab to customize the document according to
your preferences for printing. The new Ribbon has placed the quick access
buttons for the most common operations in the Page Layout Tab. But, using
the dialog box launcher 6 on the bottom right corner of the Page Setup
group, you can see the entire Page Setup Dialog box. (Figure 4.3)

6
Figure 4.1: Page layout tab

4.1.1 Page Tab


Orientation 2 specifies the page orientation for the printed page using the
Landscape and Portrait radio buttons.
Figure 4.2: Page Orientation

Scaling 5 reduces or enlarges the worksheet, or fits the worksheet to a


specific number of pages when you print. For example, if you want to adjust
the width of the document and leave the height as it is: In the first box beside
Fit to, enter 1 (or Width), in the second box beside Fit to, delete any value.
Paper size: 3 You can choose letter, A4, or other size
options to indicate the size of your document. Ex. A4 is
European standard and 210x297mm in size; Letter is
American standard and 216x279 mm in size.

1
2
5
3

Print Quality: You can choose the resolution to specify print


quality for the active worksheet. Resolution is the number of
dots per inch (dpi) that appear on the printed page. Higher
resolution produces better printing quality.
First page number: Enter Auto to start numbering pages
from 1 or write the starting page number for your print area.
Print Area: 4 You can select what to print from the entire
worksheet. When you print the document, only the selected
region will be printed.

Figure 4.3: Page Setup Dialog box

54

Microsoft Excel

4.1.2 Margins Tab


When printing, the entire page cannot be used. Some space has to be left on
each side of the paper. These spaces are called Margins. They are the
printing boundaries of the paper. Left Margin means the limit at the left of the
page where your text starts.
Using Margins quick button in the Page Layout tab, you can select Normal,
Wide or Narrow Margin options. These are the common options. But, if you
want to setup your own preferences, you click on Custom margins at the
bottom. Itll open Margins tab of the Page Setup Dialog box. From this tab,
you can enter margin settings and see the results by using the Print Preview
window. Or, adjust measurements for the Top, Bottom, Left, and Right margins.

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.5a: Margins tab in Page Setup

Margin of the Header and footer


When you enter a new margin size in the Header box, it changes the distance
from the top edge to the header.
Or, to change the distance from the bottom edge to the footer, enter a new
margin size in the Footer box.
These settings should be less than your top and bottom margin settings and
greater than or equal to the minimum printer margins.

Figure 4.5b:
Header and Footer margins

Page Setup and Printing

55

4.1.3 Header/Footer Tab


You can enter a preset Header and/or Footer using the drop
down menus.
You can change the Header/Footer using the Custom
Header and Custom Footer buttons.

Figure 4.6b

Below Custom Header and Footer boxes, some Header


and Footer options are placed.
Figure 4.6: Header and Footer tab in Page Setup

Font Button: Changes font name, size, and


style of the selected text in the section box.

Different odd and even pages: Select this button if you


want to use different Headers and Footers in odd and even
pages
Different first page: If you want a different Header/Footer in
the first page

Page Number Button: Inserts an automatic


page number in the header and/or footer
when you print the worksheet or the chart.
Total Page Number Button: Inserts the total
number of pages in the worksheet.
Date Button: Inserts the current date on your
computer.

Custom Header / Custom Footer


You can have only one custom header and one customfooter on each worksheet. If you create a new custom
header or footer, it replaces any other in the worksheet.

Time Button: Inserts the current time on your


computer.
Path & File Name Button: Inserts the path
and file name of the active workbook.
File Name Button: Inserts the name of the
active workbook.
Sheet Name Button: Inserts the name of the
active worksheet.
Insert Picture Button: Allows you to insert a
picture in the header/footer.

Figure 4.7: Custom Header dialog box

Format Picture Button: Allows you to adjust


the image.

56

Microsoft Excel

4.1.4 Sheet Tab


Print Area: 1 if you dont want to print all of the worksheet
data, you can specify a range to be printed. First select the
range to be printed, then select the Set Print Area button from
the Page Layout tab.
Print Titles: 3 When you have a large list that doesnt fit into
one page, you can print the same columns or rows as titles
on every page.

Figure 4.9: Options in Sheet tab in Page Setup

Figure 4.8: Print options in the Page Layout tab

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.

Figure 4.10: Print Order

4.1.5 Chart Tab


If the current worksheet is an Excel sheet, the last tab of the
Page Setup window shows sheet options. If it is an Excel
Chart object, then the Page Setup window changes to the
Chart options tab.
Printed chart size:
 Use full page will expand the chart to fit the full width and
height of the page margins.
 Scale to fit page will scale the chart to the nearest page
margin before printing.
 If you select Custom you can adjust the chart size.
Printing Quality: You may select the Printing Quality you want.
Black and white or color.
Figure 4.11: Chart Options

Page Setup and Printing

57

4.2 Print Preview


4.2.1 Normal view and Page Layout View
Before you print a Microsoft Office Excel worksheet that
contains large amounts of data or charts, you can quickly
fine-tune it in the new Page Layout view to achieve
professional-looking results. You can change the Page view
using the Page view buttons next to Zoom Control on the
status bar. Or Using the Workbook views group commands
in the View Tab.

Page view
buttons

Figure 4.12: 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.

Figure 4.14a: Page Break Preview

58

Figure 4.14b: Page Layout View

Microsoft Excel

4.2.2 Print Preview


After you prepare your document, you may check and see the preview of the
document. Use the Print preview from Office button to look over the page or
to make your final adjustments before printing. This will open a new window
with buttons that are necessary for previewing.
Next and Previous buttons: 1
If you have multiple pages to be
printed the Next and Previous
buttons help you to move
through the pages and see
them.
Zoom button 2 switches
between a full-page view and a
magnified view. The Zoom
feature doesnt affect print size.
Depending on your resolution
settings, you may not see
certain graphics properly, such
as thin borders, in full-page
view.
Page Setup 3 Here, we
have the most common page
setup options. For more detailed
options, you should go to Page
Layout tab.

3
4
1

Figure 4.15: Print Preview Button

Show Margins 4 button allows


you to see the page margins
and fix them using your mouse.

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.

Figure 4.16: Print Dialog box

Page Setup and Printing

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.

4.3.1 Print Range


From the Print Range, if you select All, it will print all pages in the active sheet.
If you select the Page(s) option, you can define the range of the pages to be
printed. In the Print What section, using the radio buttons, you can select
 active sheet(s),
 an entire workbook or
 only the selected region to print.
You may also print multiple worksheets by selecting with <Ctrl+Left click>
combination. If you select active sheet(s) from the Print What section, Excel
will include all of the selected worksheets for printing.
You can define the number of copies for each page using the Copies option
button. The Collate check box is available if you are printing multiple copies.
Using the Collate check box, you can adjust print order of the pages.

Figure 4.18: Options in the Print dialog box

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

4. How can you view and/or add a page header


to a worksheet? Choose all that apply.
a. Click the Header/Footer button on Office
button Prepare.
b. Open the Page Setup Dialog box and click
the Header/Footer tab
c. Select Header&Footer from the Text group
in the Insert Tab
d. Click the Page Layout button on the status
bar then click on Click to add header text

2. How do you set a Print Area, so that Excel


prints only that part of the worksheet?
a. Select the area then select the Office button
Print Quick Print.
b. Select the area then click Print Area Set
Print Area button on the Page Layout Tab.
c. Select the area you want to print then click
the Print button on the Quick Access Toolbar.

5. .................... reduces or enlarges or fits the


worksheet to a specific number of pages.
a. Orientation

b. Scaling

c. Paper size

d. Print quality

d. There is not a way of doing this.

3. The page break is not at the place you


want. How can you fix this?
a. Select the cell where you want to add a
page break and then click the Page Break
button on the Insert Tab.

6. .................. is the number of the dots per


inch (dpi) that appears on the printed page.
a. Scaling

b. Margins

c. Resolution

d. Orientation

b. Click the cell where you want to add a page


break and select View tab Freeze Panes.
c. Click the Print Preview button and click the
Fit to Print button on the toolbar.
d. Select View Page Break Preview and drag
the page break indicator line to where you
want.

Page Setup and Printing

7. ..................... are the printing limits of the


paper.
a. Scaling

b. Print Quality

c. Measurement

d. Margins

61

8. ..................... settings should be smaller


than the top and bottom margin settings
and larger than or equal to the minimum
printer margins.

10. If you have multiple pages to be printed


..................... help you to move through the
pages and see them in the Print Preview
window.

a. Header and footer margin

a. Active sheet(s)

b. Print area

b. Entire workbook

c. Date button

c. Next and previous buttons

d. Chart tab

d. Zoom button

9. If you select ..................... you will expand


the chart to fit the full width and height of
the page margins.

62

a. Use full page

b. Scale to fit page

c. Draft quality

d. Printing quality

Microsoft Excel

Word Search Puzzle


H

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.

Page Setup and Printing

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.

Print the table sorting by class- in ascending order and then by


average- in descending order.

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

FUNCTIONS AND FORMULAS


5.1 Understanding Functions and Formulas
Using formulas is the essential part of Excel. Microsoft Excel is best when you
have lots of numbers and different calculations with these numbers. Each box
(cell) is like a different address and can be used with its referring address or
name.

To Refer to

Use

The cell in column A and row 10

A10

The range of cells in row 1 and columns


A through E (5 cells)

A1:E1

The range of cells in columns A through E


and rows 1 through 5 (5 5 = 25 cells)

A1:E5

All cells in row 5 (A5:XFD5)


All cells between rows 5 through 10
All cells in column H (H1:H1048576)
All cells in columns H through J

5:5
5:10
H:H
H:J

The A1 reference style


There are two different reference styles: A1 and R1C1. By
default, Excel uses A1 reference style. This refers to columns
with letters (A, B, C... XFC, XFD a total of 16384 columns) and
rows with numbers (1 through 1.048.576).
These letters and numbers are called row and column
headings. To refer to a cell, enter the column letter followed by
the row number.
For example, D2 refers to the cell at the intersection of column
D and row 2.

Figure 5.1: A1 Reference Style

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.

 To keep well organized workbooks


 To have less workbook sizes
 To have different security and access levels, etc.
In the ancient times, when there were no computers, we used papers to
collaborate with people. Because, we have better network environments now,
we dont have to print hundreds of pages for a project and distribute it to
others and wait for all to work and return the pages. Now, we can let all people
work on their copies and we have links to appropriate locations, in order to
have dynamic and up-to-date information.
The general syntax for a link
=[WorkbookName]SheetName!CellAddress
But, if linking from the same workbook and/or worksheet, you can skip the
default parts and write only the cell address after the equal sign. So, if you
want to have a link to A1 cell from the same worksheet, in the destination cell,
you simply write:
=A1

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,


then, sheet name followed by an exclamation mark and

 write the cell address in the end:

When the workbook file name


has spaces in it, we use single
quotation.
='[Daily Plans.xlsx]Sheet1'!A1

=[Plans.xlsx]Sheet1!A1

5.2.1 Creating a link formula by pointing


Because, when entering external reference formulas manually, you can easily
make errors, usually its not the suggested method. Instead, have Excel build
the formula for you:
1. Open the source workbook.
2. Select the cell in the dependent workbook that will hold the formula.
3. If youre simply creating a link and not using the external reference as part
of a formula, just enter an equal sign (=) and then select the cell and
press Enter. If you are entering a formula, when you get to the part that
requires the external reference, activate the source workbook and select
the cell or range and press Enter.
4. After you press Enter, you return to the dependent workbook, where you
can finish the formula.
Because the references that you create with this method are always absolute
references, if you plan to copy it to create additional link formulas, you need
to pay attention when using them as absolute or relative references.
As long as the source workbook remains open, the external reference doesnt
include the path to the workbook. If you close the source workbook, however,
the external reference formulas change to include the full path.

5.3

Writing Your First Formula

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).

Functions and Formulas

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

Solution: In order to calculate a student's average, you need


to calculate the sum of Exam1, Exam2 and Exam3 and then
divide the result by 3.
For the first student, according to Figure 5.2, the cell
containing


Exam1 mark is D4;

Exam2 is E4; and

Exam3 is F4.

And you should use these referring addresses in your


formulas.
Now, you know all the details and you are ready to write your
formula. First, you select the cell where the result will appear
(G4) and then write the formula below in the formula bar:

Figure 5.2: Math exam results

= (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

5.3.1 Operators in Excel Formulas


There are three groups of operators in Excel.

Figure 5.3.a: Arithmetic Operators

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

Figure 5.3.b: Logical Operators

68

FALSE
TRUE
FALSE

Operator

Meaning

Example

Result

Range

A2:C7

All the cells from A2


to C7

space

Union (to define


The cells from B1 to
more than one A1,B1:B6
B6 and A1
reference)
produces reference
=B7:D7
Intersection
to common cells to
C6:C8
the two references
Figure 5.3.c: Other Operators

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

Analysis and Solution:


Since you want to calculate the final as 50% of the semester
average, you will multiply the Final Exam (E2) by 50 and the other
exams by 25. Then the sum of all will be divided by 100 to get the
students average. In cell F2 write the formula
= (E2*50+C2*25+D2*25)/100
to get the average of the first student. Copy the formula for the
other students in the list.

5.3.2 Absolute and Relative Reference


A relative reference is an address that keeps the relative difference from the
source to the destination cells. When you copy this formula to another
location, Microsoft Excel automatically adjusts the new addresses relatively,
according to the new location.

A1

Relative column, Relative row

$A1 Absolute column, Relative row


A$1 Relative column, Absolute row
$A$1 Absolute column, Absolute row

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.

Functions and Formulas

Because our formula is located in


column C, and when copying, well
copy again to the same column, we
can simply use B$2.

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.

Figure 5.6: Using absolute reference

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

The formula for the third payment

=D13 * $B$8

The formula for the fourth payment

=D14 * $B$8

5.4

Simple Functions:

Sum, Average, Count, Max and Min


Excel provides a wide range of predefined functions. You will study in this
section some basic functions and their uses, and the way to access these
functions.
If you click on the small arrow next to the Insert Function button in the Home
Tab and then select More functions (Or, if you select Insert Function from the
Formulas Tab. Or, press <Shift+F3>), you will see the Insert Function dialog
box.
Figure 5.7: Insert Function Button

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

5.4.1 Sum Function


This function calculates the sum of the numbers within the range. Any cell
that is not a number format will be ignored. For the Sum function you can
write a single cell addresses followed by commas or you can also use a
colon(:) to define a range.

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)

Adds 3 and 12 (Using direct numeric values)

15

=SUM(A2:A4)

Adds the first three numbers in column A

40

=SUM(A2:A4, 15) Adds the first 3 numbers in column A, and 15


Adds the values in the last two rows above,
=SUM(A5,A6, 2) and 2. Since text values in references are not
translated, the values in them are ignored
=SUM(5, 15,
TRUE)

Adds 5, 15 and 1, because the text values in


parameters are translated into numbers, and
the logical value TRUE is translated into the
number

55

21

DATA

-5

15

30

'5

TRUE

Figure 5.9: Using Sum Function

Functions and Formulas

71

5.4.2 Average Function


Average function returns the average of the numbers in the selected cells. If
your Excel worksheet contains the data shown in Figure 5.10, the following
formulas give the results described in the table.
A
1

DATA

Formula

Description

Result

10

=AVERAGE(A2:A4)

Average of the numbers


7,7,10

27

=AVERAGE(A2:A6; 5)

Average of the numbers


in A2:A6 and 5

10

Figure 5.10: Average formula usage

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

Figure 5.11: SURAT Company Annual Report

72

Microsoft Excel

Analysis and Solution:


You have four formulas;
 Total and average formulas for every product and
 Total and Average formulas for every quarter.
1. Total formula for the first product will be in cell G3, and it will find the sum of C3F3. You can use the Sum function
here and your formula will be: =Sum (C3:F3).
2. The average formula for products is also similar and will be placed in cell H3: =Average (C3:F3). Having written
these formulas, you may copy them to other resellers (G4:H7).
3. The Total for the first quarter will be in cell C8. You can use the Sum function here again: =Sum (C3:C7).
4. Average function for the first quarter will be in C9: =Average (C3:C7). Finally, your table is ready.

5.4.3 Max and Min Functions


The Max function returns the largest value within the given
range. And the Min function returns the smallest value within
the given range.

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

Write =MAX(H3:H9) into cell F11 and =MIN(H3:H9) into


cell F12 to find the maximum and minimum averages.

5.4.4 Count Function


Counts the number of cells that contain numeric values. You
can use this function to avoid #DIV/0! (division by zero) errors.
Formula

Description

Result

=Count (A2:A8)

Counts the number of cells


that contain numbers in the
table next

=Count (A5:A8)

Counts the number of cells


that contain numbers in the
last 4 rows of the table

=Count (A5:A8,2)

Counts the number of cells


that contain numbers in the
list, and the number 2

A
1

DATA

Sales

12.08.2008

4
5

19

22.24

TRUE

#DIV/O!

Figure 5.13: Count Function

Functions and Formulas

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

Name and surname

18.09.2010

Id

17.09.2010

16.09.2010

1st Semester Attendance Form


15.09.2010

1
7

Figure 5.14: Count Function example

Analysis and Solution:


Your first formula will count the days that the student missed at least one or
more hours. So, You can use the Count function to count the number of days
he missed lessons. In the other column, you can calculate the sum of the
lessons he missed.
For the first student, in cell Y3, write the formula =Count(C3:X3) and for the
total hours skipped, in cell Z3, write =Sum(C3:X3). And copy these formulas
to the other students.

5.4.5 All in One: Subtotal


Subtotal is a very flexible formula and can be used to summarize the tables
or lists. It is generally easier to create a list with subtotals by using this
command in the Outline group on the Data tab. You have 11 common
functions included in this aspirin function. Once the subtotal list is created,
you can modify the function number anytime to change to the desired
SUBTOTAL function.

74

Microsoft Excel

Function Number

Function Number

(Includes hidden values) (Ignores hidden values)

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

Figure 5.15: SUBTOTAL Functions

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.

Functions and Formulas

75

5.5 Using Functions and Formulas


In the previous section you studied how to define your own formulas and use
some common functions. In this section you will study the usage of other
predefined formulas and to get help with them.

Figure 5.16: Formulas Tab

You already know how to open the Insert Function Window (from
the button 1 in the Formulas Tab). When you select a function

using 3 and 4 in this window, it will show the usage 5 and

brief information for the selected item. There is another link 6


at the bottom of the window to get more help on the selected
function.
After you click OK, it will show another window that will guide
you with the function arguments. In the Function Arguments
window, you are asked to fill in all the required parameters in
separate boxes. If you cant remember a cell name, click the Cell
Name button; it will minimize the function arguments window,
letting you select a cell or a range. After you click the same
button or press ENTER, itll return the address to the Function
arguments window. When you finish entering arguments, Excel
will show the result in the Formula result section in the Function
Arguments window.
So far you have studied some of the common predefined
functions. But, we have many others. There are 12 main function
groups with around 350 predefined functions.

6
Figure 5.17: Insert Function dialog box

Parameters
(Function Arguments)

Current Function

Function
description

These groups are

Cell name button

 Financial

 Text

 Date & Time

 Logical

 Math & Trig

 Information

 Statistical

 Engineering

 Lookup & Reference  Cube


 Database,
The result according to
current input

Current Parameter
description

 Compatibility

To explain all these functions we need several


books. Nevertheless, well try to explain some
useful functions that you might need.

Figure 5.18: Function arguments window

76

Microsoft Excel

5.5.1 Date and Time Functions


5.5.1.1 Date()
You can easily enter a date into a cell by simply typing it while using any of
the date formats that Excel recognizes. On the other hand, we also have a
Date function to convert numbers into date format. The DATE function takes
three arguments: the year, the month, and the day. The following formula, for
example, returns a date comprised of the year in cell A1, the month in cell B1,
and the day in cell C1:
=DATE(A1,B1,C1)
Date function is useful when you want to create and manipulate a date
yourself using numbers. See the section 5.5.1.8 Counting by Months or
Years for an example.
5.5.1.2 Now()
Shows current date and time. If the cell format was General before the
function was entered, the result is formatted as a date.
You can also insert the current
date or time (statically) with a
shortcut.

Example 5.10
=Now ()

07/15/2009 15:00

Current date: Ctrl+;


Current time: Ctrl+Shift+;

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.

The difference is that when you


insert with NOW() or TODAY()
the values are renewed every
time the worksheet is
recalculated.

Example 5.11
=Today ()

07/15/2009

5.5.1.4 More about Dates (Optional)


To Excel, a date is simply a number. More precisely, a date is a serial number
that represents the number of days since the fictitious date of January 0,
1900.
 A serial number of 1 corresponds to January 1, 1900;
 a serial number of 2 corresponds to January 2, 1900, and so on.
This system makes it possible to easily deal with dates in formulas. For
example, you can create a formula to calculate the number of days between
any two dates (just subtract one from the other). Excel supports dates from
January 1, 1900, through December 31, 9999 (serial number = 2,958,465).

Functions and Formulas

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.

Figure 5.20: Arithmetic operations


with times

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.

Figure 5.21.a: Summing times

Excel uses the 1900 date and time system in which


 January 1, 1900 is represented by numeric value 1.
 2 represents January 2, 1900. And so on,
 July 17, 2009 is represented by 40011.
Here is the question, what is 0 (zero) date for? The zero date
is used to represent times without date.
Figure 5.21.b: Number Format

Because, in normal date/time format, you cannot have 25th


hour, it increments the day and says that 11:55 minutes more
than it. If you change the format, you will see that. We have
the solution for this in Format cells Custom formats. [h]
directive says to Excel not to use 24 hour system.

Figure 5.21.c: Number 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

The number of complete years in the period.

The number of complete months in the period.

The number of days in the period.

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")

Figure 5.22: Using the DateDif function

Then, it returns the result.

5.5.1.7 Counting by Weeks


How can we count by weeks? Because, date is also a number format, you
can use arithmetic addition or subtraction to calculate new date values. So,
if you insert into A1 the initial date. In B1, you can say
=A1+7

Figure 5.23: Counting by weeks

After you copy this formula to the following cells, this will create a series of
dates with seven days difference between them.

Functions and Formulas

79

5.5.1.8 Counting by Months or Years


Because each month has a different number of days, in a formula, you cannot
say =A4+30. But you can use DATE function to produce the desired result.

Figure 5.24: Counting by months

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.

5.5.1.9 NetWorkDays Function


Here is another very useful function for accountants. The NetWorkDays
function calculates the difference between two dates, excluding weekend
days (Saturdays and Sundays). As an option, you can specify a range of cells
that contain the dates of holidays, which are also excluded.
=NETWORKDAYS(start_date, end_date, holidays)
the holidays option is an optional range that contains the holidays.

5.5.2 Math and Trigonometric Functions


5.5.2.1 Abs()
Calculates the absolute value of a number.
Example 5.14
=ABS(2)

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.

Figure 5.25: Using ABS when


subtracting times

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

Functions and Formulas

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)

returns the fourth power of two 16

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

Sum_Range: are the actual cells to sum.


Example 5.27
Summing negative numbers in a range.
=SumIf(Range, "<0")

Functions and Formulas

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)

Let Excel help you write SumIf functions:


1. Choose Office Excel Options to display the Excel Options dialog box.
2. Click the Add-ins tab on the left.
3. Select Excel Add-Ins from the drop-down list labeled Manage.
4. Click Go to display the Add-Ins dialog box.
5. Place a check mark next to Conditional Sum Wizard.
6. Click OK.

5.5.2.14 Sqrt()
Returns the square root of a number
Example 5.29
= Sqrt(4)

returns 2

= Sqrt(25634)

returns 160.1062147

5.5.2.15 RandBetween(bottom, top)


Returns an evenly distributed random number greater than or equal to the
bottom and less than or equal to the top value. A new random number is
returned every time the worksheet is calculated.

5.5.3 Logical Functions


5.5.3.1 And(), Or(), Not() functions
And, Or, Not are used to process and combine logical results.
In Logical tests, logical operators
are used:
<, <=, >, >=, =, <>.
They produce True or False
results.

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:

Figure 5.26: Using the IF function

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 Statistical Functions


Statistics searches the occurrences, distributions, frequencies, relations and
possibilities of events. It is one of the developing sciences of the future. If
there is the best and the worst, then there is statistics. So, its everywhere.
And as you know, when functions are an essential part of something, Excel is
good for that. Here are some basic and essential functions for statistics.

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)

Figure 5.27: Using the IF function

Functions and Formulas

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)

Returns the number of cells containing the value 12

=COUNTIF(Data,<0)

Returns the number of cells containing a negative value

=COUNTIF(Data,<>0)

Returns the number of cells not equal to 0

=COUNTIF(Data,A1)

Returns the number of cells equal to the contents of cell A1

=COUNTIF(Data,>&A1)

Returns the number of cells greater than the value in cell A1

=COUNTIF(Data,*)

Returns the number of cells containing text

=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())

Returns the number of cells containing the current date

=COUNTIF(Data,>&AVERAGE(Data))

Returns the number of cells with a value greater than the average

=COUNTIF(Data,TRUE)

Returns the number of cells containing logical TRUE

=COUNTIF(Data,#N/A)

Returns the number of cells containing the #N/A error value

For using multiple criteria Excel provided a new function series: AverageIfs, SumIfs, CountIfs are some of them.
=COUNTIFS(Data, ">10", Data, "<20")

Returns the number of cells whose value is between 10 and 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:

Figure 5.29: Mode of a list

-8, -3, -1, 0, 0, 0, 4, 5, 12. As you see 0 repeats 3 times whichs the mode of
these series.

5.5.4.7 Standard deviation


In a set of data, standard deviation is a statistic that tells us how tightly all the
various examples can be clustered around the mean. This can be useful
when comparing results from different sources.

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.

Functions and Formulas

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.

Figure 5.31: Using the CORREL Function

88

Microsoft Excel

5.5.5 Text Functions


5.5.5.1 Mid()
Returns Num_Chars characters from the text starting from the start_num
character
=Mid(text, start_num, num_chars)
 Text: is the text string containing the characters you want to extract.
 Start_num: is the position of the first character you want to extract from
the text.
 Num_chars: specifies the number of characters you want Mid to return
from the text.

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.

Functions and Formulas

89

Example 5.37
According to the Figure 5.32, write these formulas into suitable cells, and
examine the results.
=Find( " ",C3)

Finds the first position of space char in C3

=Len(C3)

Return the length of C3

=LEFT(C3,C7)

Copy C7 (6) chars from C3

=RIGHT(C3,C8-C7)

Get C8-C7 (13-6=7) chars from the right of C3

=MID(C3,C7+1,15)

Get 15 chars from C3 starting from the


(C7+1)th (7th) char

Figure 5.32: Using Text functions

5.5.6 Lookup & Reference Functions


5.5.6.1 VLookUp()
Searches for a value in the leftmost column of a table, and then returns a
value in the same row from a column you specify in the table.
=VLookUp (lookup_value, table_array, col_index_num, range_lookup)
 Lookup_value: is the value to be found in the first column of the array.
Lookup_value can be a value, a reference, or a text string.
 Table_array: is the table of information in which data is searched. Use a
reference to a range or a range name, such as Database or List.
 Col_index_num: is the column number in the table_array from which the
matching value must be returned.
 Range_lookup: is a logical value that specifies whether you want
VLookUp to find an exact match or an approximate match.
5.5.6.2 HLookUp()
Searches for a value in the top row of a table or an array of values, and then
returns a value in the same column from a row you specify in the table or
array.
=HLookUp(lookup_value,table_array,row_index_num,range_lookup)
 Lookup_value: is the value to be matched in the first row of the table.
Lookup_value can be a value, a reference, or a text string.
 Table_array: is a table of information in which data is looked up. Use a
reference to a range or a range name. The values in the first row of
table_array can be text, numbers, or logical values.
 Row_index_num: is the row number in the table array from which the
matching value will be returned.
 Range_lookup: is a logical value that specifies whether you want
HLookUp to find an exact match or an approximate match.

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.

Figure 5.33: Calculating letter grades

Analysis and Solution:


You can use both; HLookUp or VLookUp, according to your worksheet
design. But, if you design the worksheet as in Figure 5.33, because the
values that you search are located in the left most column, you need to use
VLookUp.
When looking up the letter grade of the first student,
 youll write the formula in F3
 referring to the average in E3.
 The table is in J3:K9 and you want
 the VLookUp function to return the value in the second column as the result.
The formula for the first student becomes
=VLookUp(E3, J3:K9,2,TRUE)
Because you dont change the address of Letter Grade Table (J3:K9) for
every student, this is an absolute address. As you know from previous
sections, you place a $ sign to the front of an absolute address;
$J$3:$K$9.
Because the Lookup value cell changes for every student, it is a relative
address. Finally the formula becomes
=VLookUp(E3, $J$3:$K$9, 2, TRUE)
The formula is ready and can be copied for other students.

Functions and Formulas

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)

Value at the intersection of the 2nd row and 2nd


column in the range (Pears)

=INDEX(A2:B3,2,1)

Value at the intersection of the 2nd row and 1st column


in the range (Bananas)

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

Figure 5.34: Using Defined Names

92

will give the intersection of these ranges (48)

Microsoft Excel

5.5.7 Database Functions


For a good analysis of data, you need to have a well organized data list. This
is called a database. Microsoft Excel provides a flexible environment for you
to prepare well organized lists and powerful functions to process and decide
fast. For this purpose, it includes many functions that analyze data stored in
lists or databases. One of these functions, referred to collectively as the
Dfunctions, uses three arguments: database, field, and criteria. These
arguments refer to the worksheet ranges that are used by the function. When
placing criteria:
 Take care that your criteria field does not overlap with your database.
 Do not place your criteria field beneath your database.
Example 5.42
The Assistant director of Atlanta High School is using an Excel worksheet to
keep track of students attendance. In his form, he has 6 columns of
information; Class, Name, Date, Subject, Hours, and Motivation. But,
because its quite difficult to count or to filter and then process all the data,
he wants a formula that counts automatically all the data with the given
criteria. In the example below, he wants to search all data for Todd Raffertys
unmotivated absences. (Design all the data in a worksheet and write your
formula using the DSum function).
CRITERIA
Class

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

Functions and Formulas

93

Analysis and Solution:


As it is explained in the question, we need six fields: Class, Name and
Surname, Date of absence, Subject, Number of hours, and if the absence is
Motivated or not. (Motivated True means the student has permission.)
Because the database might grow bigger, the criteria field should not be
beneath the database. So, we can place it to the top of the sheet starting from
B2 till the end of G3 that includes your search values together with the titles.
Every time we add another absence, well add to the bottom of the database
and it will grow bigger. Well use the DSum function which adds the numbers
in the field column of records in the database that match the criteria.
=DSum (Database, Field, Criteria)
We want the result to appear in the 5th row, so we will write the formula into
the cell B5. The Database range according to the given table is B7:G18,
where B7 is the start address of the Database. But, because your table will
grow bigger, you shouldnt use G18 as the Last cell. Rather than 18, you
should use something big enough to handle your future table; like 2000. And,
the Criteria range is B2:G3 and we want the Hours field to be summed
according to the Criteria. Then, the formula becomes;
=DSum(B7:G2000,"Hours",B2:G3)
It will calculate the sum of the numbers in the Hours column with the records
complying with the criteria described in the Criteria range. When you enter a
name in the criteria name part, all the absences with that name will be
processed. If you want to see the total unmotivated absence of this student,
in the motivation field, write FALSE. Or, if you want absences from a specific
subject then write also the subject name. The function will return the sum of
the Hours column with the records satisfying your criteria.

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
?

6. What is the result


of the function
=Max(B1:D4)

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)

2. According to the figure in question 1, if the


value of A5 is 40, what can be the formula
in it?
a. =Count (A1:A4)

b. =Sum (A1:A4)

c. =Average (A1:A4)

d. =Max (A1:A4)

7. Which function returns the result of the


mathematical expression Sin(30)?
a. =Sin(30)
b. =Sin(30*P/180)
c. =Sin(30*180/Pi())
d. =Sin(30*Pi()/180)

3. If you want to type a formula in a cell, you


must start your formula with a ..... sign.
a. =

b. !

c. $

d. ?

4. Which of the followings is not a Microsoft


Excel function?
a. If

b. List

c. Max

5. Look at the next figure. The


A5 cell contains the
formula =A1+A2+A3.
What can be the reason for
the error message #VALUE!?
a. The column is too narrow
b. A3 contains text
c. One of the columns is deleted
d. Formula is misspelled

Functions and Formulas

8. What is the result of the formula in A4?


1
2
3
4

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

9. The result of =Int(-1.5) is less than the


result of=Trunc(-1.5)
TRUE 

FALSE 

95

10. According to the formulas in C1 and C2,


which one is true?
A B
1 John 3
2 Smith 4

13. What is the result of the formula


=Int(3.741696) + Round(36.9245,2)

a. 40,1

b. 40

c. 39,92

d. 39

=If(B1<=2,"Very bad" ,If(B1<4, "Bad", "Perfect"))


=If(B2<=2,"Very bad" ,If(B2<4,"Bad","Perfect"))

a. John : Very bad Smith : Bad

14. Match the following functions with the


definitions?

b. John : Bad Smith : Bad


c. John : Very bad Smith : Very bad

Functions

d. John : Bad Smith : Perfect

11. Which formula must


be written into cell
B2 to calculate the
volume of the cube
in the figure?
A
1 A:
2 Volume:

Definitions

Min

Calculates the average value of a list of numbers

Max

Adds a list of numbers.

Average

Finds the smallest value in a list of numbers.

Sum

Finds the largest value in a list of numbers.

15.

In cells B1 through G1 these values are


entered arbitrarily. What is the result of the
formula =CountIf(B1:G1, >5)

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

16. The LookUp functions allow you to


a. Retrieve the names of workbooks and
worksheets.

12. Find the result of the formula


=VLookUp (2, A2:D4, 3)

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

b. Retrieve information according to given


criteria.
c. Dynamically change information in different
workbooks and worksheets.
d. Retrieve information stored in different
reseources.

d. 4

Microsoft Excel

Project
1. According to the figure next write the necessary
formulas to


calculate the average salary of all employees

find the maximum salary

find the minimum salary

find the total salary

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

The Average salary of all employees :


Maximum salary :
Minimum salary :
Total salary :

?
?
?
?

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).

3. In the following Figure, write a formula




in A3 to calculate the multiplication of


the numbers in range A1:F1.

in B6 to calculate the absolute value of


the given number in A6.

in D6 to calculate the square-root of the


given number in C6.

in F7 to calculate xy

Functions and Formulas

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 #
?

5. Create a mini trigonometric table below.


A
1
2
3
4
5
6
7
8
9
10
11
12

Degree
0
10
20
30
40
50
60
70
80
90

C
D
Mini Trigonometric Table
Radian
Sinus
Cosine

E
Tangent

6. Use the following functions on the table below.


1
2
3
4
5
6

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

8. Draw the following chart using Sin and Cos functions.

9. Write the necessary formula,




in column B to show the


lengths of adjacent names in
column A.

using Find, Left, Mid and Len


functions to separate the
texts in column A to the
columns D and E as shown
in the figure.

10. Write the necessary formulas


into the cells between B11
through G11 that will accept C9
as student id using the
VLookUp function.

Functions and Formulas

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

Maths Physics chemistry AVERAGE


4
5
3
4

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

12. A very common use for a lookup formula involves an


income tax rate schedule (see the figure next). The
tax rate schedule shows the income tax rates for
various income levels.
Write the necessary formula to the B3 cell that
checks the income level (B2) and returns the Tax rate.

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

14. There is an international Informatics


Olympiad in your country. They
prepared a table after the exam. For
some statistical purposes, they want
to get some information from the
table. Write the necessary formulas


In cell F18 to show the number of


students who did not participate
on the first day;

to show each student's total


points in the column F

in cell F20, to show the number


of students from the given
country, in the cell B20.

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

Functions and Formulas

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.

19. Prepare the following figure using the absolute reference


formula in the cells C12:F12.
Note: Multiply the exchange rates in C9:F9 with A12 to
produce the results.

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.1 Preparing Lists


Microsoft Excel is perfect when you have huge lists with lots of numbers and
calculations. It has many fast and easy to use tools to analyze and process
data. Sorting and Filtering are two examples of this.
A simple example that shows the advantage of sorting is the telephone guide.
In telephone guides for many cities, you have hundreds of thousands of
names. Can you imagine what would happen if the names in these guides
were not in order? You would need to search, sometimes for many days, to
find a single name. But since the names are in order you easily find a name
in minutes.
For a good analysis of data, firstly, you need to prepare well organized data
lists. This is called a Database. There are some important rules when
preparing lists.
1. Before you start any other operation, perhaps the most important part is
to think carefully and decide the titles of the list. After you start collecting
data, it can be very difficult to add another field to your list.
2. The same type of information must be entered to each column. For
example; for a travel agency's records, you may assign name, date of
reservation, hotel, suite type, payment type, and total price, etc. as
column titles.
3. It is better to prepare single purpose clear titles. Try avoiding mixed
columns. For example, if you store hotel name and suit type in the same
column, you might have difficulty later.
4. Try to avoid blank rows and columns.

6.2

Sorting

Sorting means putting or arranging items in order, according to some criteria.


Sorting is commonly used with lists. In many conditions, you prepare lists and
put them in order.

6.2.1 Using Fast Sort


When you have a simple sort (sorting according to one field), first, you select
the range using your mouse (or keyboard). Then, using your Tab and Enter
keys, activate the column according to which you want your list to be sorted.

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

Figure 6.2: Attendance list

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

Figure 6.1: Faster Sort

6.2.2 Custom Sort


Microsoft Excel provides an easy feature to put the items in order; the Sort
dialog box.
 Click on a cell in the range that you want to sort. Excel will automatically
determine the extent of the list. If you dont want to include the entire list,
and you want to sort only a part of it; or, if somehow Excel cannot
determine the exact range; Select the range of cells yourself
 Click the Custom Sort 3 button from Home Editing Sort & Filter to
display the Sort dialog box, Figure 6.4.

2
3

Figure 6.4: The Sort dialog box

Data Processing

Figure 6.3: Sort & Filter commands

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

Figure 6.5: Before and after sorting

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:

 Firstly select the list including the header row


 Then click Custom Sort from Home Tab Editing Sort&Filter (Figure 6.6)

 Itll open the Sort dialog box (Figure 6.7)


Figure 6.6: Custom sort

Figure 6.7: Sort Dialog Box

 Select Name from the Column combo box then


 Click the Add Level button this will open new level
 Select the Surname field from the second column list
 Press OK.
Class Name Surname

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

Figure 6.8: The sorted list: by Name and then by Surname

Data Processing

107

6.2.3 Custom Lists

You can show Custom Lists dialog


box from
Excel Options Advanced Edit
Custom Lists ...

The Custom List option lets


you specify a custom sort
order; such as Low, Medium,
High; or Jan, Feb, Mar, so
forth. You can write your list
order in the List Entries
column, and click on the
Add button to add this to the
Custom lists. Your Custom
List is ready to be used in
sorting orders now. Custom
Lists is explained in Chapter
8.7.5.
Figure 6.9: Custom Lists dialog box

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

 Filter 4 , which includes filter by selection, for simple criteria

 Advanced Filtering in Data Tab, for more complex criteria


Filtering does not rearrange a list; it temporarily hides rows which dont meet
the criteria. When Excel filters rows, you can edit, format, prepare charts,
copy/paste and print your subset list without rearranging or moving.

Figure 6.10: Filtering

6.3.1 Quick Filter


When you activate the Filter command 4 from Home Editing, small
arrows 5 appear to the right of column labels in the list. If you click on these

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.

Figure 6.11: Quick Filter Options

108

Microsoft Excel

Figure 6.12: Popup menu, Filter options

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.

6.3.2 Advanced Filter


The Advanced Filter command can filter a list in place like the
AutoFilter command, but it does not display drop-down lists
for the columns. Instead, you type the criteria by which you
want to filter in a separate criteria range above the list. A
criteria range allows for more complex criteria to be filtered.
The following wildcard characters can be used as comparison
criteria for filters when filtering lists.

Operator

Meaning

? (question Any single character. For example, sm?th


mark)
finds smith and smyth
Any number of characters. For example,
* (asterisk)
*east finds Northeast and Southeast
A question mark, asterisk, or tilde. For
~ (tilde)
example, fy91~? finds fy91?

Example 6.3:

Figure 6.13: Using Wildcards

Your guidance teacher has a list of absences in a worksheet. He wants to


analyze the list with questions like: show me the list of the students whose
absences are between March and June and at the same time who have two
hours from a lesson, etc. Help him to prepare the list.
Solution: You can apply an Advanced filter. You can write a condition for
each column. After that, you can apply these conditions to your main range
of data.
Advanced Filter can even copy the result onto another location. First, click the
Advanced button from the Data tab, and then select your criteria range.
Finally click the Copy to
another location radio
button to activate the Copy
to combo box, and then
select the location where the
result will be copied to.

Condition
Range

Data Range

Copy to

Figure 6.14: Advanced Filter

Data Processing

109

6.4 Consolidating Worksheets


Consolidation means you summarize the information from several workbooks
or worksheets using linked formulas into a worksheet. Here are two common
examples of consolidation:
 The budget for each department in your company is stored in a single
workbook, with a separate worksheet for each department. You need to
consolidate the data and create a company-wide budget on a single
sheet.
 Each department head submits a budget to you in a separate workbook
file. Your job is to consolidate these files into a company-wide budget.
These types of tasks can be very difficult or quite easy. The task is easy if the
information is laid out exactly the same in each worksheet. If the worksheets
arent laid out identically, they may be similar enough. In the second example,
some budget files submitted to you may be missing categories that arent
used by a particular department. In this case, you can use a handy feature in
Excel that matches data by using row and column titles using the Consolidate
command in the Data Tab.
If the worksheets bear little or no resemblance to each other, your best bet
may be to edit the sheets so that they correspond to one another. Better yet,
return the files to the department heads and insist that they submit them
using a standard format.
You can use any of the following techniques to consolidate information from
multiple workbooks:
 Use external reference formulas.
 Copy the data and use Home Clipboard Paste Paste Link.
 Use the Consolidate dialog box, displayed by choosing Data Data
Tools Consolidate.

6.4.1 Consolidating worksheets by using formulas


Consolidating with formulas simply involves creating formulas that use
references to other worksheets or other workbooks. The primary advantages
of using this method of consolidation are
 Dynamic updatingif the values in the source worksheets change, the
formulas are updated automatically.
 The source workbooks dont need to be open when you create the
consolidation formulas.
If youre consolidating the worksheets in the same workbook and all the
worksheets are laid out identically, the consolidation task is simple. You can
just use standard formulas to create the consolidations. For example, to
compute the total for cell A1 in worksheets named Sheet2 through Sheet10,
enter the following formula:
=SUM(Sheet2:Sheet10!A1)

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.

6.4.2 Using Consolidate Command


You can use the Consolidate dialog box, displayed by choosing Data Data
Tools Consolidate.
Example 6.4:

Figure 6.15: Marks Sheet for


distribution

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).

This box, in general, is divided into 4 parts.


 From the first combo box 1 you select the consolidation
function. You have the standard 11 outline functions here. In
this example, because every teacher will enter information
into his/her range, you can use the Average or Sum
functions.
 Using the second 2 box, you define ranges and, click the
Add button. That range is inserted into the All references

3 box. In this exercise, select A1:F10 range and click Add


button. When you change the active sheet, the address in
the Reference box automatically changes, too. So, if you
have identical ranges in the sheets, you dont have to
redefine the ranges, you just click the Add button to add the
new range to the All References box.

Data Processing

1
2
3

Figure 6.16: Consolidate Window

111

 Some files submitted to you may be missing categories that


arent used by some others. In this case, you can use a handy
feature here that matches data by using row and column titles:
Use labels in part 4 . You select both: Top row and Left column
in this example.
 If you check the Create links to source data 5 box, Excel will
create dynamic links to the other worksheets/workbooks. So, if
the teachers change their data in their files, your file will be
updated everytime your sheet is recalculated.
 After you finish adding all the worksheets, press OK to finish.
Figure 6.17: Consolidated Data

After you finish, it closes and returns the consolidation worksheet


and prepares the table, as in Figure 6.17, using Outline option in
Excel (well discuss outline in the following chapters). When you click
on any plus sign on the left of the row headers, it will open the hidden
rows and show the contents. As you see, each cell contains linked
cell value in the referred worksheet. And, at the bottom of each
group, we have the outline function (row 7 in this case contains the
Sum function).

6.5 Pivot Tables


A pivot table is essentially a dynamic summary report generated from a
database. After a few simple clicks, a pivot table can help transform endless
rows and columns of numbers into a meaningful presentation of the data.
After you create a pivot table, you can rearrange the information in almost any
way imaginable and even insert special formulas that perform new
calculations. On the other hand, one minor drawback for using a pivot table
is that a pivot table does not update automatically when you change
information in the source data.

6.5.1 Inserting a Pivot Table


 Select the table and
 Press the Insert Tab Pivot Table button. Thisll open the Create Pivot
Table dialog box.
 Then, press OK. Excel then creates an empty Pivot table in a new sheet.

112

Microsoft Excel

a. Create Pivot table Dialog box

b. Empty Pivot Table

a. Adding Pivot table fields

Figure 6.18: Inserting a Pivot table

 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

Figure 6.19a: Accountancy Report

Figure 6.19b: Summary according to Fields

Data Processing

113

Figure 6.20a: Summary according to Sports & Qtrs

With another click you can show: Summary according to Sports and Qtr.
Deselect the Sports from the field list.

Figure 6.20b: Summary according to Qtrs

114

Microsoft Excel

Questions
1. You can filter according to colors.
TRUE 

FALSE 

2. You can sort according to colors.


TRUE 

FALSE 

6. You applied AutoFilter to the


table in question 4. Then,
for the column No, you
applied a custom filter as
shown in the figure below.
How many students will be
displayed?

3. What is the meaning of this button?


a. Sort ascending
b. Sort descending
c. Enter formula
d. Autosum
4. Which of the following is true for filtering
data?
a. It deletes the row(s) which meet criteria.
b. It moves the row(s) which meet criteria.
c. It hides the row(s) which meet criteria.

a. 5

b. 2

c. 3

d. 4

d. It displays the row(s) which meet criteria.


7. . means putting or arranging
items in order, according to some criteria.
a. Listing

b. Auto filtering

c. Filtering

d. Sorting

8. You have a list which contains all students


information from all classes. But, you want
to see only one class. Which Excel feature
should you use?
5. Which of the following is used to show
only the records according to given
criteria?
a. Consolidate

b. Filter

c. Short

d. Pivot Tables

Data Processing

a. Validation
b. Auto filter
c. Conditional formatting
d. Auto series

115

9. Which of the following is a way to sort


numbers in decreasing order?

13. Which one of the following is not true


about sorting in ascending order?

a. Select all numbers and click Sort


ascending or Sort descending from the
View tab.

a. Numbers are sorted from the smallest


negative number to the largest positive
number.

b. Select all numbers and click on


Descending order from the Data tab.

b. When you sort text, Excel sorts left to right,


character by character.

c. Select all numbers and click Sort from the


Data tab, then check, Sort left to right from
Sort Options.

c. In logical values, FALSE is placed before


TRUE.
d. Blanks are always placed first.

d. All of them

10. . is a quick and easy way to find


and work with a subset in a data list.
a. Sorting

b. Filtering

c. Spelling

d. Subtotals

14. In the figure below, you add a custom filter


to column B as follows. Which rows are
visible?
a. 3, 4, 5

b. 3, 4, 5, 9 10

c. 9, 10

d. 6, 7, 8

11. You can consolidate data only from the


different worksheets of the active workbook.
TRUE 

FALSE 

12. Which of the following function cannot be


used in consolidation?

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.

Figure 7.1: Annual Sales Report

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.

7.1 Inserting Charts


Excel offers powerful and easy to use Chart tools to create charts with some
simple clicks. You select the range and then, select proper chart type from
Insert Charts tab. Its all that simple and your chart is ready.
Example 7.1:

Figure 7.2: Istanbul city Monthly


Weather Statistics

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

7.2 Chart Tools: Design Tab


After you prepare your initial chart and select it, 3 new tabs will appear in the
ribbon. These are called Contextual tabs. The first of these tabs is the Chart
Design Tools tab which contains the tools for: Chart Type, Chart Data, Chart
Layouts, Chart Styles, and the Location. The tools, different than the previous
Excel versions, are so efficient and rich that they have many ready to use
formats prepared by professionals. You just need to be a little patient to
decide for a good color and design.

Figure 7.5: Chart Tools Design Tab buttons

7.2.1 Chart Layouts


The Chart Layouts group contains possible positioning layout options for:
Chart Title, X and Y category axes title positioning, Legend positioning, etc.
options.

Legend is a box that identifies


the patterns or colors that are
assigned to the data series or
categories in a chart.

Figure 7.6: Chart Layouts

7.2.2 Chart Types


If the selected chart type didnt fit your needs, you dont
have to start over. Just, click the Change Chart Type button
in the Chart Design Tools tab. It will open the dialog box
containing many options. You can choose the new chart
type from this dialog box.
Figure 7.7: Changing Chart Type

Charts

121

7.2.2.1 Bar Charts


You may use different types of charts for different purposes. For example, for
annual sales, because its easy to see the growth/shrink, you can select
Column, Cylinder or Line.

Figure 7.8: Column and Line Charts

7.2.2.2 Pie Charts


On the other hand, for market shares or for the results of an election, you
could prefer a Pie chart, etc. A pie chart consists of a circle split into
segments. The segments represent individual parts which make up the total.
Figure 7.9: Pie Chart

7.2.2.3 Scatter Charts


Scatter charts are used when you have two or more variables and you want
to search the relation between them. (See Chapter 5.5.4.8 Correlation) In the
left figure, as you see, there is a strong negative relation between the number
of absences and final grade.

7.2.2.4 Other Charts

Figure 7.10: Scatter Charts

A surface chart is useful when you want to find optimum combinations


between two sets of data. As in a topographic map, colors and patterns
indicate areas that are in the same range of values. Like a pie chart, a
doughnut chart shows the relationship of parts to a whole, but it can contain
more than one data series.

7.2.3 Chart Styles


Chart styles offer many professional color and design sets. All
you need to do is to select the one that suits your needs. You
are not limited with these predefined style sets. You can also
select a different color theme and have fun with hundreds of
different style sets. Moreover, you are able make your own
changes as you wish.

Figure 7.11: Chart Styles

122

Microsoft Excel

7.3 Chart Tools: Layout Tab

Figure 7.12: Chart Layout Tools Tab

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.

Figure 7.13: Axis title positioning

7.3.1 Layout In Brief


1. Chart Title: Descriptive text that briefly explains the purpose of the chart.
Its usually located at the top of the chart.
2. Axes: Charts typically have two axes (axis: A line bordering the chart plot
area used as a frame of reference for measurement. The Y-axis is usually the
vertical axis and contains data values. The X-axis is usually the horizontal axis
and contains categories or items) used to categorize and measure data: a
category (X) axis and a value (Y) axis. 3-D charts have a third (Z) axis. Pie and
doughnut charts do not have any axis.
3. Legend: A box that identifies the patterns or colors that are assigned to the
data series or categories in a chart. You can choose the legend location by
selecting one of the Bottom, Corner, Top, Right, or Left buttons.
4. Gridlines: Lines you can add to a chart that make it easier to view and
evaluate data. Gridlines extend from the tick marks on an axis across the plot
area. Choose proper options, either you want to display the major and/or
minor gridlines for the X and Y axis. Usually, minor gridlines are not displayed.

Charts

123

5. Data Labels: A label that provides additional information about a data


marker, which represents a single data point or value that originates from a
worksheet cell. Choose to display and/or format data labels.
You can place Legend keys with the assigned format and color, next to the
labels in the chart.
 Series name displays data on the selected axis as the default category (x)
axis, even if data is date formatted.
 Category name displays the category name assigned to all data points.
For scatter and bubble charts, the X value is displayed.
 Value displays the value represented for all data points.
 Percentage displays the percentage of the whole for all data points in pie
and doughnut charts.
 Separator allows you to choose how the contents of the data label are
separated. Choose from the options available or type in a custom
separator.

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.

7.4 Chart Tools: Format Tab


Chart Tools Format tab contain the standard shape formatting tools that has
been explained in the MS. Word book of this series. Briefly, we have Shape
Style tools, WordArt tools, and shape arrangement tools here.

Figure 7.14: Chart Tools: Format tab

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.

Figure 7.15: Inserting Chart

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.

Figure 7.16: Adding Title

Charts

125

To open the Format Chart Area


dialog box
 Select an object from the
chart area

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.

 Click the Format Selection


button in the Current
Selection group.

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.

Figure 7.18: 10A Math Semester 1 Results Chart

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

2. A bar chart is useful for . .


(Choose all that apply)

6. An doughnut chart is useful for .... .


a. Showing optimum combinations between
the two sets of data.
b. Comparing individual items.
c. Showing the relationship of parts to a whole
with more data series.
d. Showing changes to data at regular
intervals.

a. Showing the amount of change in data over


time.
b. Showing the relationship of parts to a
whole.

7. Which of the following tabs contains the


Chart command?

c. When searchingthe relation between two or


more variables

a. Home

b. Page Layout

d. Comparing individual items.

c. Formulas

d. Insert

3. From where can you change the positions


of: Titles, Legend and Data Labels?
a. Chart Options

b. Source Data

c. Chart Layouts

d. Chart Type

4. Which chart type is used to show the


optimum combinations between the two
sets of data?
a. Column

b. Scatter

c. Pie

d. Surface

8. Charts typically have two axes used to


categorize and measure data: a category
(x) axis and a value (y) axis. Pie and
doughnut charts do not have any axes.
TRUE 

FALSE 

9. Which chart type(s)


cannot be used for
the table below?
I. Doughnut

5. Can you add more data series to a pie


chart?
a. Yes

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.

2. Make the following chart for the given data.

Charts

129

Word Search Puzzle


Solve the clues and find each word in the puzzle.
R

Words

Clues

AXES

Plural form of a straight line around which an object rotates.


A chart type.
Visual display of information.
A chart type.
Information
Brief description which appears on a computerized note.
Used to identify each bar in a 3-D column chart.
A chart type.
The secondary gridlines on the background of a chart.
General or descriptive heading for a chart.
A chart type used especially on limited data.
The main gridlines on the background of a chart.

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.

8.1 Data Validation


You can help users to enter accurate and appropriate information into
worksheets with MS. Excels Data Validation feature. Data validation can
restrict the type of information that is entered in a cell and can provide
instructions for the user on entering information.
Example 8.1: Back to your teachers worksheet. To improve it, he asks you
to restrict the data entrance. Because the school uses a 10-grade system, he
wants to be able to enter only the whole numbers between 1 and 10.

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

Figure 8.1: Math lesson exam results

Analysis and Solution:


Before you open the Data Validation dialog box, you must select
the range of cells to which you want to apply validation. Select the
range C2:D9 range. Now, you can open Data Validation from the
Data Tab. In the Settings tab of the Validation dialog box, you can
enter validation criteria.
You can choose the type of data that you want to enter in your
selected area from the Allow drop down menu. For this example,
select Whole number type. From the Data drop down menu, you
can enter the range of the values, depending on the conditional
criteria. Set the minimum value to 1 and maximum value to 10.

Figure 8.2: Data Validation

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.

Figure 8.3: Data Validation: Input Message

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.

Figure 8.4b: Data validation error message

If you clear the check box at the top, the error alert will
be disabled.

Extra Options

Figure 8.4a: Data validation Error Alert

133

8.1.1 Data Validation Allow Options


In data validation dialog box we have different tools for different
purposes. In the previous example, we had decimal numbers
between 1 and 10. On the other hand, in another situation
 Using the list option, you might want to restrict the (or select
from list of) birthplace entries, for the cities from your country
 Again using the list option, you can restrict class entries to
allow only specific classes.
 Using date option, you might want to restrict the birth date
entries, between two dates
 Again using date option, you might want to restrict the
birthdate entries. You can allow registering only the people
who are 18 or older.

8.2 Freeze and Split Panes


Figure 8.5:
Data validation allow options

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.

8.2.1 Splitting Panes


You Split a worksheet in order to view and scroll different parts of it
independently. Splitting a worksheet into panes allows you to view different
parts of the same worksheet side by side. It is useful when you want to copypaste data between different areas of a large worksheet.

Figure 8.6: Horizontal and Vertical Split buttons

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.

Figure 8.7: View tab Window

When you want to remove a split,


you can double click on it, or
click Split button again from the
View tab.

Figure 8.8: Split panes

8.2.2 Freezing Panes


To keep row and column labels or other data visible as you scroll through a
sheet, you can Freeze the top rows and/or left columns. The frozen rows and
columns do not scroll but remain visible. But other rows or columns are
automatically hidden while you move through the rest of the worksheet.

Figure 8.9: View Window tab

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

Figure 8.11: Titles in the place of column headings

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

Figure 8.12: Freezing panes

8.2.3 Displaying a workbook in more than one window


Sometimes, instead of using split, you may want to open a workbook in
different windows. You also can display a single workbook in more than one
window. For example, if you have a workbook with two worksheets, you may
want to display each worksheet in a separate window in order to process the
two sheets simultaneously. All the window-manipulation procedures
described previously still apply. Choose View Window New Window to
open an additional window for the active workbook.

8.2.4 Synchronous Scrolling two workbooks


Sometimes, instead of using split or freeze, you want to compare data from
two different workbooks. For such situations you can open two workbooks at
the same time, then use the View side by side button from Window group in
View tab. If you also select Synchronous Scrolling, when you scroll down in
one window the other window also scrolls simultaneously.
Figure 8.13: Synchronous Scrolling

8.3

Group and Outline

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.

Figure 8.14b: Auto Outline

Figure 8.14a: 11th grade annual report

You click somewhere in the table, then all you need to do is to click Auto
Outline from Data Outline Group tab.

Figure 8.15a: The list after outlining

As you see in this figure, after Auto Outline, Excel creates


the Outline according to your formulas and places some
plus and minus signs for each. When you click on any
minus sign, Excel collapses relevant columns and hides
the details of that outline. If you click on any plus sign,
Excel expands the details of it. In the following figure,
Math, Physics and Chemistry exam details are hidden
but the Computer Exam details are shown.
Figure 8.15b: Math, Physics and Chemistry lessons collapsed

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.

Figure 8.16: Grouping Columns

In a worksheet, there can be only


one range of Group and Outline.
So, if you need to group two
different ranges, use two
worksheets.

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.

Figure 8.17: Using Subtotal

Select the entire table first, and then, use SubTotals button. It will show you
the SubTotal dialog box.

138

Microsoft Excel

Figure 8.18: Using Subtotal command to prepare the outline of a table

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.

As you might guess, in order for


Excel to outline properly, the
column that you select in At
each change in box (Class
column) must be sorted.

8.4 Using Watch window


Sometimes, when you work with large amount of data and
you need to consult some data frequently, its suggested to
use the Watch window. So, you dont have to move around
and hunt data in that mess.
In the next figure, if you need to consult some currencies
frequently, you can add them in the Watch window so when
you move around, you can see and reach your favorites
easily.

8.5

Comment

Sometimes, especially when you share a workbook with a


group of people, you may want to explain your worksheet to
others. You can insert comments and when they point at the
cell, Excelll show automatically the comment they are
attached to.

Extra Options

Figure 8.19: Watch window

Double click on a cell in the


watch window to jump to it
directly.

139

8.5.1 To Insert a Comment:


1. Right-click the cell you want to attach a comment to
2. Select Insert Comment from the popup menu.
Figure 8.20: Adding Comments

3. Type in the comment in the box


4. Click anywhere outside the comment area when you are finished.
To Edit a Comment:
1. Right-click the cell that contains the comment you want to edit.
2. Select Edit Comment from the popup menu.
3. Edit the comment.

Figure 8.21: Editing Comments

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.

8.5.2 To Format a Comment:


1. First, right click on the cell and from the popup menu select the
Shown/Hide comments
2. Then right click on one of the borders of the comment
3. Select Format Comment from the shortcut menu.
4. Adjust the comment from the Format Comment dialog box.
Example 8.6:
You can insert a picture in the comment box.
 Select Colors and Lines tab in the Format Comment dialog box.
 Click the Color drop-down list and
 select Fill Effects.
 In the Fill Effects dialog box, click the Picture tab and
Figure 8.22a: Using pictures in
comments

 then click the Select Picture button to specify a graphics file.

8.5.3 To change Comment Shape


Normally, a comment is rectangular in shape. But you can change it.
 First, add the Change Shape button into the QAT, from Drawing Tools.
 Then, make your comment to be shown always and select it.
Figure 8.22b:
Changing Comment Shape

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.

8.6.1 How to Use Change Tracking


To activate Tracking changes, firstly, your workbook cannot contain any table
(table which is defined by Office as a Table). If your workbook is OK with this,
save it first and click the Highlight changes button from Review Changes
Track Changes.
Figure 8.23a: Highlight Changes

Figure 8.23b: Highlight Changes dialog box

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

List changes on a new sheet: Displays the changes on a separate history


worksheet that you use to filter the information to find the changes you want.
This check box is available only after the workbook has been saved as a
shared workbook.

Figure 8.24: List changes on a new sheet

8.6.2 Sharing a Workbook


Sharing a workbook is another way to collaborate data. You can share a
workbook to allow changes by more than one user at the same time.
You share a workbook using the Share Workbook button from the Review
Changes tab. This also allows workbook merging. You can remove any users
you do not want to use the shared workbook.

Figure 8.25: Sharing a workbook

Figure 8.26: Sharing a workbook

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.

8.6.3 Display changes


Using Accept or Reject Changes from Review Changes Track Changes,
you can accept or reject any change in the workbook. When you click on this
button Excel will first ask for saving the changes. After that, itll open the
Accept or Reject Changes dialog box.

Figure 8.27: Accept or reject changes

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.

8.7.1 General Tab

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.

Figure 8.29: Office Menu Excel Options

144

Microsoft Excel

From this tab, you can


 Enable Live Preview
 Change color scheme,
 Change Screen tip style
 Define the number of worksheets,
 Change default fonts,

8.7.2 Formula options


This tab includes options related to the Formula calculation, performance,
and error handling options.
Calculation options
Workbook Calculation specifies how you want Microsoft Office Excel to
calculate workbooks: Automatic, Automatic except for data tables, Manual,
etc.
Enable iterative calculation: When this option is selected, it allows iterative
formulas (also known as circular references) to be calculated. Unless you
specify otherwise, Excel stops after 100 iterations or when all values change
by less than 0.001.

Figure 8.30: Formula options

Extra Options

145

Working with formulas


Using
your
programming
capabilities, you can also write
your own function that converts
R1C1 into A1 reference style.
(This can be a good case study).

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.

8.7.3 Proofing Options


Proofing options includes Language tools. You should be familiar with the
AutoCorrect Options from MS. WORD. Using AutoCorrect you can correct
your misspelled words automatically. Or, you can create new shortcut words
for your company initials, etc. e.g. you can select to replace your initials im
with your name Ibrahim Mesecan.

Figure 8.31a: Proofing Options

146

Figure 8.31b: AutoCorrect Options

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.

8.7.4 Save Options


As its clear from the name, this tab contains
the options for saving. You can change
 Default save format.
 Saving time for the Auto Recovery file
 Default file location
 Offline editing options for document
management server files
 AutoRecover exceptions
 Preserve visual
workbook for the

appearance

of

the

Figure 8.32: Save options

8.7.5 Advanced Options


Probably, the most commonly used tab. It
contains many different options in different
categories:
 Editing options contains the options when
editing a worksheet, like:
 After pressing Enter, move selection
down;
 Enabiling fill handle and cell drag-anddrop;
 Allow editing directly in cells;
 Enable AutoComplete for cell values;
 Use system separators, is nice if you
dont want to change your system
setting but you want to change how
Excel handles numbers with floating
point. Etc.

Extra Options

Figure 8.33: Advanced options

147

 Cut, Copy, and Paste options


 Display contains the options like:
 Show this number of Recent Documents;
 Show function ScreenTips;
 Options for cells with comments; etc.
 Display options for this workbook/worksheet
 General Options:
 Enable multi-threaded calculation: This option enables fast calculation
by using all of the processors on your computer or by using the
number of processors that you type manually;
 When calculating this workbook
 Update links to other documents;
 Set precision as displayed: Permanently changes stored values in cells
from full precision (15 digits) to whatever format is displayed, including
decimal places. Be careful that, this can cause your data to lose
precision. Etc.
 Lotus Compatibility

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

dialog box and click the Cell Name button 2


to select your Custom list range. After you
select the range of the list, press ENTER. This
will take the address of the list to the Import list

from cells box 1 . After that, click the Import


button 3 , your list will be added into Custom
Lists 4 .

Figure 8.34a: Creating Custom Lists

148

Microsoft Excel

In order to sort a list according to this custom lists:


 First Add your list into Custom lists
 Then select your range, and click the Sort & Filter
button from Home Editing to display the Sort dialog
box
 Select Column and Sort On combo boxes properly
 Then, select Custom Lists from the Order Combo box
 It will show you the Custom Lists Dialog box, Select
your custom list and press OK.

Figure 8.34b: Using Custom Lists

8.7.6 Customize Ribbon and QAT


Ribbon doesnt include all the commands that you can
use in Excel. By using Customize you can change your
Quick Access Toolbar, so that, you can add new
commands that are not available in the ribbon or you
commonly use but not easy to access from the ribbon.
You can also prepare your own tab in the Office 2010.

8.7.7 Trust Center


Because macros could be very dangerous, you
needed to be very careful when opening Excel
documents in earlier Excel versions. But now,
developers of Excel made a lot of improvements. The
most essential change is the Macro containing files
extensions. If an Excel document contains macros, it is
saved with .xlsm extension. The good side is that, in a
way, if the extension is changed to .xlsx Excel will not
open it and warn that this is not a recognized format.

Figure 8.35: Customizing QAT

In general, Trust Center is the essential window for


security. By default, developers setup it quite secure.
You just need to be careful when you see a warning
message over Formula bar:

If you click the Options button, itll show the MS.


Security Options dialog box. If you trust the sender of
the file you can enable the macro. If you are not sure
what to do, you should better protect yourself.

Extra Options

Figure 8.36: Trust Center Options

149

Questions
1. validation criteria allow the user
to enter anything in the cell.

6. When you Highlight Changes, which of


the changes below is tracked?

a. Decimal

b. Any value

a. Change sheet names

c. List

d. Custom

b. Insert or delete worksheets


c. Add or change comments
d. Changing the formula of a cell

2. The validation criteria allows you


to enter your birthday to the cell.?
a. Decimal

b. Date

c. Time

d. Text Length

According to the default Excel settings,


choose the right one.

7. Gridlines are hidden.


TRUE 

3. Which is the Excel Options button located?


a. In Home tab

NOT DEFINED 

8. The resulting value of any formula can be


seen in cells.
TRUE 

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 

4. You can change the comment shape.


TRUE 

FALSE 

10. This View settings does not effect other


sheets in the same workbook.
TRUE 

5. If the manual option is selected from the


calculation tab on the Options window, which
key is used to recalculate the formulas?
a. F5
150

b. F8

c. F7

d. F9

FALSE 

NOT DEFINED 

11. Function screentips are visible.


TRUE 

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.

2. Create the following table and apply grouping as shown


in the figure.

3. Use the split command on the table in the first practice.


4. Suppose that your workbook contains 4 sheets. Show how you can write the same data to all sheets
simultaneously.
5. Can you hide
sheet tabs,
vertical & horizontal scroll bar,
column & row headers,
formula bar,
status bar.
6. Change the color scheme silver and the gridlines color to dark blue.
7. Change the cell calculation style to manual so that it wont calculate results automatically.
8. Add a list showing the days of the week of your country.
9. How can you secure your Excel document?

Extra Options

151

Put the Words in Groups


Write the following commands into their own Tab on the Options menu.
1. Font size

8. Include this many sheets

2. Flag repeated words

9. AutoCorrect options

3. Show all windows in the taskbar

10. Use all processors on this computer

4. Save in this file format

11. Use 1904 date system

5. R1C1 reference style

12. Use table names in formulas

6. Enable iterative calculation

13. Dictionary language

7. Color scheme

14. Show insert options buttons

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

Figure 9.1: Developer tab Code


group commands

Macro is a series of instructions to perform an operation automatically. If you


perform a task repeatedly, its better to use a macro for this process. You can
save your processes in Excel and give a name and a shortcut for this process
(macro), then, any time you need to perform it; you can just call it to repeat
the same process for you.

9.1 Before Starting Macros


Here are some essential things that you should know before starting macros.

9.1.1 Displaying Developer Tab


If you plan to work with VBA macros, youll use Developer tab often. To
display this tab:
1. Choose Office Excel Options.
2. In the Excel Options dialog box, select Customize Ribbon.
3. Place a check mark next to Developer tab.
4. Click OK to return to Excel.

9.1.2 Some Definitions


VBA newcomers are often overwhelmed by the terminology that is used in
Macro programming. Here are some key definitions for a better
understanding.
 Macro: A series of commands and functions that are stored in a Microsoft
Visual Basic module and can be run whenever you need to perform the
task.
 VBA-Visual Basic for Applications: Special programming language for
Macros that you can use in Excel and other Office applications
 Module: A container for VBA code where you write your macros.
 Code: VBA commands that are produced in a module sheet when you
record a macro. These commands -keywords- have special syntax. You
can make Excel to produce the code for you or you can enter it manually.
 Function: One of two types of VBA macros that you can create. (The
other is a Sub procedure.) A function returns a single value. You can use
VBA functions in other VBA macros and also in Excel sheets.
 Procedure: The other name for macro sub programs. A VBA macro can
be a Sub procedure or a Function procedure. Sub procedures do your
operations described there.

154

Microsoft Excel

 Object: An element that you manipulate with VBA. Examples include:


Ranges, Charts, Sheets, and so on.
 Controls: Objects on a UserForm (or in a worksheet) that you
manipulate. Examples include: buttons, list boxes, etc.
 Method: An action taken on an object (or control). For example, applying
the Clear method to a Range object erases the contents and formatting
of the cells.
 Property: A particular aspect of an object. For example, a Range object
has properties like: Height, Style, and Name.
 UserForm: A container that holds controls for a custom dialog box and
holds VBA code to manipulate the controls.
 VB Editor: The window (separate from Excel) that you use to create/edit
VBA macros and UserForms.

9.1.3 Security first


Because macros can be very dangerous, in the earlier Excel versions, you
needed to be very careful when opening Excel documents. But now,
developers of Excel made a lot of improvements. The most important change
is the Macro containing files extensions. If an Excel document contains
macros, it is saved with the .xlsm extension. This means that before opening
the document you know that it contains macros. The good side is that, in a
way, if the extension is changed to .xlsx Excel will not open it and warn that
this is not a recognized format.
Trust Center is the essential window for security in general. By default,
developers setup it quite secure. You just need to be careful when you see a
warning message over the Formula bar:

If you click Options button, itll show MS. Security Options


dialog box. If you trust the sender of the file you can
enable the macros in it. If you are not sure what to do, you
should protect yourself. If you dont enable the macros,
you can still edit the document as a standard Excel
document. In order to arrange security tightly, select Trust
Center from the Office button Excel Options.

Figure 9.2: Options in Trust center

Macros

155

9.2 Writing Your Macros


In general, you can write macros using two common methods:
 By recording
 Writing macros manually

9.2.1 Recording Macros

Figure 9.3: Developer tab Code


group commands

Write the macro


name here

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:

Figure 9.4: Record Macro dialog box

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

ALT+F8 displays the Macro


dialog box to create, run, edit, or
delete a macro.

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

Figure 9.6: VB Editor environment

In this window, the main pane includes your Macro.

The header of
subprogram
Explanation /
User Comments

Sub Macro1()
' Macro1 Macro
' Macro recorded 08.04.2009
'
' Keyboard Shortcut: Ctrl+Shift+D

Press Alt+F11 to open VB Editor.

'

Actual code

Macros

Selection.Delete Shift:=xlToLeft
End Sub

157

9.2.2 Writing Macros Manually


From this Visual Basic Editor window, you can edit your code (Macros) or you
can write your entire code from the beginning. Most of Basic Programming
Language, Excel and Visual Basic instructions can be used here. Here is a
brief explanation about the code above:
 The text after the apostrophe is an explanation, not a programming code.
 Sub is a command that says to VB (Visual Basic) that a subprogram with
the name Macro1 is starting.
 And End Sub shows that the subprogram has ended.
 So, we have just one line of code here. And, instead of recording, you
could manually write your macro like this one:
Sub Macro1()
Selection.Delete Shift:=xlToLeft
End Sub

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.

9.2.3 Types of Macro Procedures


There are two types of macro procedures:
 Sub procedures
 Function procedures
In the example above, we had a sub procedure. You can also have function
procedures in your macros. Function procedures are like Excel functions, and
they return a result to the name of function somewhere in your code (usually
at the end). They start with the keyword Function. When you create a function
procedure, you can use it in your macros and in your Excel sheets.

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

Now, change it manually as follows,

Microsoft Excel

Parameter(s)
Function header
After your
calculations, you
return a result to
the name of the
function.

Function Cube(num As Integer)


Cube = num * num * num
End Function

Figure 9.7:
Using VB functions in Excel

 Then in your Excel sheet, you can use it as your other predefined
functions.

9.3 Macro Language


In your Macros, you can use Excel object language, or Basic programming
language.

9.3.1 Excel Object Hierarchy


VBA is an object-oriented language, which means that it manipulates objects,
such as Ranges, Charts, AutoShapes, and so on. These objects are
arranged in a hierarchy. The Application object (which is Excel) is the topmost object and contains other objects. Most of objects can contain other
objects. For example, a Workbook object can contain the following objects:
 Charts (a collection of Chart sheet objects)
 Names (a collection of Name objects)
 Styles (a collection of Style objects)
 Windows (a collection of Window objects in the workbook)
 Worksheets (a collection of Worksheet objects)
When you write the object name followed by a period, after a short time, Excel
will display possible operations, sub objects and properties that you can use
in this context.

Figure 9.8: Object model code


compilation

9.3.2 Object Collections


A collection consists of all like objects. For example, the collection of all
Workbook objects is known as the Workbooks collection. You can refer to an
individual object in a collection by using an index number or a name. For
example, if a workbook has three worksheets named: Sheet1, Sheet2, and
Sheet3, you can refer to the first object in the Worksheets collection in either
of these ways:

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.

9.3.3 Assigning value to a cell


Using the Range command in Excel, we can assign a value to a range.
Range("B2") = 7

'Puts 7 to the cell B2

Range("C1:D3") = 5

'Puts 5 to all cells in the range C1:D3

Range("A:A") = 3

'Puts 3 to all cells in column A

Range("5:5") = 4

'Puts 4 to all cells in Row 5

Range("B1") = Range("D7") 'Copies the value of D7 to B1


Range("B2") = ""

'Clear the contents of B2

9.3.4 Using the Message Box and Input Box


InputBox can be used to get info from the user.
Name = InputBox("Enter your name please..:")

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!")

9.3.5 Concatenating Two Strings


Figure 9.9: Using inputbox and
message box

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".

9.3.6 Using Basic Programming Language in your


macros
You can use Basic Programming Language in your Macros. Here are some
essential structures from it.

160

Microsoft Excel

9.3.6.1 Selection statements


The most common selection statement is the If Then structure. It is used to
decide. It has two essential and one optional part.

If (Boolean Expression) Then


Statement
Else

This part is optional

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..:")

Res=MsgBox("Hello Mr." & Name & ". Are you sure?", _


vbYesNo,"Delete Record?")

If Res = vbYes Then

Figure 9.10: Using InputBox and


MsgBox in Macros

Selection.Delete Shift:=xlToLeft
End If
End Sub

Macros

161

9.3.6.2 Repeating some statements


Using For Next loops, you can repeat some operations:
For x = 1 To 10
' The code here will be repeated 10 times
Next x

D1 is the parameter and its


value is assigned to Num.

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

The loop is repeated Num


times (7 in this example).

Result = Result * x
Next x
NFactorial = Result
End Function

x represents all numbers


from 1 to num(7). Then,
Result is multiplied by all
the numbers from 1 to 7.

9.3.7 Object Browser


Object Browser gives short description and usage information about
commands and objects. It shows class names and Members of the selected
class. It also gives the properties of the member; either the member is
property or a function of the class.

Write your command


here to search

Figure 9.12: Object browser

162

Microsoft Excel

9.4 Ready for a bigger project?


Your physics teacher is preparing a multiple choice exam and he wants to
check this exam using Excel. He designed a worksheet similar to Figure 9.13.
He is going to write the answers of a student in this sheet. At the end, he
wants to store the result using a macro. Macro will take the result (D14) and
name (C1) to the end of the list in the columns F, G and H.
Analysis and Solution: According to his design:
 The current students name will be written into C1
 The current Student order is written in E4
 Student answers will be written in to B4:B13
 The cells C4:C13 already contains the correct answers,
 The cells D4:D13 have the formulas to check if the student answer is the
same as the correct answer.
 F, G and H columns contain the result list.
A

Student's

Name

Todd Williams

QN Answers Correct Answers Result

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

Figure 9.13: Physics exam results

Macros

163

Arranging formulas first


Result is a formula that checks if the answer of current student is the same as
the correct answer. For the first question, itll check if C4 is equal to B4. If both
are the same, itll give TRUE, otherwise FALSE.
=IF(C4=B4,TRUE, FALSE)

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.

Before starting to record macro


After you prepare the sheet, for each student, the teacher will write names into
C1 and answers into B4 through B13. Then, the formulas will produce his total
correct answers. Macro is now ready to run and store this student info.

Record your macro


After entering all data, well call the macro for this
student. Well use the number in E4 for the row number
of the destination. After starting macro, you will
 Give a name and a shortcut for your macro
 Copy the student name from C1 into destination row
in column G
 Copy result from D14 into column H.
 After that increment the number in E4
 And clear old data (The cells B4:B13 and C1)
 Select C1
 Stop recording
Figure 9.14: Viewing Excel and Visual Basic Editor
Simultaneously

When recording, you can show both Excel window and


VB Editor at the same time to watch your recording.
If you record this macro, it will be something similar to
the following code,

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

'Clear old name


'Clear old answers
'Select name cell

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")

' RowOrder is currently 7

Then, instead of writing the result always to G7, we can concatenate and form
the new address as,
Range("G" & RowOrder)

Macros

' This is like Range("G7")

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")

'Copies the name into column G

Then, our final program becomes,


Sub Macro1()
' Keyboard Shortcut: Ctrl+Shift+P
'
RowOrder = Range("E4")

'Takes the row order from E4

Range("G" & RowOrder) = Range("C1") 'Copy the name into column G


Range("H" & RowOrder) = Range("D14")'Copy the result
Range("F" & RowOrder) = RowOrder

'Copy Student order

Range("E4") = RowOrder + 1

'Increment row order

Range("B4:B13") = ""

'Clear the old answers

Range("C1") = ""

'Clear the Name cell for next student

Range("C1").Select

'select C1 for the next student

End Sub

9.4.1 Want More? (Optional)


If you find it confusing, dont worry, you are not alone.
Programming subjects come difficult for many people in
the world. But, be patient and ask more and more from
Excel, itll show how to solve your problems. Dont forget
that practice (with patience) makes perfect. Here is
another project for you.
In your school, Science teachers decided to have a
general exam every month. Because its getting more
and more difficult to process data every month, they
decided to use Macros. Theyll have a list similar to the
figure on the left.
The sheet has two parts: Starting from the 6th row, they
will place general exam data; they want to see the results
of query at the top.
Figure 9.14: General exam sheet

166

The class and student name information will be provided


into the cells A3 and B3. And then, with a shortcut key,
macro will run. Macro will search all the data for the
specified class and student. In the third row, they want
specified students marks. And in the fourth row, they
want to see lesson averages of the selected class.

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

Figure 9.15: Record GDS GetData


macro

Paste also the results over the Range(C3:F3)


 Repeat this LastSt times
Its quite normal that nobody can know everything. So, for the parts we dont
know, we can ask from Record Macro to find out. Lets say that we dont
know how to add a range over another.
We run Record Macro from Developer Tab. It will ask for a macro name and
a shortcut. After you press OK, it will start recording Macro.

In this record macro, we want Excel to show us how to add the value of a cell
range onto another. So,

When giving macro names:


1. Use Letters, digits, and
underscore sign only. No
special characters allowed
like: %, $, # or space.
GetDollar is OK; Get$ is not.
2. Start with a letter: FirstPlace
is OK; 1stPlace is not.
3. Dont use special words
(Keywords) for Excel and
VBA. GetData is OK; For,
While are not.

 We select the source range then, we copy it.


 After that, we right click on destination, and select Paste Special from
the menu.
 Finally, from the Paste special window, we select Paste: Value,
Operation: Add.

Macros

When giving shortcuts be careful


not to overwrite the predefined
(standard) shortcuts. Ctrl+C
means copy.

167

1. Sub GetData()
2. ' Getdata Macro

Pay attention to the underscore


sign at the end of line 9. If your
statement exceeds the visible
window
size,
using
an
underscore you can continue
from the next line.

3. ' Macro recorded 7/20/2007


'
' Keyboard Shortcut: Ctrl+Shift+D
Range("C11:F11").Select

'Select source

Selection.Copy

'Copy

Range("C4").Select

'Select destination

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlAdd, _


SkipBlanks

:=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

Here is the entire code


Sub Calculate()
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 next operation

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

9.5. Form Controls


Until now, we studied how to record a macro; how to modify it; and some
main Excel Macro elements. However, there are some other tools which
facilitate many operations in Microsoft Excel Macro. Form Controls is one of
these tools.
1. Button

7. Group box

2. Combo box

8. Label

3. Check Box

9. Scroll bar

4. Spinner

10. Edit Box

5. List Box

11. Combo List Edit

6. Radio Button

12. Combo Drop Down

Figure 9.15: Developer tab Controls Insert Form Control

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

 or press the Record Button to record a new macro


 or you can select one of the existing macros in the list then press Assign.
Any time you need, you can see this macro by using the Macros
command from the Developer Tab (or right click on the button and select
Assign Macro) then click the Edit button to edit it as you wish.

9.5.2 Combo Box


Combo box is used to list some items and lets you select one. Selected item
will appear in the main box. Different than other objects, Form Controls have
another tab in the Format Control window: Control Tab. Using this tab, you
can change the controls like; input range, cell link and some other status
options for the combo 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.

9.5.3 Check Box

Figure 9.19: Combo Box

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.

Figure 9.20a: Sample combo boxes

9.5.4 Option Button


Option button is also a common button in many programs. Its used when
you have different options where its possible to select only one. When you
have two possible options, its better to use a check box. But, if you have
three or more options and only one of them can be selected at a time, then,
its better to use combo box or option buttons group. For example, For cells
with comments option in Excel Options, we have 3 possible choices. And,
you can select only one of the choices. Or, in most of the multiple choice
exams, only one answer can be selected: A, B, C, D or none.

Figure 9.20b: Sample combo boxes

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

If you dont change the Format


Control Properties, when copying
or resizing cells, the controls over
these cells are also copied or
resized.

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

Figure 9.21b: Accountancy program

For his expenses, he prepared a list of categories and numbered them.


Instead of memorizing many categories with their numeric values, he wants
to select the category from a combo box. After then, hell write the date,
explanation and the amount. Finally, after pressing a button, he wants to put
this record into the database.
Analysis and Solution
First, we design the worksheet as in the figure above. We write our new
expenses in row four. We have just one combo box and its cell link is at its
back: B4. Combo box input range can be in another sheet showing the
expenses (the table on the left).
When entering data, we select the expense category from the combo box.
Because, the cell link of the combo box is B4, the result will appear at the
back of it. Well then write the date, explanation and the amount of payment.
After we press the macro button, The macro will
 copy and insert the range A4:E4 to the top of the list, A7:E7
 then, it will clear the range C4:E4
 finally increment the number in A4 for the next operation.
The sum of the numbers will appear in A2. But for this sum formula, our start
cell must be less than 7 (6 is OK), and somehow bigger than our initial size
of list (20 or 30).
=SUM(E6:E20)

Figure 9.22: Combo box properties

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") = ""

'Clear for the next operation

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

Figure 9.23: Multiple choice exam

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.

Writing your macro


Now right click on an option button and select Assign Macro from the
menu. For Macro Name box, write Answers. And click New from the Assign
Macro window. This will open the VB editor with a new sub procedure.
Change it as follows:
Sub Answers()
'Option button has been clicked
answer = Range("C2")
If
If
If
If
If

answer
answer
answer
answer
answer

=
=
=
=
=

1
2
3
4
5

Then
Then
Then
Then
Then

Result
Result
Result
Result
Result

=
=
=
=
=

"A"
"B"
"C"
"D"
""

'Get the answer. The one has been clicked.


'Convert option button to a letter

QN = Range("D1")
Range("B" & QN+3) = Result

'Get current Question Number


'Write the result in column B

QN = QN + 1
Range("D1") = QN

'Increment QN for next operation and


'store QN

If QN > 15 Then
res = Range("D19")

'After the last question show a MsgBox


'Get his result

C=MsgBox("The result is" & res & _


", Clear the answers?", vbYesNo, "Information")
If C = vbYes Then
Range("D1") = 1
Range("B4:B19") = ""
End If ' end of C=vbYes
End If ' end of QN>15
End Sub

174

Microsoft Excel

Explanation of the macro


When we click on an option button, itll
 read the button number from the cell link (C2) and convert it to a letter
(Result).
 After that, it will read the question number from D1 (initially its 1).
 Because, we have 3 more lines at the top, and our first answer is in the
4th row, write the result to the cell B4 (B & QN+3).
 Then it will increment the QN for next question (QN= QN + 1) and assign
it to D1 (Range("D1") = QN)
 for every click, it will repeat the same macro process, until, QN exceeds
the last question (15). When it exceeds the last question, its going to
show the result
 and ask whether to clear the old data or not. If you say OK then the old
answers will be cleared.
Macro for the selected option button is ready. Now, you need to assign this
macro also to the other option buttons. Pay attention that you dont need to
write the same macro for each, just assign this macro for all the others.

9.6 Using User Forms

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.

Figure 9.25: Questionnaire

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

'Option button was clicked


'Get the Answer for the current question
'Get Questionnaire number
'QN is for Questionnaire Number
'Get Question Number
'Get the answers of current examinee
&
&
&
&
&

"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"

a. A1 will have the value in ClassName - "A"


b. Its an illegal operation
c. A1 will have "5A"
d. It assigns "5A" to ClassName
2. How can you run a macro?
a. Select Macros from the Developer Tab.
Then, select your Macro and click the Run
button
b. Select the Developer tab Play Macro and
select your macro
c. Press Alt+F11 and click somewhere in your
macro
d. Click the Run Dialog button from the
Developer tab Controls then select your
macro and press OK
3. If you perform a task repeatedly in
Microsoft Excel, you can automate the
task by using a ...
a. Filtering

b. Formula

c. Macro

d. User Form

4. Which of the followings are not valid


macro names? Explain.
a. CalcTax%

b. Calculate Salary

c. FirstofAprilJokes

d. 2ndExpense

5. What is the shortcut to open the VB


Editor?

178

6. Which of the following is not a Form


Control?
a. Option Button

b. Check box

c. Button

d. Popup menu

7. What is the shortcut to show the Macro


dialog box?
a. Alt+F8

b. Alt+F11

c. Ctrl+M

d. Ctrl+F5

8. What does the following statement do?


Range("A1") = Range("A1") * 2

a. Multiplies the value in A1 by 2 and puts the


result back in A1
b. A1 will contain half of the old value
c. The square of the value in A1 is written
d. Its an illegal operation
9. What does the following statement do?
Range("A1:F1") = ""

a. The Range("A1:F1") will have a double


quotation
b. The Range("A1:F1") will have zero
c. Clear the contents in the Range("A1:F1")
d. Its an illegal operation
10. Which of the following is not a property of
Combo box in Excel?
a. Cell link

b. Input range

c. Selected Item

d. Drop down lines

11. For what an input box is used for?


a. to get a value from the user using a box
b. To store some values there

a. Ctrl+F5

b. Alt+F7

c. To show a message to the users

c. Alt+F11

d. Ctrl+F12

d. To hide some details from the users


Microsoft Excel

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.

2. Champions League Matches: UEFA has fired their computer programmer,


because of some disagreements. and now, they need someone who can
solve their programming problems.
Basically, they have difficulty with their current pointing system and they
want to calculate points of each team directly from the score board. In a
data board, in an Excel sheet, they store the scores of each match. And
they want you to write a macro program that will take the data from the
board and calculate the points and sort the teams.

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

4. Prepare a calculator in Excel.


Prepare buttons as in the figure. As a second project, you can also upgrade
this calculator to make complex calculations using parenthesis.
Note: Use Macros, dont use the easier method in which you calculate the
results without programming.

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.

4. Write a function to calculate the cube root of a number.


Note: You can use power operator (^) num ^(1/3)

5. How many Macro procedure types do you know?

6. What are the properties of Functions?

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

Custom List 108, 148

Abs 80

Customize 13, 54, 149

Gridline

57, 123

Group

136, 138, 170

Absolute 69, 70, 80


Active cell 9, 21, 44
Alignment 36, 39, 42, 125
Area 21, 22, 54, 126, 132

D
Data 110, 132, 137, 176
Data Validation 132

Assign 124, 160, 162

Date 38, 56, 77, 80, 86, 93, 105

Auto Correct 146

Day 39, 80, 148

Autofit 24

Delete 24, 25, 26, 140, 157

Average 72, 86, 87, 91, 168

Developer 28, 154, 256

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

Double Click 11, 23, 24, 26, 43, 135

I
If 83, 85, 174
Index 92, 159

Border 24, 40

Button 70, 76, 170

Enter 21, 22

Cancel 21, 178

F2 23

Keyboard 12, 59, 157

Cell 9, 21, 23

Factorial 82, 162

Chart 57, 120, 159


Check box 170, 171
Class 134, 162
Color 36, 40, 42, 44, 106

File format 16
Fill 20, 24, 36, 41
Fill series 20, 148
Filter 108, 109

Column 8, 9, 13, 15

Input box 24, 160


Insert 24, 27, 44, 70

L
Left 21, 22, 60, 89, 135
Len 89, 90
Link 26, 66, 110
Logical 76, 84, 90

Find 89, 90, 92, 109


Combo box 170, 172, 176
Footer 55, 56
Comment 139, 140
Complete 21
Concatenate 160, 165, 176
Conditional Formatting 45
Consolidate 110

M
MMacro 16, 149, 154

Format 16, 20, 37, 39


Format control 170, 172
Format painter 43
Formatting 20, 25, 27, 36, 42, 45

Margin 36, 55
Match 90, 92, 94
Merge 36, 40, 141
Message box 160

Contextual 11, 121

Formula 13, 23, 25, 66

Method 155

Correlation 88, 122

Formula bar 8, 23, 41, 67

Mid 89, 90

Count 73, 75, 79

Fraction 23, 38

Module 154

Countif 86, 164

Freeze 134

Month 14, 77, 80, 148

Currency 38, 39

Function 71, 76, 158

Mouse 12, 14, 20, 42

Move 20, 22, 26, 147

Pie 122, 123

Shape 124, 140

Title 105, 121, 125

Multiple 21, 22, 24, 27, 40, 60, 86,


173

Pivot table 112, 113

Share 122, 139, 141

Today 77, 86

Pointer 20, 24, 36

Shift 22, 24, 27, 39, 77, 157

Tracking 141, 143

Preview 58, 59, 145

Shrink 40, 122

Transpose 26, 168

Name box 8, 9, 67, 68

Print 54, 57, 59, 60

Sin 81

Name Manager 44

Procedure 154, 158, 161

Skip blanks 26

NetWorkDays 80

Property 155, 162

Smart tags 20

Now 77

Protect 28, 41, 149

Sort 104, 106, 149

Number format 37, 39, 78


Numeric processing 10

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

Object 43, 126, 155, 159, 162

Review 10, 141, 142

Office 2003 12, 41, 44, 46

Ribbon 9, 11, 12, 13

Style 40, 42, 66

Operation 25, 154, 167

Right 20, 22, 55, 89

Subtotal 74, 138

Watch 139, 164

Orientation 26, 40, 54

Row 9, 24, 66, 69

Sum 69, 71, 83, 112

Workbook 9, 14, 16, 42

Page break 8, 58

Scale 54, 57

Tab 9, 10, 40, 54

Page setup 54, 59, 60

Scatter 122, 124

Table 15, 43, 90, 112

Page view 8, 9, 58, 59

Scrolling 136

Task 10, 154

Paste 20, 25, 108, 167

Security 66, 149, 155

Template 16

Paste Special 25, 167

Select 20

Themes 25, 41, 42, 122

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

Wiley Publishing, Inc.

MS. Office Excel 2007 Bible

Wiley Publishing, Inc.

Excel 2007 Formulas

Wiley Publishing, Inc.

Microsoft Office Excel 2007 Step by Step

Microsoft Press Excel 2003, Zambak Publishing

Excel 2007 Power Programming with VBA

Wiley Publishing, Inc.

MS. Excel Help Contents

Microsoft Inc.

MS. Excel 2003 Inside Out

Microsoft Press

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