Excel Conditional Formatting and Data Validation
Excel Conditional Formatting and Data Validation
Use the Quick Analysis tool to apply popular conditional formats, such as data bars
and icon sets, to a selected cell or range.
Click and drag to select range B4:B15.
The range is selected. At the bottom-right of the range, the Quick Analysis button
appears.
Click the Quick Analysis button.
The Quick Analysis gallery opens. The Formatting tab is selected by default and
displays a list of conditional formatting options.
Click Data Bars.
Excel adds data bars to the range.
Use data bars in a range of numbers to see at a glance which values are largest and
which are smallest. Data bars are easy to insert and require less screen space than
charts.
Click and drag to select range B4:B15.
In the Styles group on the Home tab, click the Conditional Formatting button.
The Conditional Formatting menu opens.
On the Conditional Formatting menu, point to Data Bars.
The Data Bars gallery appears.
In the Data Bars gallery, in the Gradient Fill section, click the Green Data Bar option.
Excel inserts data bars into cells in the range. The bars vary in length according to
cell value; the larger the cell value, the longer the data bar.
Use conditional formatting to make certain values in a range stand out, such as the
highest or lowest values, negative numbers, and those that equal a specified target
value.
Click and drag to select cells B4:B15.
You will create a new conditional formatting rule to apply to cells in this range.
In the Styles group, click the Conditional Formatting button.
The Conditional Formatting menu opens.
On the menu, click New Rule.
The New Formatting Rule dialog box opens. When you create a new rule, you need
to specify the rule type, the rule parameters, and the formatting the rule will apply.
In the Select a Rule Type section, click Format only top or bottom ranked values.
This rule can apply to Top or Bottom ranked values. In the Edit the Rule Description
section, the Top ranked values option is selected by default. You will accept this
setting and specify parameters in the value text box.
Select the value box, which currently displays the number 10, and type 5 in the box.
By default, the top 10 values are selected for this rule. You are changing the rule to
select the top 5 values.
In the Edit the Rule Description section, click the Format button.
The Format Cells dialog box opens, where you will choose formatting options for the
top ranked cells.
In the Format Cells dialog box, click the Fill tab.
You will fill the cell backgrounds of the top ranked cells with a color you specify here.
In the Background Color section, click the Blue, Accent 5 option, the second to last
color in the top row.
Top ranked cells will be formatted with a Blue, Accent 5 cell background.
In the Format Cells dialog box, click OK.
Excel previews the conditional formatting choice in the New Formatting Rule dialog
box.
Click OK.
Excel applies the new conditional formatting rule to the range.The top 5 cells are
highlighted in blue.
Use conditional formatting rules to identify and highlight the cells in a worksheet that
contain a target value, such as test scores over 90 or the lowest unit cost.
Click and drag to select range B4:B15.
In the Styles group, click the Conditional Formatting button.
The Conditional Formatting menu opens.
On the Conditional Formatting menu, point to Highlight Cells Rules.
The Highlight Cells Rules menu opens with a variety of rule options. You can
highlight cells based on relative values, text content, dates, and more.
Click Less Than.
The Less Than dialog box opens. The insertion point is in the Format cells that are
LESS THAN text box.
Type 50000 in the text box.
Excel will highlight every cell in the selected range whose value is less than $50,000.
Next, you will choose a formatting option for highlighting the cells.
Click the Format cells arrow.
A list of formatting options appears.
On the list, click the Yellow Fill with Dark Yellow Text option.
Click OK.
Excel highlights cells in the range B4:B15 as specified in the conditional formatting
rule.
Using conditional formatting to highlight duplicate values in a table can help eliminate
data entry errors or possible duplicate records. For example, you could check your
customer contact table to determine whether two companies have the same
Manager ID by mistake.
Click and drag to select range A5:J18.
In the Styles group on the Home tab, click the Conditional Formatting button.
The Conditional Formatting menu opens.
On the menu, point to Highlight Cells Rules.
The Highlight Cells Rules menu appears with a variety of options for highlighting
cells.
Click Duplicate Values.
Excel highlights all duplicate values in the range using the default highlight style. The
Duplicate Values dialog box opens with options to change the formatting settings.
In the Duplicate Values dialog box, click the values with arrow.
Excel displays a list of formatting options, including the default format of Light Red
Fill with Dark Red Text. You will create a custom format by changing the fill color, but
not the font color.
Click Custom Format.
The Format Cells dialog box opens. You can specify number, font, border, and fill
formatting options.
Click the Fill tab.
You will change the background fill color of cells with duplicate values to a bright
yellow.
In the Background Color section, click the Yellow color icon, the fourth icon in the
last row.
Excel displays a preview of the yellow fill color in the Sample area.
Click OK.
The Format Cells dialog box closes, and Excel changes the fill color of the
highlighted cells to yellow. The font color remains dark red.
In the Duplicate Values dialog box, click OK.
The dialog box closes, and you return to your worksheet.
Data bars can show what portion of a goal has been met. If an automatic value for
the data bars results in filling nearly all the affected cells, you can edit the Data Bars
conditional formatting rule to compare the data more clearly.
Click and drag to select range D5:D8.
You want to change the maximum value for the data bars in this range.
In the Styles group, click the Conditional Formatting button.
The Conditional Formatting menu opens.
On the menu, point to Data Bars.
The Data Bars gallery appears. You can change the data bar format using gradients
and colors, or you can customize the data bar display by clicking More Rules.
Click More Rules.
The New Formatting Rule dialog box opens. The Maximum value is currently
Automatic, meaning that Excel determines the maximum value of data bars for you.
In the dialog box, in the Edit the Rule Description section, click the Maximum arrow.
You will set a new maximum value.
On the menu, click Number.
You will specify a number as the maximum value.
Select the current value in the Value box in the Maximum section, and then
type 75000to replace it.
Click OK.
Excel adjusts the data bars to completely fill every cell with a value of 75,000 or
above.
Using a data validation rule improves the accuracy of your worksheet, and a
validation message can help even more by explaining what a valid entry consists of.
For example, a data validation message can state that users must enter a
performance rating from 1 to 5.
Click cell D6.
Cell D6 contains a data validation rule limiting cell entries to whole numbers ranging
from 1 to 5. You want to add an input message alerting users to this rule.
Click the Data tab on the ribbon.
The Data tab contains numerous options for getting, analyzing, and manipulating
data.
In the Data Tools group, click the Data Validation button.
The Data Validation dialog box opens with the Settings tab active. The Settings tab
displays the validation criteria for the current rule.
In the Data Validation dialog box, click the Input Message tab.
Your input message will explain the data parameters to the user. Note that the check
box to show the input message when the cell is selected is checked. You will accept
this setting.
Click the Title box and type Rating Parameters in the text box.
Click the Input message box and type Enter a whole number from 1 to 5 in the
box.
Click OK.
The dialog box closes, and Excel displays the input message.
Using a data validation rule with an error alert can improve the accuracy of your
worksheet by preventing entry of invalid data. Customizing the error alert can provide
further information or clarity to users.
Click cell D6.
Cell D6 contains a data validation rule limiting cell entries to whole numbers ranging
from 1 to 5. You want to create a customized error alert message for this rule.
Click the Data tab on the ribbon.
The Data tab contains numerous options for getting, analyzing, and manipulating
data.
In the Data Tools group, click the Data Validation button.
The Data Validation dialog box opens with the Settings tab active. The Settings tab
displays the validation criteria for the current rule.
Click the Error Alert tab.
You will customize the error alert properties by specifying an error style, title, and
message.
Click the Style arrow.
The Style appears with three error styles to choose from: Stop, Warning, and
Information.
Click Stop.
The Stop error style prevents users from entering invalid data into a cell.
Click the Title text box and type Input Error in the text box.
Click the Error message text box and type Value must be a whole number from 1
to 5in the text box.
In the Data Validation dialog box, click OK.
The dialog box closes. If a user tries to enter an invalid entry in cell D6, your
customized error message will display.
Create a data validation rule
Using a data validation rule improves the accuracy of your worksheet by controlling
the type of data users can manually enter. For example, a data validation rule could
require that users enter a performance rating from 1 to 5 and display an error
message if anything else is entered.
Click cell D6.
You want to restrict the acceptable inputs for this cell to whole numbers from 1 to 5,
inclusive. You will create a data validation rule to accomplish this.
Click the Data tab on the ribbon.
The Data tab contains numerous options for getting, analyzing, and manipulating
data.
In the Data Tools group, click the Data Validation button.
The Data Validation dialog box opens with the Settings tab active by default. You will
define your validation rule here.
Click the Allow arrow.
The Allow list displays validation criteria options.
Click Whole number.
The cell will only accept whole numbers. You want to further restrict cell entries by
establishing a range within which the whole numbers must fall. The default value in
the Data text box is between, which you will accept. Next, you will set the minimum
and maximum values for the cell.
Click the Minimum text box and type 1 in the textbox.
Click the Maximum text box and type 5 in the textbox.
Click OK.
The rule is complete; only whole numbers ranging from 1 to 5 can be entered in cell
D6. If you try to enter a number that does not fit the rule, Excel will display an error
message and ask you to try again.
Use icon sets to illustrate, at a glance, which values in a group of numbers are
higher and lower than others.
Click and drag to select range D4:D18.
On the Home tab, in the Styles group, click the Conditional Formatting button.
The Conditional Formatting menu opens.
Point to Icon Sets.
The Icon Sets gallery appears.
In the Directional section, click the 3 Arrows (Colored) option, the first option in the
section.
Excel applies the icon set format to the range, with the green arrow indicating high
values, the yellow arrow indicating medium values, and the red arrow indicating low
values.
Conditional formatting can make your worksheet more meaningful and easier to
understand. If you change your mind about the formatting, you can edit the
formatting rule to meet your needs.
Click and drag to select range B5:B16.
In the Styles group, click the Conditional Formatting button.
The Conditional Formatting menu opens.
On the menu, click Manage Rules.
The Conditional Formatting Rules Manager dialog box opens. You can edit, create,
or delete a rule. Clicking Edit Rule edits the first rule, which is selected by default. If
several rules were listed, you would first select a rule to edit.
Click Edit Rule.
The Edit Formatting Rule dialog box opens where you can edit the rule type and
description. You can also see a preview of the conditional formatting that will be
applied.
In the Edit Formatting Rule dialog box, under Format only cells with, click the greater
than arrow.
A list of options appears.
Click less than.
Instead of formatting cells whose value is greater than $25,000, the new rule will
format cells whose value is less than 25,000.
Click OK.
The Edit Formatting Rule dialog box closes.
Click OK.
The Conditional Formatting Rules Manager closes. Excel applies the edited rule to
the range.
Excel's data validation feature reduces data entry errors and increases accuracy.
Even more useful, Excel can retroactively locate and circle cells with invalid data if a
data validation rule is created after data has already been entered.
Click the Data tab on the ribbon.
In the Data Tools group, click the Data Validation arrow.
The Data Validation menu opens.
On the menu, click Circle Invalid Data.
Excel circles the entries in cells D7 and D12, which contain the numbers 5 and 4.
Valid entries for the cells in column D are whole numbers from 1 through 3.
A macro lets you add functionality to your worksheet by automating a set of actions.
To allow for more than one outcome, you can insert a conditional statement into an
existing VBA macro by typing the statement into the open Visual Basic code window
for the macro.
At the insertion point, type If myValue = "User1" Then in the code window as a
single line of code.
You will code a conditional statement into the existing Update macro using
If…Then…Else terminology. The first line of code checks if the value entered in the
Input Box is "User1".
Press ENTER.
Type Range("B21").Value = "Authorized" in the code window as a single line of
code
If the Input Box value is User1, the macro will enter a value of "Authorized" into cell
B21.
Press ENTER.
Type Else in the code window
Next you will enter the Else part of the conditional statement, instructing the macro
what to do if the Input Box value is not User1.
Press ENTER.
Type Range("B21").Value = "Not Authorized" in the code window as a single line
of code.
If the Input Box value is not User1, the macro will enter a value of "Not Authorized"
into cell B21.
Press ENTER.
Type End If in the code window.
This concludes the conditional statement. You will now save the code and return to
the Excel window.
On the Visual Basic toolbar, click the Save Rockland Financials.xlsm button.
Excel saves the module with the added conditional statement.
On the Visual Basic toolbar, click the View Microsoft Excel button.
Excel returns to the worksheet window.
Clear conditional formatting rules that you no longer want to use in your worksheet.
Clearing the rule removes the conditional formatting from the cells.
Click and drag to select the range B4:B15.
If you want to clear the conditional formatting for a specific range, select the range
first.
In the Styles group, click the Conditional Formatting button.
The Conditional Formatting menu opens.
On the menu, click Clear Rules.
A submenu opens with options for clearing the conditional formatting rules from the
selected cells or from the entire worksheet.
Click Clear Rules from Selected Cells.
The conditional formatting is cleared from the range B4:B15, which applied a green
background colour to the top five values.