SpreadSheets - Conditional Formatting
SpreadSheets - Conditional Formatting
SpreadSheets - Conditional Formatting
BICT 1101
Lecture 3: Spreadsheets ( Conditional Formatting, Importing Data, Append Data, Data Integrity, Sorting
You can use data that already exists in another file in a workbook
instead of typing it manually.
If the data you need for a workbook is from a source outside of
Excel, then Excel needs to be able to import that data in such a
way that it can make sense of where cell entries begin and end and
where records begin and end.
Even simple text files, such as .TXT or CSV files, where values
are separated (delimited) by commas can be imported, because
commas act like fence posts, and Excel recognizes fence posts.
IMPORTING DATA
Opening Non-Native Files Directly in Excel
Excel has two main data formats:
One whose files end with .XLS extension,
One whose files end with .XLSX extension, it is XML-based
Many programs now publish data to a format that Excel accepts.
Excel can import data provided in XML format, in this case, there’s no
guarantee that the columns will all be aligned properly or that the headings
will be in the place Excel expects them to be for a table.
.TXT or .CSV file, use certain characters, such as commas and quotation
marks, as delimiters—characters that separate data entries from one
another—and that Excel will not interpret as part of a cell entry.
IMPORTING DATA
STEP BY STEP Open a Non-Native File Directly in Excel
LAUNCH Microsoft Excel and OPEN a blank workbook.
1. Click the Data tab, and then in the Get External Data
group, click From Text.
2. In the Import Text File dialog box, locate and click
Importing Data2.csv. Click Import.
3. In Step 1 of the Text Import Wizard, notice the preview at
the bottom.
IMPORTING DATA
This is Excel’s best guess, for the moment, as to how the
data should be formatted.
There are population figures rendered in “quotation
marks” with commas between each figure.
Each comma acts as the delimiter, and it’s difficult to
judge whether each figure between the commas will be
the same length.
Under Choose the file type that best describes your data,
choose Delimited and then select My data has headers.
IMPORTING DATA
4. The preview shows the headers starting on row 3. Thus, for
the Set import at row option, choose 3. Click Next.
5. In Step 2 of the wizard uncheck Tab because the preview
does not indicate long spaces between the figures. Check
Comma. Set Text qualifier to “ (quotation mark).
Scroll down the Data preview pane, and notice now that
Excel has found the column separations between figures.
Click Next.
IMPORTING DATA
6. Step 3 of the wizard lets you establish the data type for each
discovered column. Click the first column in the Data preview
pane. Then, under Column data format, click Date. Click
Finish.
7. In the Import Data dialog box that appears next, leave
Where do you want to put the data? set to Existing worksheet.
Click OK.
IMPORTING DATA
8. Change the width of column A to 16.
9. The worksheet that Excel has generated, shows United
States population estimates for each month from April 2010
to December 2012.
Excel could not make sense of the dates in column A, so it
left the data type set to General for most of the cells.
However, it did make an error in attempting to convert the
year in cell A25.
IMPORTING DATA
To correct it, begin by selecting and deleting rows 2, 12,
and 25 (be sure to select all three rows at the same time
before deleting them).
10. Click cell A2, type April 2010, and then press Enter.
11. Drag the fill handle from cell A2 down to cell A34. Excel
changes the entries in column A to proper months.
12. Delete rows 35 through 40.
13. SAVE the workbook.
IMPORTING DATA
Getting External Data
In computing, there are databases and data files. Databases are
stored in files.
A data file stores a series of records in a relatively simple format,
and Excel is a program that uses data files in this manner.
A database is a complex system that can store a large amount of
related data, which requires a program to be able to assess and
extract that data.
IMPORTING DATA
When Excel imports data from a database as opposed to a data
file (as in the previous exercise), it begins a communication
process with that database program, and instructs it to process
the data it requires.
In the following exercise, we will use a file from Microsoft Access.
STEP BY STEP Get External Data
LAUNCH Excel and open a blank workbook.
1. Click the Data tab, and then in the Get External Data group,
click From Access.
IMPORTING DATA
2. In the Select Data Source dialog box, locate Importing Data
Contacts3.accdb database file.
Select it and click Open.
3. In the Select Table dialog box, click Customers (the table we want
to import) and then click OK.
4. In the Import Data dialog box, click Table. Under Where do you
want to put the data, click Existing Worksheet and ensure the text
box reads =!$A$1.
5. Click OK.
Excel displays a formatted table, complete with AutoFilter
buttons in the column headers.
IMPORTING DATA
Appending Data to a Worksheet
After you import data from another format or database into a
worksheet, you’ll probably spend a good deal of time reconciling
that data with existing records. In the previous two exercises, you
imported data into blank worksheets. In most situations, however,
you’ll import data from other sources into an existing worksheet.
IMPORTING DATA
STEP BY STEP Append Data to a Worksheet
OPEN the Append Data4.xls workbook.
1. Click cell A21.
2. Click the Data tab, and then in the Get External Data group,
click From Other Sources and then click From XML Data Import.
3. In the Select Data Source dialog box, locate and select the
Append Data Import5.xml data file.
Click Open. A dialog box named Error In XML might appear at this
point. If so, click OK to dismiss the dialog box and proceed.
IMPORTING DATA
4. In the Import Data dialog box, click Existing worksheet and
then click OK. Although a list of customers is appended to the
end of the worksheet, the columns don’t line up. This is
typical of appended data.
5. To correct the problem, begin by moving the first names
from cell range E23:E75 to B23:B75. Overwrite the existing
contents in column B.
6. Move the last names from cell range H23:H75 to A23:A75.
Overwrite the existing contents in column A.
IMPORTING DATA
7. Repeat the process for the states in column J that should be
in column E,
the ZIP codes in column K that should be in column F, and the
phone numbers in column I that should be in column G.
8. Delete columns H through L.
9. Delete rows 21 and 22.
10. Replace all 11 instances of Dell City in column D with Del
City.
11. Adjust the column widths to fit the data.
ENSURING YOUR DATA’S INTEGRITY (CHANGING DATA
TYPES)
3. Click the Data tab, and then in the Data Tools group, click
Data Validation. The Data Validation dialog box opens.
4. Click the Settings tab.
5. In the Allow list box, choose Text length.
This is the first step in the creation of a rule governing how
many characters each new entry should contain.
6. In the Data list box, choose equal to.
7. Click the Length box and type 3.
ENSURING YOUR DATA’S INTEGRITY (CHANGING DATA
TYPES)
8. Click the Input Message tab.
This tab displays a message when you select a cell in the
validation range.
9. Click the Title box and type Rule:.
10. Click the Input message box and type Please enter a three-
digit area code.
11. Click the Error Alert tab.
Excel can display an error alert message when a user
attempts to enter data that is invalid.
ENSURING YOUR DATA’S INTEGRITY (CHANGING DATA TYPES)
12. Click the Title box and type Data Entry Error.
13. Click the Error message box and type Only three-digit
area codes are recognized.
This message is displayed in a dialog box whenever an
invalid entry is made in column L.
14. Click OK.
15. To test the new validation rule, click cell L57.
You should see the notification message you typed into the
Input Message tab.
ENSURING YOUR DATA’S INTEGRITY (CHANGING
DATA TYPES)
Sorting a data range in Excel helps you to locate the precise data
you need.
For example, you might want to sort customers in a table by their
last name rather than a random customer number you won’t
remember.
When you enter a new customer, you might find it easier to enter
the name at the bottom of the list and then resort the table
alphabetically.
This way, you don’t have to manually insert a blank row in the
middle of the worksheet, at the appropriate alphabetical
location.
SORTING DATA
Sorting Data on a Single Criterion
A Criteria or Criterion is an element used in executing a function.
For instance, a telephone directory is sorted by phone owners’
last names.
The last name is one criterion of the sort. Because many people
share the same last name, lists of students can then be sorted by
their first names, and then by their middle initials when they’re used.
This leads to two different criteria for such a sort. When individuals
in a database are indexed by number, however, and that number is
guaranteed to be unique, it forms a single criterion for a common
sort operation.
SORTING DATA
STEP BY STEP Sort Data on a Single Criterion
1. Use the current workbook Data Integrity6.
2. In the Patient List worksheet, click cell E5.
Note this is the first cell in the Owner # column and its
entries are all numerical.
3. On the Data tab, in the Sort & Filter group, click the Sort
Smallest to Largest button (with A on top of Z, and an arrow
pointing down). The list is now sorted in ascending numerical
order by Order #, which was the column you clicked in before
performing the sort.
SORTING DATA
4. Click cell A5.
5. Click the Sort A to Z button. This time, the list is sorted by
Patient Name, and again, the first column you clicked in before
performing the sort. Murdock the Rottweiler, which we previously
added to row 57, now appears in row 44. SAVE the workbook.
If your sort is based on a single column in an Excel table, you can
select the entire table range or any cell in the column you want to sort.
Be careful not to select only a portion of the table (such as a single
column) before sorting, or Excel will sort just the selected data and
the rest of the data will remain intact, resulting in mismatched
records.
Excel warns you before performing this type of sort.
SORTING DATA
Sorting Data on Multiple Criteria
A proper database containing records of people divides each element
of their names into, at the very least, last names and first names, and
might also include optional elements such as middle initials.
For this reason, any time you sort a database, range, or table by names,
you want to sort by multiple criteria.
STEP BY STEP Sort Data on Multiple Criteria
1. Click the Client List worksheet tab.
2. Select the range A4:N56.
3. Name the range Clients.
SORTING DATA
4. On the Data tab, in the Sort & Filter group, click Sort.
The Sort dialog box appears.
5. In the Sort by box, under Column, choose Last Name.
6. Click Add Level.
7. In the Then by box that appears, choose First Name.
8. Click Add Level.
9. In the next Then by box, choose MI (middle initial).
SORTING DATA
10. Click Add Level again.
11. In the next Then by box, choose Suffix.
12. Leave My data has headers checked, so that Excel won’t
treat the headers row as part of the range to sort.
13. Click OK. The clients list is now sorted alphabetically,
with people sharing the same last name sorted alphabetically
by first name.
Although the client numbers appear all out of sort, the data is
unchanged and the database itself retains its full integrity.
SAVE the workbook.
SORTING DATA
Sorting Data Using Cell Attributes
Excel is capable of sorting records based on the conditional
formatting that is applied to its cells.
Excel can sort and group those records whose cells have these
special formats applied to them.
SORTING DATA
STEP BY STEP Sort Data Using Cell Attributes
1. On the Patient List worksheet, which should still be sorted in
ascending order on column A, select column E.
2. Right-click the column and then click Insert in the shortcut
menu.
3. With column E selected, on the Data tab, in the Data Tools
group, click Data Validation.
4. In the Data Validation dialog box, click Clear All. Click OK.
When creating a new column to the right of one with a data
validation rule, the new column acquires that same rule even if it’s
intended for a different purpose.
SORTING DATA
To clear this rule, select the new column, bring up the Data
Validation dialog box, and then click Clear All as we have just
done in step 4.
5. Click cell E4 and type Spayed/Neutered. Change the width
of column E to 17.
6. In column E, type S for the following row numbers: 6, 15,
19, 21, 22, 25, 34, 37, 46, 50, and 56.
7. In column E, type N for the following row numbers: 5, 7, 8,
9, 10, 13, 16, 17, 20, 24, 27, 30, 31, 32, 36, 40, 41, 43, 47, 48,
52, 54, and 57.
8. Select column E.
SORTING DATA
9. On the Data tab, in the Data Tools group, click Data
Validation.
10. In the Data Validation dialog box, click the Settings tab.
Under Allow, choose List.
11. In the Source box, type N,S.
12. Click the Input Message tab. In the Input message box,
type S = Spayed, N = Neutered. Click OK.
13. Select the range E5:E100. Click the Home tab, and then in
the Styles group, click Conditional Formatting. Click New
Rule.
SORTING DATA
14. In the New Formatting Rule dialog box, choose Format
only cells that contain in the Select a Rule Type list.
15. In the list box, under Format only cells with, choose No
Blanks.
16. Click Format.
17. In the Format Cells dialog box, click the Fill tab. Choose
the sixth color swatch from the left in the third row. Click
OK.
18. Click OK. Now both spayed and neutered animals should
appear shaded.
SORTING DATA
19. Select the range A4:F57. Name the range Patients.
20. in the Sort & Filter group, click Sort.
21. In the Sort dialog box, in the Sort by, choose
Spayed/Neutered.
22. In the Sort On, choose Cell Color.
23. Click the down arrow next to No Cell Color. The list box
that appears shows only those colors that are actually in use for
conditional formatting—in this case, only one swatch. Click
the color swatch.
SORTING DATA
24. Click OK. The sorted worksheet should now appear.
All the “N” and “S” animals are grouped together at the
top, with the two types mingling among each other.
All the non-operated-on animals are bunched toward the
bottom.
FILTERING DATA
Using AutoFilter
An AutoFilter is the quickest means for you to find values.
With AutoFilter only rows or columns that meet simple criteria
(for example, just the students from a particular city, or students
who have joined a particular association/club can be displayed.
With filtering you can control both what you want to see and also
what you want to exclude
It converts the headings row of your table into a set of controls, which
you then use to choose your criteria and the select the data you want to
see.
FILTERING DATA
STEP BY STEP Use AutoFilter
1. Click the Client List worksheet tab. In the Name box, type
Clients and then press Enter.
Excel highlights the data range for the Clients table.
2. On the Data tab, in the Sort & Filter group, click Filter.
Excel adds down arrow buttons to the field names in all of
the columns in the list. Scroll up and click cell A5 to
deselect the range.
FILTERING DATA
3. Click the down arrow beside the Client # heading in
column A. Excel displays the AutoFilter menu.
4. To sort the table by client number, click Sort Smallest to
Largest.
This gives you a shortcut for sorting.
5. To show just the clients with addresses in Ohio, click the
down arrow beside State. In the AutoFilter menu that
appears, uncheck the (Select All) box to clear all check boxes
and then check OH. Click OK.
SAVE the workbook.
FILTERING DATA
When an AutoFilter is active, so that you see filtered results
rather than the complete table, Excel applies special notation to
the AutoFilter buttons and to the row numbers.
E.g. the button for the column used in the sort now contains an
up arrow, whereas the button for the column used in the filter
contains a funnel symbol.
Also, notice the row numbers are colored blue and are not
consecutive. If you look closely, you’ll see that where
nonmatching rows are hidden, Excel puts a double-border
between the numbers. For instance, between rows 17 and 20 and
between 46 and 54.
FILTERING DATA
Creating a Custom AutoFilter
A custom AutoFilter uses a rule that you create, instructing
Excel how to evaluate the entries in each row.
The result of that evaluation determines whether rows are displayed or
filtered out. With a simple AutoFilter, Excel looks for contents based on
actual samples from the column.
For example, with the previous task, Ohio (OH) and Indiana (IN) were
choices because both were featured in the State column; no other states
were listed.
FILTERING DATA
By contrast, with a custom AutoFilter, you can create a rule instructing
the worksheet to display only records whose values in one given column
are above or below a certain amount.
Essentially, your rule tells Excel to compare each value in the
column against something else. Whether that value is displayed
depends on the terms of the comparison—is it equal? Higher?
Lower? Is it among the ten highest or lowest?
FILTERING DATA
STEP BY STEP Create a Custom AutoFilter
1. Switch to the Patient List worksheet, and insert a new
column between the existing columns D and E.
2. Clear the validation rules from the new column E.
3. Add the title Hepatitis Inoculation to cell E4 and widen the
column as necessary to display the heading on two lines.
FILTERING DATA
4. Type the following dates into the cells shown:
E8 01/18/2016
E11 08/16/2015
E13 05/15/2016
E18 03/01/2013
E22 10/19/2014
E26 07/05/2016
E32 02/02/2015
E37 08/15/2016
E38 07/14/2015
E43 09/01/2016
FILTERING DATA
5. Select the Patients data range. The range should
automatically include the new column.
6. On the Data tab, in the Sort & Filter group, click
Filter.
7. Click the down arrow beside Hepatitis Inoculation. In
the menu, point to Text/Date Filters and then click
Custom Filter. The Custom AutoFilter dialog box opens.
8. In the first list box just below Hepatitis Inoculation,
choose is before. In the box to the right, type 1/1/2016.
9. Click the Or button between the two rows of list boxes.
FILTERING DATA
10. In the second list box below Or, choose equals. Leave the list
box blank (literally meaning “blank” or “nothing”).
11. Click OK.
After the dialog box disappears, Excel filters out all entries in
the patient list where the patient is known to have had a
hepatitis inoculation in 2016 or later.
What remains are both the animals known to have been
inoculated in 2015 or earlier, or whose inoculation dates are
not known.
12. Click the filter button beside Hepatitis Inoculation again. In
the menu, point to Text/Date Filters and then click Custom Filter.
FILTERING DATA
13. In the second list box that currently reads equals, choose the
blank entry at the top of the list. The box should now be
empty.
14. Click OK. The list should now show only the two/five
animals known to have been inoculated in 2015 or earlier.
15. Click the filter button beside Hepatitis Inoculation again.
In the menu, choose Clear Filter from “Hepatitis
Inoculation”. SAVE the workbook.
FILTERING DATA
When conditional formatting is applied to a column of cells, that
formatting is something that Excel can recognize when filtering
data.
We can say that the formatting is the value to be looked for during
the filtering.
So you can easily have a filter “hide rows where cells in a column
don’t have a particular format”, such as a shaded background or
a font color.
FILTERING DATA
STEP BY STEP Filter Data Using Cell Attributes
1. In the Patient List worksheet, click the Spayed/Neutered
button down arrow.
2. In the menu, click Filter by Color.
3. In the popup menu, choose the pink swatch. Excel now
shows only those animals that have been spayed or neutered.
SAVE the workbook.