Unit 4
Unit 4
4.0 OBJECTIVES
The objective of this course is to help you understand how MS Excel can be used for
sorting and filtering the data. By the end of this practical course, you will know how to do
the following:
• recognize and understand many of the functions in Microsoft Excel;
• sort the dates in ascending and descending order;
• learn how to show and hide the rows and columns;
• how to add filters to the data;
• removing the filters from the data; and
• using pivot tables as a data summarization tool
• learn how to create, change interactively, delete or copy a pivot table
4.1 INTRODUCTION
Data Form
When a spreadsheet is designed for data the menu item Data: Data Form can be used for
data entry. Select Data Form from the Data menu. Click on the New button in the upper
right corner. Enter the data shown below. Use the Tab key to move to the next field blank.
Do NOT use the down arrow key: it will cause the Data form to "go blank." The reason for
this is because the down arrow generates a next New record.
Use of the tab key to move from one field to the next has been a standard in the data entry
industry for over 30 years. The Tab key will work in Excel, Microsoft Access, and fill-in-
the-blank fields found on the Internet and all other data entry applications.
Data Sorting
When a spreadsheet is designed for data the menu item Data: Sort will detect the field
names and offer to sort by field name. Select Sort from the Data Menu. Set up your sort as
follows:
Filtering
When the spread sheet is too long and we need to find the data in the spread sheet on the
basis of some particular fields/values, we can use the inbuilt filter option, which has
different range and criteria for filtering the data.
As you might expect from their names, ascending sorts are done such that values increase,
while descending sorts result in values decreasing. How does this affect your actual data,
however?
If you choose to do an ascending sort, Excel uses the following sorting order:
1. Number values, from least to greatest
2. Date and time values, from earliest to latest
3. Text values, numbers first, then alphabetically (1, 2, 3, a, b, c, and so on)
4. Logical values, FALSE, then TRUE
5. Error values
Descending is the opposite of ascending. No matter which order you choose, Excel always
places blanks (empty fields) at the end of the final list.
Issue: Check that dates and times are stored as dates or times If the results are not what
you expected, the column might contain dates or times stored as text and not as dates or
times. For Excel to sort dates and times correctly, all dates and times in a column must be
stored as a date or time serial number. If Excel cannot recognize a value as a date or time,
the date or time is stored as text.
NOTE: If you want to sort by days of the week, format the cells to show the day of the
week. If you want to sort by the day of the week regardless of the date, convert them to
text by using the TEXT function. However, the TEXT function returns a text value, and so
the sort operation would be based on alphanumeric data. For more information, see Show
dates as days of the week.
If you have a Microsoft Excel workbook that contains a column or row that you want to
hide, you can do this easily. With a few clicks, you can hide this column and row from
view. You won't be deleting the column or row, because you can redisplay it later when
you want it to be viewed.
Step 1 Start Microsoft Excel and open an existing workbook that contains a column or
row that you would like to hide. If you'd prefer, start a new workbook and enter
data into a column or row that you would like to hide.
Step 2 Click in any cell that lies in the column or row that you would like to hide. The cell
will have a thick black line around it when you have selected it, meaning that you
can move on to the next step.
Step 3 Choose the "Format" menu and click on "Column" if you want to hide a column. If
you want to hide a row, click on "Row."
Step 4 Click "Hide" in either the "Column" or "Row" submenu to hide the column or row
that contains the cell you have selected. The column or row will now be hidden
from view. You will notice that the hidden column letter or row number will be
missing from your workbook.
Show All
Select the rows or columns you want to hide.
To select Do this
Text in a cell If editing in a cell is turned on, select the cell, double-click in it, and
then select the text in the cell.
If editing in a cell is turned off, select the cell, and then select the
text in the formula bar.
A single cell Click the cell, or press the arrow keys to move to the cell.
A range (range: Two or Click the first cell of the range, and then drag to the last cell.
more cells on a sheet.
The cells in a range can
be adjacent or
nonadjacent.) of cells
A large range of cells Click the first cell in the range, and then hold down SHIFT and
click the last cell in the range. You can scroll to make the last cell
visible.
Nonadjacent cells or cell Select the first cell or range of cells, and then hold down CTRL and
ranges select the other cells or ranges.
Adjacent rows or Drag across the row or column headings. Or select the first row or
columns column; then hold down SHIFT and select the last row or column.
Nonadjacent rows or Select the first row or column, and then hold down CTRL and
columns select the other rows or columns.
More or fewer cells than Hold down SHIFT and click the last cell you want to include in the
the active selection new selection. The rectangular range between the active cell (active
cell: The selected cell in which data is entered when you begin
typing. Only one cell is active at a time. The active cell is bounded
by a heavy border.) and the cell you click becomes the new
selection.
NOTES:
If the first row or column of a worksheet is hidden, click Go To on the Edit menu. In the
Reference box, type A1, and then click OK. On the Format menu, point to Row or
Column. and then click Unhide.
Instead of being hidden, the height or width of the first row or column of a worksheet may
have been set to zero. In this case, point to the border of the Select All button until the
cursor changes to or , and then drag to widen the row or column.
Sub AAA()
Dim Rng As Range
Dim Found As Boolean
For Each Rng In Range(Cells(1, 1), Cells(1, Columns.Count)).Cells
If Rng.Value = Date Then
Found = True
Exit For
End If
Next Rng
If Found = True Then
Range(Rng(1, 2), Cells(1, Columns.Count)).EntireColumn.Hidden
= True
End If
End
1- Excel use same sorting order for both ascending & descending
a- True
b- False
3- For Excel to sort Date & Times correctly, all Date & Times in a column must be stored
as:
i- Text
ii- Date & Time
iii- None
Displaying specific parts of data in Excel can be accomplished by simply applying filters
with Excel's AutoFilter command.
Here are some examples to show you how easily you can apply data filtering. Let's say
you have a spreadsheet with the title in Row 1 and column headings in Row 2 and your
data looked something like this:
Click in any cell in row 2 and go to the Data Menu and select Filter, then AutoFilter and
you will see dropdown arrows in every cell in row 2:
Click the dropdown arrow in the Department Cell and see a list of everything that is
included in that column. Choose "B" from the list:
Now your data has been filtered to only show the people in Department B:
Click the Department dropdown arrow again and select All to remove the filter.
Click the Q1 Sales dropdown arrow and select Custom. In this box, choose is greater
than from the first dropdown box and type 25000 in the second box. Click OK.
Your data has now been filtered to show only those salespeople whose sales are greater
than $25,000.
Remove the filter by returning to the Q1 Sales dropdown and select All. You could also
filter this data to show only those sales people in Dept B whose sales are greater than
$25,000. Simply apply one filter, then apply the second one without removing the first.
Excel will continue to filter your data, with the second filter being applied to the results of
the first filter.
To remove all filters, click on the appropriate column dropdown arrows and select All.
Then go back to the Data Menu and click on AutoFilter to remove the dropdown arrows
completely.
After the Excel advanced filter is applied, orders with a total greater than 500 will remain
visible.
Other operators include:
< less than
<= less than or equal to
>= greater than or equal to
3. Set up the Extract Range (optional)
If you plan to copy the data to another location, you can specify the columns that you want
to extract. If you want to extract ALL columns, you can leave the extract range empty for
the Excel advanced filter.
1. Select the cell at the top left of the range for the extracted data.
2. Type the headings for the columns that you want to extract. These must be an
exact match for the column headings, in spelling and punctuation. The column
order can be different, and any or all of columns can be included.
<> not equal to
Note: The list must contain a heading, or the first item may be duplicated in the
results.
Extract Data to another Worksheet
If the database is on Sheet1, you can extract data to Sheet2, by using an Excel Advanced
Filter:
1. Go to Sheet 2
2. Select a cell in an unused part of the sheet (cell C4 in this example).
3. From the Data menu, choose Filter, Advanced Filter.(In Excel 2007, click the Data
tab on the Ribbon, then click Advanced Filter.)
4. Choose Copy to another location.
5. Click in the List Range box
6. Select Sheet 1, and select the database.
7. (optional) Click in the Criteria range box.
8. Select the criteria range
9. Click in the Copy to box.
10. Select the cell on Sheet 2 in which you want the results to start, or select the
headings that you have typed on Sheet 2.
11. (optional) Check the box for Unique Values Only
12. Click OK.
Using Wildcards in Criteria
Use wildcard characters to filter for a text string in a cell.
The (*) wildcard .
The asterisk (*) wildcard character represents any number of characters in that position,
including zero characters.
In this example, any customer whose name contains "mart" will pass through the Excel
advanced filter.
Criteria on different rows are joined with an OR operator. In the second example,
customer must be MegaMart OR product must be Cookies OR total must be greater than
500.
By using multiple rows, you can combine the AND and OR operators. In the third
example customer must be MegaMart AND product must be Cookies
OR
product must be Cookies AND total must be greater than 500.
To remove a filter applied to one column in a range or a list, click the arrow next to the
column, and then click All.
To remove filters applied to all columns in a range or list, point to Filter on the Data
menu, and then click Show All.
To remove the filter arrows from a range or list, point to Filter on the Data menu, and
then click AutoFilter.
Pivot tables provide a way to easily summarize, analyze, consolidate, filter, prepare data
for charting, and report on large quantities of raw data in a flexible, ad hoc manner. They
are called pivot tables because you can change their layout by rearranging, or pivoting, the
row and column headings quickly and easily.
Now the user can choose the field and can add as per requirement either on row or
column
To remove a field from the table simply drags the field button outside the table range.
When the large X appears release the mouse button.
Right-click on any cell in the table and choose Options to access a dialog box of selectable
options. As in any Office 97 dialog box, right-clicking on an option and choosing "What's
This" will give you some explanation of the option. One option deserving a bit of
explanation is "Save Data With Table Layout." This option determines whether or not the
pivot table's data is stored with the spreadsheet. If you clear this check box and save the
file, you'll have to refresh the data the next time you open the file. Although this requires
an additional step, it helps keep the size of your spreadsheet files to a minimum.
Sorting
By default data is sorted in ascending order within a data label. Sort order can be changed
by right-clicking on a data label and choosing Field, or by double-clicking on a data label.
In the Field dialog box click Advanced to display the Advanced Options dialog box where
you can select the field and sort order desired.
Grouping
Grouping is useful when the data reported in the pivot table is too detailed for what you
need. Maybe with too much detail the table shows all the days in each month or you want
to report the data in histogram fashion using ranges. Right-click on the data label of the
data you wish to group. Choose Group and Outline | Group (and note the Ungroup option).
Dynamic Charting
There are two things to remember in dynamic charting. First, chart the entire data area of
the table. Second, typically you should not include totals as they will cause scaling
problems.
5-
a- Refreshing a pivot table
b- Changing a pivot table interactively
c- Deleting & changing a pivot table
d- Hiding a pivot table
4.7 Summary
When you sort information in a worksheet, you have control over the order in which that
information is sorted. Sorting in Excel lets us easily reorder our data based on the type of
sorting that we choose. This chapter had shown us how to do a ascending and descending
sort on date. Hiding rows and columns can be very helpful in keeping worksheet users
focused on important details or to keep them from straying into areas that you don’t want
them to see. The filtering tools provided in Excel make it easy to filter a data list so that
only certain rows are displayed. Excel, when used to store data, follows a database
paradigm that equates rows with records and columns with fields in each record. Classical
filtering is done by examining values in columns (fields) and thereby determining which
rows (records) should be displayed based on what is found there.
A pivot table is a data summarization tool found in data visualization programs such as
spreadsheets. Among other functions, they can automatically sort, count, and total the data
stored in one table or spreadsheet and create a second table displaying the summarized
data. Pivot tables are also useful for quickly creating cross tabs. The user sets up and
changes the summary's structure by dragging and dropping fields graphically. This
"rotation" or pivoting of the summary table gives the concept its name. The term pivot
table is a generic phrase used by multiple vendors. However, the specific form PivotTable
is a trademark of the Microsoft Corporation.