3
3
Although you can apply common number formats from the Ribbon, you may occasionally
want to create a custom number format to fit your needs. Custom formats can be
specified using the Custom category on the Number tab of the Format Cells dialog box.
Excel also provides options that allow you to populate cells using advanced Fill Series
options that include linear and growth series.
When typing new data in a workbook from a paper source—especially several records at
once—it’s easy for anyone to type the wrong digits or characters, especially in a field
where a single character denotes a type, such as a senior citizen or a child, or such as a
dog or a cat. Data validation helps to ensure that data gets entered correctly, before it
gets processed incorrectly.
Applying Custom Number Formats
In Excel, the same number can appear differently in a cell depending on its number
format. For example, 0.25, 1/4, and 6:00 A.M. are all the exact same number in Excel.
Changing the number format has the same impact on the cell’s value as changing its
color—none. In this section, we will look at some of the other things you can do with
number formatting.
You can use formatting controls on the Ribbon to quickly change your cells’ number
formats to the most commonly used formats. Now we’re going to explore custom number
formats. The first thing to understand when defining custom number formats is that Excel
allows four number formats in every cell, and they are separated with semicolons. The
basic structure is:
<Format for Positive Numbers> ; <Negative Numbers> ; <Zeroes> ; <Text>
The following table lists and describes the basic number formatting characters that can be
used in custom number formats.
Code Description
0 (zero) Digit placeholder. This means the number always displays, even
if it’s not significant. A format of 000.00 would display the
number 3.3 as 003.30
# Digit placeholder; doesn’t show insignificant zeroes. The #
symbol comes into play mostly when placing your thousands
separators. A format of #,##0.## would display the number 3.3
as 3.3
? The question mark is also a digit placeholder. It follows rules that
are similar to the # placeholder described above—if there’s a
non-zero number it will display the number, but it won’t display
a zero. However, unlike the # symbol, for a zero the ? will display
a space, not nothing. This means that if you use a format like
0.0?? Excel would align the numbers’ decimals vertically, three
digit-spaces from the right. The question mark also gets a lot of
use when formatting fractions.
. The period displays the decimal point in a number.
, The thousands separator. About the only time the decimal point
(.) and thousands separator (,) can get “interesting” is if you are
working with international workbooks and you have modified
the advanced options by deselecting the Use system separators
check box. If you do that, then Excel will update any custom
formats to use whichever separators you’ve indicated in your
advanced options.
% Displays the number as a percent—multiplies the number by 100
and places a
% symbol after it. Note that the value doesn’t change; 99% still
has a value of
1 de 11 14/04/2021, 14:31
OneNote https://euc-onenote.officeapps.live.com/o/onenoteframe.aspx?ui=pt-PT&...
2 de 11 14/04/2021, 14:31
OneNote https://euc-onenote.officeapps.live.com/o/onenoteframe.aspx?ui=pt-PT&...
s or ss Seconds as 0 – 60 or 00 – 60.
s.0 / s.00 / ss.0 / ss.00 Seconds as 0 – 60 or 00 – 60 but with one or two decimals of
precision.
am/pm or a/p The a.m. / p.m. indicators as one-letter or two.
[h] or [m] Elapsed time – hours will display above 24, minutes will display
above 60.
[Red] You can use the square brackets to specify a color for a section
[>500] of the number format specification. The color argument must
come first. Red for negative numbers is by far the most popular
use of the color argument. The other colors available are Black,
Blue, Cyan, Green, Magenta, White, and Yellow.
You can embed conditions into number formats. However you
are still limited to four overall number formats, which means that
you can specify two conditions before you are obliged to define
an “else” format and then a text format. Conditional formatting
is a much more robust and powerful way to handle this type of
format.
General This is the default number format. Numbers display as numbers
showing no thousands separator and as many decimals as
precision allows; text shows as text.
In certain cases, Excel will automatically change a cell’s number format based on how you
type the number in the cell. If you begin a cell entry with a dollar sign ($), Excel will
change the cell’s format to Currency. If you type a percent sign (%) after a number, Excel
will change the number format to a percentage, or a percentage with two decimal places
based on how many digits you typed. If you type 1/8 the cell will display the d-mmm date
format. If you type 1/1/1 the cell will display the d/m/yyyy date format. If you type 8 p the
cell reformats to the h:mm AM/PM time format.
Take Note You might be wondering “if we use ‘m’ for months and ‘m’ for minutes, and
both involve date/ time serial values, how does Excel know which to use?”. The answer is
“by context”. Simply put, whenever there’s an “m” in our number format, Excel checks for
an “h” before the “m” or an “s” after the “m.” If there is an “h” before the “m,” then Excel
interprets the “m” as minute; otherwise, Excel interprets the “m” as month.
3 de 11 14/04/2021, 14:31
OneNote https://euc-onenote.officeapps.live.com/o/onenoteframe.aspx?ui=pt-PT&...
Figure 2-1: Modifying a custom format in the Format Cells dialog box
4. Click OK. Use the Number tab in the Format Cells dialog box to set the number
formats in the ranges listed below, per the specification indicated. In all instances
you can directly select the Custom category and type in the number format.
However you can often “jump start” the process by using a predefined number
format first and then switching to the Custom category and making any final edits.
If available, a shortcut that will default to the desired format or get you close is
shown below the desired number format. After trying each shortcut, select the
Custom category to make sure you have the desired format and make any needed
edits there.
4 de 11 14/04/2021, 14:31
OneNote https://euc-onenote.officeapps.live.com/o/onenoteframe.aspx?ui=pt-PT&...
D29 #,##0.0,,,
D30 \B$ #,##0.00,,,
D31 $ #,##0.0,, “MM”
5. Compare your results with Figure 2-2 and make any necessary adjustments.
Figure 2-2: Custom number formats applied through row 31 of the Number
Formats worksheet
6. Continue applying the additional formats specified in the following table, using the
instructions from step 4.
5 de 11 14/04/2021, 14:31
OneNote https://euc-onenote.officeapps.live.com/o/onenoteframe.aspx?ui=pt-PT&...
Figure 2-3: The remaining custom number formats applied to the Number
Formats worksheet
10. SAVE the workbook.
PAUSE. LEAVE the workbook open to use in the next exercise.
Take Note Excel has a precision limitation of 15 significant digits. If you go beyond that,
Excel starts putting in zeroes for the least significant digits. This means that standard 16-
digit credit card numbers need to be stored as text. Do not try to format them as
numbers! You will not retain all of the data.
6 de 11 14/04/2021, 14:31
OneNote https://euc-onenote.officeapps.live.com/o/onenoteframe.aspx?ui=pt-PT&...
○ Hold down the Ctrl key as you drag the fill handle.
○ Double-click the fill handle, click the Auto Fill Options button at the bottom-
right corner of the filled range, and select the Fill Series option.
Use any of these three options to fill the range H4:H27 with numbers 1 through 24.
8. Select I4 and double-click the fill handle. Click the Auto Fill Options button and
select Fill Formatting Only.
9. Select J4 and double-click the fill handle. Notice that the default fill for a time value
is by the hour.
10. Select K4:K5 and double-click the fill handle. If you need to fill in times by any other
increment, you’ll need to start with two times.
11. Select L4:L27 (don’t drag the fill handle) and on the Home tab, in the Editing group,
click the Fill drop-down arrow and select Series. Change the Step value to 2.5
(Figure 2-4). Click OK.
12. Select M4:M27 and on the Home tab, in the Editing group, click the Fill drop-down
arrow and select Series. Change Type to Growth and the Step value to 2 and then
click OK.
13. Select N4:N27 and on the Home tab, in the Editing group, click the Fill drop-down
arrow and select Series. Leave Type as Linear, select the Trend check box, and then
click OK.
Figure 2-4: Using the Series dialog box to specify fill series options
14. Select O4:O27 and on the Home tab, in the Editing group, click the Fill drop-down
arrow and select Series. Change Type to Growth, select the Trend check box, and
then click OK.
Notice how changing the Type to Growth allows Excel to correctly figure out the
appropriate growth equation—the numbers in column O match the numbers in
column M.
15. For our first use of Flash Fill, using the data in P4:P12 we want to extract from the
first dash to just before the second dash. Select Q4, double-click the fill handle, click
the Auto Fill Options button, and select Flash Fill. Excel correctly fills the data.
Take Note Most Flash Fill examples tend to be pretty simple, but the algorithms
this feature uses can do some pretty good guesswork. However, these algorithms are
not quite infallible.
16. Now, we want to extract data from the first dash until two characters after the
second (using P4:P12). Select R4, double-click the fill handle, click the Auto Fill
Options button, and select Flash Fill. This time, Excel didn’t quite figure out what we
wanted. Instead it guessed that our rule was “first dash then five more characters”.
17. Select cell R6 and edit it to be -112-KN. (Use the F2 key and add an “N” to the
existing value in R6. Otherwise Excel will think you’re entering a formula.)
7 de 11 14/04/2021, 14:31
OneNote https://euc-onenote.officeapps.live.com/o/onenoteframe.aspx?ui=pt-PT&...
18. Select cells R7:R12 and press the Delete key to clear the remaining cells that were
flash-filled incorrectly the first time.
19. Now select R4:R6, double-click the fill handle, click the Auto Fill Options button,
and select Flash Fill. This time Excel is able to correctly figure out our rule.
20. Select S4:S7. Drag the fill handle over to column V. Auto Fill is able to appropriately
fill multiple rows simultaneously.
21. Select S10 and drag the fill handle down to row 27 (Auto Fill will stop with Feb.
17th). Then, from the Auto Fill Options button select Fill Months. Notice that Auto
Fill has guessed you wanted the last day of each month.
22. Select cell T11 and drag the fill handle down to T27. Click the Auto Fill Options
button and then select Fill Weekdays. Notice, our range has no Saturdays or
Sundays.
23. Select V11:V36. Click the File tab, click Options, select Advanced, and then scroll
almost to the bottom of the dialog box. Click the Edit Custom Lists button.
24. The Import list from cells control should already display the range $V$11:$V$36.
Click the Import button. A list starting with “Black, Blue, Brown, Chartreuse” should
appear in the Custom lists box (Figure 2-5). Click OK. Click OK in the Excel Options
dialog box.
8 de 11 14/04/2021, 14:31
OneNote https://euc-onenote.officeapps.live.com/o/onenoteframe.aspx?ui=pt-PT&...
Figure 2-6: Use the Settings tab to specify the data validation rule
10. Click the Input Message tab. This tab displays a message when you select a cell in
the validation range.
11. Click the Title box and type Rule:.
12. Click the Input message box and type Please enter the two-character state
abbreviation.
13. Click the Error Alert tab. Excel can display an error alert message when a user
attempts to enter data that is invalid.
14. Click the Title box and type Data Entry Error.
15. Click the Error message box and type Only two-character state abbreviations are
recognized. This message is displayed in a dialog box whenever an invalid entry is
made in column F.
16. Click OK.
17. To test the new validation rule, click cell F57. The notification message you typed
into the Input Message tab displays.
18. Type Ohio and press Enter. Excel displays an alert dialog box with the error message
you created (Figure 2-7).
Take Note Excel’s validation rules pertain only to new data that is entered into the
workbook, not to data that existed in the workbook prior to creating the rules.
9 de 11 14/04/2021, 14:31
OneNote https://euc-onenote.officeapps.live.com/o/onenoteframe.aspx?ui=pt-PT&...
Many databases includes fields that allow a specified number of valid entries, such as
political party affiliation or the work shift to which one is assigned. In data entry, it’s easy
for someone to slip and type an invalid entry. You can preempt events like this by building
a rule that restricts entry to a handful of valid entries.
10 de 11 14/04/2021, 14:31
OneNote https://euc-onenote.officeapps.live.com/o/onenoteframe.aspx?ui=pt-PT&...
22. After you attempt to enter Puppy into column B, respond to the error message by
clicking Cancel and by selecting Dog from the drop-down list.
23. After you attempt to enter 61 into column E, respond to the error message shown in
Figure 2-9 by clicking No and typing 31.
Take Note It’s still feasible for an invalid value to remain in a worksheet after the user
has been warned that it’s invalid. For example, in the previous steps if you were to click
Yes instead of No, the value 61 would remain in column E, even though there is no client
numbered 61 in column A of the Client List worksheet. Conceivably, this way you can
purposefully enter a new canine patient into the list without an owner, if you intend to
add the owner’s information later.
11 de 11 14/04/2021, 14:31