MICROSOFT® EXCEL® FUNCTIONS AND FORMULAS

SIXTH EDITION

LICENSE, DISCLAIMER OF LIABILITY, AND LIMITED WARRANTY

By purchasing or using this book (the “Work”), you agree that this license grants permission to use the contents contained herein, but does not give you the right of ownership to any of the textual content in the book or ownership to any of the information or products contained in it. This license does not permit uploading of the Work onto the Internet or on a network (of any kind) without the written consent of the Publisher. Duplication or dissemination of any text, code, simulations, images, etc. contained herein is limited to and subject to licensing terms for the respective products, and permission must be obtained from the Publisher or the owner of the content, etc., in order to reproduce or network any portion of the textual material (in any media) that is contained in the Work.

MERCURY LEARNING AND INFORMATION (“MLI” or “the Publisher”) and anyone involved in the creation, writing, or production of the companion disc, accompanying algorithms, code, or computer programs (“the software”), and any accompanying Web site or software of the Work, cannot and do not warrant the performance or results that might be obtained by using the contents of the Work. The author, developers, and the Publisher have used their best efforts to insure the accuracy and functionality of the textual material and/or programs contained in this package; we, however, make no warranty of any kind, express or implied, regarding the performance of these contents or programs. The Work is sold “as is” without warranty (except for defective materials used in manufacturing the book or due to faulty workmanship).

The author, developers, and the publisher of any accompanying content, and anyone involved in the composition, production, and manufacturing of this work will not be liable for damages of any kind arising out of the use of (or the inability to use) the algorithms, source code, computer programs, or textual material contained in this publication. This includes, but is not limited to, loss of revenue or profit, or other incidental, physical, or consequential damages arising out of the use of this Work.

The sole remedy in the event of a claim of any kind is expressly limited to replacement of the book, and only at the discretion of the Publisher. The use of “implied warranty” and certain “exclusions” vary from state to state, and might not apply to the purchaser of this product.

Companion files for this text are available for download by writing to the publisher at info@merclearning.com.

MICROSOFT® EXCEL® FUNCTIONS AND FORMULAS

With Excel 2021 / Microsoft 365

SIXTH EDITION

BRIAN MORIARTY
BERND HELD
THEODOR RICHARDSON

MERCURY LEARNING AND INFORMATION
Dulles, Virginia
Boston, Massachusetts
New Delhi

Copyright ©2022 by MERCURY LEARNING AND INFORMATION LLC. All rights reserved.

This publication, portions of it, or any accompanying software may not be reproduced in any way, stored in a retrieval system of any type, or transmitted by any means, media, electronic display or mechanical display, including, but not limited to, photocopy, recording, Internet postings, or scanning, without prior permission in writing from the publisher.

Publisher: David Pallai
MERCURY LEARNING AND INFORMATION
22841 Quicksilver Drive
Dulles, VA 20166
info@merclearning.com
www.merclearning.com
(800) 232-0223

B. Moriarty, B. Held, and T. Richardson. Microsoft® Excel® Functions and Formulas, Sixth Edition
ISBN: 978-1-683928-539

Microsoft, Excel, Visual Basic, and Windows are registered trademarks of Microsoft Corporation in the U.S. and other countries.

The publisher recognizes and respects all marks used by companies, manufacturers, and developers as a means to distinguish their products. All brand names and product names mentioned in this book are trademarks or service marks of their respective companies. Any omission or misuse (of any kind) of service marks or trademarks, etc. is not an attempt to infringe on the property of others.

Library of Congress Control Number: 2022935272

222324321 This book is printed on acid-free paper in the United States of America.

Our titles are available for adoption, license, or bulk purchase by institutions, corporations, etc. Digital versions of this title are available at www.academiccourseware.com and most digital vendors. Companion disc files are available for downloading by contacting info@merclearning.com. For additional information, please contact the Customer Service Dept. at (800) 232-0223 (toll free).

The sole obligation of MERCURY LEARNING AND INFORMATION to the purchaser is to replace the disc, based on defective materials or faulty workmanship, but not based on the operation or functionality of the product.

CONTENTS

Acknowledgments

Introduction

Chapter 1: Formulas in Excel

Calculate production per hour

Calculate the age of a person in days

Calculate a price reduction

Convert currency

Convert from hours to minutes

Determine fuel consumption

Calculate your ideal and recommended weights

The quick calendar

Design your own to-do list

Increment row numbers

Convert negative values to positive

Calculate sales taxes

Combine text and numbers

Combine text and date

Combine text and time

Generate a special ranking list

Determine average output

Determine stock gains and losses

Evaluate profitability

Determine percentage of completion

Convert miles per hour to kilometers per hour

Convert feet per minute to meters per second

Convert liters to barrels, gallons, quarts, and pints

Convert from Fahrenheit to Celsius

Convert from Celsius to Fahrenheit

Calculate total with percentage

Monitor the daily production plan

Calculate the number of hours between two dates

Determine the price per pound

Determine how many pieces to put in a box

Calculate the number of employees required for a project

Distribute sales

Calculate your net income

Calculate the percentage of price reduction

Divide and double every three hours

Calculate the average speed

Calculate number of characters in a string

Chapter 2: Logical Functions

Use the AND function to compare two columns

Use the AND function to show sales for a specific period of time

Use the OR function to check cells for text

Use the OR function to check cells for numbers

Use the XOR function to check for mutually exclusive conditions

Use the IF function to compare columns and return a specific result

Use the IF function to check for larger, equivalent, or smaller values

Combine IF with AND to check several conditions

Use the IF function to determine the quarter of a year

Use the IF function to check cells in worksheets and workbooks

Use the IF function to calculate with different tax rates

Use the IF function to calculate the commissions for individual sales

Use the IFS function to calculate the commissions for individual sales

Use the IF function to compare two cells

Use the IFS function to compare two cells

Use the SWITCH function to compare two cells

Use the INT function with the IF function

Use the TYPE function to check for invalid values

Use nested IF functions to cover multiple possibilities

Use IFS function to cover multiple possibilities

Use SWITCH function to cover multiple possibilities

Use the IF function to check whether a date is in the past or the future

Use the IF function to create your own timesheet

Use the IFERROR function to display a default

Chapter 3: Text Functions

Use the LEFT and RIGHT functions to separate a text string of numbers

Use the LEFT function to convert invalid numbers to valid numbers

Use the SEARCH function to separate first name from last name

Use the MID function to separate last name from first name

Use the MID function to sum the digits of a number

Use the EXACT function to compare two columns

Use the SUBSTITUTE function to substitute characters

Use the SUBSTITUTE function to substitute parts of a cell

Use the SUBSTITUTE function to convert numbers to words

Use the SUBSTITUTE function to remove word wrapping in cells

Use the SUBSTITUTE function to combine and separate columns

Use the REPLACE function to replace and calculate

Use the FIND function to combine text and date

Use the UPPER function to convert text from lowercase to uppercase

Use the LOWER function to convert text from uppercase to lowercase

Use the PROPER function to convert initial characters from lowercase to uppercase

Use the FIXED function to round and convert numbers to text

Use the TRIM function to delete spaces

Use the TRIM function to convert “text-numbers” to real numbers

Use the CLEAN function to remove all non-printable characters

Use the REPT function to show data in graphic mode

Use the REPT function to show data in a chart

Use the CHAR function to check your fonts

Use the CHAR function to determine special characters

Use the CODE function to determine the numeric code of a character

Use the UNICHAR function to determine the Unicode character from a number

Use the UNICODE function to determine the numeric Unicode value of a character

Use the DOLLAR function to convert numbers to currency in text format

Use the T function to check for valid numbers

Use the TEXT function to combine and format text

Use CONCATENATE function to combine text

Use CONCAT function to combine text

Use TEXTJOIN function to combine text

Use ARRAYTOTEXT function to combine text

Use VALUETOTEXT function to display text from any cell value

Chapter 4: Date and Time Functions

Use custom formatting to display the day of the week

Use the WEEKDAY function to determine the weekend

Use the TODAY function to check for future dates

Use the TEXT function to calculate with the TODAY function

Use the NOW function to show the current time

Use the NOW function to calculate time

Use the DATE function to combine columns with date parts

Use the LEFT, MID, and RIGHT functions to extract date parts

Use the TEXT function to extract date parts

Use the DATEVALUE function to recalculate dates formatted as text

Use the YEAR function to extract the year part of a date

Use the MONTH function to extract the month part of a date

Use the DAY function to extract the day part of a date

Use the MONTH and DAY functions to sort birthdays by month

Use the DATE function to add months to a date

Use the EOMONTH function to determine the last day of a month

Use the DAYS360 function to calculate with a 360-day year

Use the WEEKDAY function to calculate with different hourly pay rates

Use the WEEKNUM function to determine the week number

Use the EDATE function to calculate months

Use the WORKDAY function to calculate workdays

Use the NETWORKDAYS function to determine the number of workdays

Use the YEARFRAC function to calculate ages of employees

Use the DATEDIF function to calculate ages of employees

Use the WEEKDAY function to calculate the weeks of Advent

Use the TIMEVALUE function to convert text to time

Use a custom format to create a time format

Use the HOUR function to calculate with 100-minute hours

Use the TIME function to combine single time parts

Chapter 5: Basic Statistical Functions

Use the MAX function to determine the largest value in a range

Use the MIN function to discover the lowest sales volume for a month

Use the MINIFS function to discover the lowest sales volume for a month based on criteria

Use the MAXIFS function to discover the highest sales volume for a month based on criteria

Use the MIN function to detect the smallest value in a column

Use the SMALL function to find the smallest values in a list

Use the LARGE function to find the highest values

Use the INDEX, MATCH, and LARGE functions to determine and locate the best salesperson

Use the SMALL function to compare prices and select the cheapest offer

Use the AVERAGE function to calculate the average output

Use the SUBTOTAL function to sum a filtered list

Use the COUNT function to count cells containing numeric data

Use the COUNTA function to count cells containing data

Use the COUNTA function to count cells containing text

Use the COUNTBLANK function to count empty cells

Use the COUNTA function to determine the last filled row

Use the SUBTOTAL function to count rows in filtered lists

Use the RANK, RANK.EQ, RANK.AVG functions to determine the rank of sales

Use the MEDIAN function to calculate the median sales

Use the QUARTILE, QUARTILE.INC, QUARTILE.EXC functions to calculate quartiles

Use the STDEV, STDEV.S, STDEV.P functions to determine the standard deviation

Use the FORECAST.LINEAR function to determine future values

Use the FORECAST.ETS function to determine future values

Use the FORECAST.ETS.CONFINT function to determine confidence in future values

Use the FORECAST.ETS.SEASONALITY function to future value patterns

Use the CORREL function to determine data correlation

Use the AVERAGE, GEOMEAN, HARMEAN, TRIMMEAN to determine meaningful averages

Chapter 6: Mathematical Functions

Use the SUM function to sum a range

Use the SUM function to sum several ranges

Use the SUMIF function to determine sales of a team

Use the SUMIF function to sum costs higher than $1,000

Use the SUMIF function to sum costs up to a certain date

Use the COUNTIF function to count phases that cost more than $1,000

Use the COUNTIF function to calculate an attendance list

Use the SUMPRODUCT function to calculate the value of the inventory

Use the SUMPRODUCT function to sum sales of a team

Use the SUMPRODUCT function to multiply and sum at the same time

Use the ROUND function to round numbers

Use the ROUNDDOWN function to round numbers down

Use the ROUNDUP function to round numbers up

Use the ROUND function to round time values to whole minutes

Use the ROUND function to round time values to whole hours

Use the MROUND function to round prices to 5 or 25 cents

Use the MROUND function to round values to the nearest multiple of 10 or 50

Use the CEILING/CEILING.MATH functions to round up prices to the nearest $100

Use the FLOOR/FLOOR.MATH function to round down prices to the nearest $100

Use the PRODUCT function to multiply values

Use the PRODUCT function to multiply conditional values

Use the QUOTIENT function to return the integer portion of a division

Use the POWER function to calculate square and cube roots

Use the POWER function to calculate interest

Use the MOD function to extract the remainder of a division

Modify the MOD function for divisors larger than the number

Use the ROW function to mark every other row

Use the SUBTOTAL function to perform several operations

Use the SUBTOTAL function to count all visible rows in a filtered list

Use the RAND function to generate random values

Use the RANDBETWEEN function to generate random values in a specified range

Use the RANDARRAY function to generate random values in a range of rows and columns

Use the EVEN and ODD functions to determine the nearest even/odd value

Use the ISEVEN and ISODD functions to check if a number is even or odd

Use the ISODD and ROW functions to determine odd rows

Use the ISODD and COLUMN functions to determine odd columns

Use the ROMAN function to convert Arabic numerals to Roman numerals

Use the ARABIC function to convert Roman numerals to Arabic numerals

Use the BASE function to convert decimal numbers to binary numbers

Use the DECIMAL function to convert binary numbers to decimal numbers

Use the SIGN function to check for the sign of a number

Use the SUMSQ function to determine the square sum

Use the GCD function to determine the greatest common divisor

Use the LCM function to determine the least common multiple

Use the SUMIFS function to determine sales of a team and gender of its members

Use the COUNTIFS function to count phases that cost more than $1,000 within a certain duration

Compare the INT, TRUNC, and ROUND functions

Use the ABS function to return only positive differences between numbers

Use the SQRT function to determine the hypotenuse of a right triangle

Use the COMBIN function to determine the number of combinations in a lottery

Use the FACT function to determine the number of combinations in a lottery

Use the LET and IFS functions to determine sales bonuses

Use the SEQUENCE function to generate a sequential list of dates in a row, column, or an array

Chapter 7: Basic Financial Functions

Use the SYD function to calculate depreciation

Use the SLN function to calculate straight-line depreciation

Use the PV function to decide an amount to invest

Use the PV function to compare investments

Use the DDB function to calculate using the double-declining balance method

Use the PMT function to determine the payment of a loan

Use the FV function to calculate total savings account balance

Use the RATE function to calculate interest rate

Use the INTRATE function to calculate interest over an entire period

Use the NOMINAL function to calculate real interest rate given an annual rate

Chapter 8: Database Functions

Use the DCOUNT function to count special cells

Use the DCOUNT function to count cells in a range between x and y

Use the DCOUNTA function to count all cells beginning with the same character

Use the DGET function to search for a product by number

Use the DMAX function to find the most expensive product in a category

Use the DMIN function to find the least expensive product in a category

Use the DMIN function to find the oldest person on a team

Use the DSUM function to sum sales for a period

Use the DSUM function to sum all prices in a category that are above a particular level

Use the DAVERAGE function to determine the average price in a category

Chapter 9: Lookup and Reference Functions

Use the ADDRESS, MATCH, and MAX functions to find the position of the largest number

Use the ADDRESS, MATCH, and MIN functions to find the position of the smallest number

Use the ADDRESS, MATCH, and TODAY functions to sum sales up to today’s date

Use the XMATCH function to find who sold cookie boxes at or near the goal

Use the VLOOKUP function to look up and extract data from a database

Use the XLOOKUP function to return a row of information

Use the VLOOKUP function to compare offers from different suppliers

Use the HLOOKUP function to determine sales and costs for a team

Use the HLOOKUP function to determine sales for a particular day

Use the HLOOKUP function to generate a list for a specific month

Use the LOOKUP function to get the directory of a store

Use the LOOKUP function to get the indicator for the current temperature

Use the INDEX function to search for data in a sorted list

Use the INDIRECT function to play “Battleship”

Use the INDIRECT function to copy cell values from different worksheets

Use the INDEX function to determine the last number in a column

Use the INDEX and COUNTA functions to determine the last number in a row

Use the OFFSET function to sum sales for a specified period

Use the OFFSET function to consolidate sales for a day

Use the OFFSET function to filter every other column

Use the OFFSET function to filter every other row

Use the HYPERLINK function to jump directly to a cell inside the current worksheet

Use the HYPERLINK function to link to the Internet

Use the CHOOSE function to lookup values

Use the ROW and COLUMN functions to determine how many rows and columns are in a worksheet

Use the FORMULATEXT function to display a formula in a cell

Use the TRANSPOSE function to rearrange information on a worksheet

Use the FILTER function to filter data from a range

Use the SORT function to sort an existing range into another range

Use the SORTBY function to sort an existing range into another range

Use the UNIQUE function to return unique rows of data into another range

Chapter 10: Conditional Formatting with Formulas

Use the WEEKDAY function to determine weekends and shade them

Use the TODAY function to show completed sales

Use conditional formats to indicate unavailable products

Use the TODAY function to shade a specific column

Use the WEEKNUM and MOD functions to shade every other Tuesday

Use the MOD and ROW functions to shade every third row

Use the MOD and COLUMN functions to shade every third column

Use the MAX function to find the largest value

Use the LARGE function to find the three largest values

Use the MIN function to find the month with the worst performance

Use the MIN function to search for the lowest nonzero number

Use the COUNTIF function to mark duplicate input automatically

Use the COUNTIF function to check whether a number exists in a range

Use conditional formatting to control font styles in a specific range

Use a user-defined function to detect cells with formulas

Use a user-defined function to detect cells with valid numeric values

Use the EXACT function to perform a case-sensitive search

Use the SUBSTITUTE function to search for text

Use conditional formatting to shade project steps with missed deadlines

Use conditional formatting to create a Gantt chart in Excel

Use the OR function to indicate differences higher than 5% and lower than −5%

Use the CELL function to detect unlocked cells

Use the COUNTIF function to shade matching numbers in column B

Use the ISERROR function to mark errors

Use the DATEDIF function to determine all friends younger than 30

Use the MONTH and TODAY functions to find birthdays in the current month

Use conditional formatting to border summed rows

Use the LEFT function in a product search

Use the AND function to detect empty rows in a range

Use the COUNTIFS function to determine value based on multiple filters

Chapter 11: Working with Dynamic Array Formulas

Use the ADDRESS, MAX, and ROW functions to determine the last cell used

Use the INDEX, MAX, ISNUMBER, and ROW functions to find the last number in a column

Use the INDEX, MAX, ISNUMBER, and COLUMN functions to find the last number in a row

Use the MAX, IF, and COLUMN functions to determine the last column used in a range

Use the MIN and IF functions to find the lowest nonzero value in a range

Use the AVERAGE and IF functions to calculate the average of a range, taking zero values into consideration

Use the SUM and IF functions to sum values with several criteria

Use the INDEX and MATCH functions to search for a value that matches two criteria

Use the SUM function to count values that match two criteria

Use the SUM function to count values that match several criteria

Use the SUM function to count numbers from x to y

Use the SUM and DATEVALUE functions to count today’s sales of a specific product

Use the SUM function to count today’s sales of a specific product

Use the SUM, OFFSET, MAX, IF, and ROW functions to sum the last row in a dynamic list

Use the SUM, MID, and COLUMN functions to count specific characters in a range

Use the SUM, LEN, and SUBSTITUTE functions to count the occurrences of a specific word in a range

Use the SUM and LEN functions to count all digits in a range

Use the MAX, INDIRECT, and COUNT functions to determine the largest gain/loss of shares

Use the SUM and COUNTIF functions to count unique records in a list

Use the UNIQUE function to list unique records in a list

Use the AVERAGE and LARGE functions to calculate the average of the x largest numbers

Use the TRANSPOSE and OR functions to determine duplicate numbers in a list

Use the MID, MATCH, and ROW functions to extract numeric values from text

Use the MAX and COUNTIF functions to determine whether all numbers are unique

Use the TRANSPOSE function to copy a range from vertical to horizontal or vice versa

Use the FREQUENCY function to calculate the number of products sold for each group

Use the FILTER function to determine wins for a specific division

Use the SORT function to list an existing table of data by a certain column

Use the SORTBY function to list an existing table of data by a certain column

Use the RANDARRAY function to return a list of random numbers across any number of rows and columns

Use the SEQUENCE function to return a list of a sequence of numbers across any number of rows and columns

Chapter 12: Special Solutions with Formulas

Use the COUNTIF function to prevent duplicate input through validation

Use the EXACT function to allow only uppercase characters

Use data validation to allow data input by a specific criterion

Use data validation to limit data to a specific list

Use controls with formulas

Use Goal Seek as a powerful analysis tool

Use a custom function to shade all cells containing formulas

Use a custom function to change all formulas in cells to values

Use a custom function to document and display all cells containing formulas

Use a custom function to delete external links in a worksheet

Use a custom function to delete external links in a workbook

Use a custom function to enter all formulas into an additional worksheet

Chapter 13: User-Defined Functions

Use a user-defined function to copy the name of a worksheet into a cell

Use a user-defined function to copy the name of a workbook into a cell

Use a user-defined function to get the path of a workbook

Use a user-defined function to get the full name of a workbook

Use a user-defined function to determine the current user of Windows or Excel

Use a user-defined function to display formulas of a specific cell

Use a user-defined function to check whether a cell contains a formula

Use a user-defined function to check whether a cell contains data validation

Use a user-defined function to find all comments

Use a user-defined function to sum all shaded cells

Use a user-defined function to sum all cells with a colored font

Use a user-defined function to delete leading zeros for specified cells

Use a user-defined function to delete all letters in specified cells

Use a user-defined function to delete all numbers in specified cells

Use a user-defined function to determine the position of the first number

Use a user-defined function to calculate the cross sum of a cell

Use a user-defined function to sum each cell’s cross sum in a range

Use a user-defined function to check whether a worksheet is empty

Use a user-defined function to check whether a worksheet is protected

Use a user-defined function to create your own AutoText

Chapter 14: Examples

Calculate average fuel consumption

Calculate net and corresponding gross prices

Determine the economic value of a product

Calculate the final price of a product, taking into account rebates and price reductions

Search for data that meets specific criteria

Separate cities from zip codes

Eliminate specific characters

Combine text, dates, and timestamps

Determine the last day of a month

Determine the number of available workdays

Determine a person’s exact age

Determine the number of values in a specific range

Determine the weekly sales for each department

Round a value to the nearest 5 cents

Determining inventory value

Determine the top salesperson for a month

Determine the three highest values in a list

Determine amount to invest

Determine how many items are in various categories

Find a specific value in a complex list

Dynamically show costs and sales per day

Extract every fourth value from a list

Display names in a list or in an array

Filter for certain job positions

Display the mile time for a runner

Create a list of random telephone numbers

Create a list of sequential Friday dates

Sort a list of names

Sort a list of names to include all their data

List unique data based on names and city

Retrieve student’s math and history scores

Retrieve student’s total score

Chapter 15: Other Features

Insert Icons

Draw Freestyle

Smart Lookup

Share Files

Flash Fill

Quick Analysis Tool

Map Chart

Funnel Chart

Data Types – Stocks

Data Types – Geography

View workbook objects using the navigation pane

Review workbook statistics

Smooth scrolling when cells cross over viewable pages

Unhiding multiple worksheets at once

Resizing the conditional formatting window

Duplicating a conditional formatting rule

Chapter 16: Data Analytics Using Excel

Activate “Analysis ToolPak”

Display a Histogram to view the frequency of Sales

Display many statistics describing a data set

Reveal how numbers correlate to each other

Smooth a natural progression of numbers

Determine a moving average for a data set

Create a list of random numbers

Rank a list of clients obtained in a month

Determine an accurate house price

Select four random customers to receive a prize

Chapter 17: Shortcut Keys

Go to cells or highlight cell ranges

Other Common Shortcuts

Appendix: Excel Interface Guide

Anatomy of Excel

Microsoft 365 vs 2021

Microsoft Excel 2021

Microsoft Excel 2021 for Macintosh

Microsoft Excel Web App

Index

ACKNOWLEDGMENTS

I appreciate the patience and understanding my wonderful wife and adorable daughter inured while I diverted time from them to express my knowledge of Excel to you.

I would also like to thank the dedicated individuals at Mercury Learning and Information who labored in producing this book for their indefatigable work and generous commitment to quality, informational books.

INTRODUCTION

Microsoft Excel is the well-known standard spreadsheet application that allows you to easily perform calculations and recalculations of data by using numerous built-in functions and formulas. Although you may be familiar with simple functions such as SUM, this is just one of the many Excel functions and formulas that can help you simplify the process of entering calculations. Because there are so many other useful and versatile functions and formulas inside Excel that most users have yet to discover, this book was written to help readers uncover and use its wide range of tools.

For each function or formula, we started with a simple task that can be solved with Excel in an efficient way. We added tips and tricks and additional features as well to provide deeper knowledge and orientation. After you have stepped through all the lessons, you will have a great toolbox to assist you with your projects and make many everyday workbook tasks much easier. The most notable changes from Excel 2019 to 2021 (and Microsoft 365) are additional functions. We added 11 functions to this edition – there are more but only included the more common functions. Some of these functions are array formulas that can provide multiple calculations dynamically displayed in multiple rows and columns. In other words, one formula in one cell can provide a table of information. This edition also includes previous features such as Stock and Geography data types along with widely used formulas that have been around since 2016 such as IFERROR, COUNTIFS, CHOOSE, and COLUMN. Some functions that are not available in 2021 but are available with a Microsoft 365 subscription are noted throughout the book.

The content of the book is as follows:

Chapter 1 describes practical tasks that can be solved by using formulas.

In Chapter 2, you learn the usage of logical functions that are often used in combination with other functions.

Chapter 3 shows how text functions are used. You will often need these functions when working with text in tables or if the text needs to be changed or adapted, especially when it is imported into Excel from other applications.

In Chapter 4, you learn about the date and time functions in Excel. Times and dates are automatically converted inside Excel to the number format, which makes it easier to perform calculations.

With Chapter 5, you delve into the secrets of working with statistics in Excel.

Chapter 6 describes the most commonly used functions for mathematics and trigonometry, along with easy-to-follow tasks. The most common function here is the SUM function, with which you may already be familiar. However, you may be surprised about the additional possibilities shown.

If you want to learn more about functions for financial mathematics, study Chapter 7. Here you will find examples of how to calculate depreciation of an asset and how long it takes to pay back a loan using different interest rates.

With Chapter 8, you get into the secrets of database functions. There are a variety of functions explained that can be used for evaluation of data, especially when using different criteria.

Chapter 9 is about lookup and reference functions inside Excel. With these functions, you can address data in various ranges and look up values in a reference.

Chapter 10 goes into the depth of conditional formatting. Even though this feature has been available since Excel 97, there are new features that allow you to express information without programming.

Chapter 11 introduces dynamic array formulas. The way that Excel now manages arrays is vastly different than how it has managed them in previous versions. There is less work on your part compared with legacy array formulas requiring ‘Ctrl+Shift+Enter’ (CSE). With these you learn how to perform multiple calculations and then return either a single result or multiple results.

Chapter 12 shows special solutions with formulas, such as creating a function to color all cells containing formulas inside an Excel spreadsheet.

Chapter 13 goes even deeper into user-defined functions with examples that use Visual Basic for Applications (VBA) inside Excel. This chapter will show you how to solve problems even when Excel cannot calculate an answer.

With Chapter 14, we present some examples of tasks that combine several functions shown in the previous chapters. Use these to get more experience. Read the description of the task first and try to determine the functions that are needed to get the desired result. Compare your solution to the one shown beneath the task.

Chapter 15 details a few features that will enhance how you develop, test, and present the Excel products you create for efficiency.

Chapter 16 provides functions pertaining to data analytics. This chapter displays rudimentary examples of how to report on and select from data.

Chapter 17 guides you through some of the more common shortcut keys. These save time and allow you to get around Excel with less keystrokes.

Appendix A provides an overview of the current versions of Excel. This includes Excel 2021 for Windows, the primary version used for the images and examples in the text. The interface for Macintosh is also covered; the appearance of this version is different, but it can perform the same calculations. The Excel Web App available as part of the Microsoft OneDrive and Microsoft 365 is also demonstrated in this appendix; it has limited functionality compared with the complete installations, but it still has significant capacity for performing calculations.

Have fun reading the book and exploring the many useful functions, formulas, and features you will discover here.

CHAPTER 1

FORMULAS IN EXCEL

CALCULATE PRODUCTION PER HOUR

Data for some employees is recorded in a worksheet. They work a varied number of hours each day to produce clocks. By calculating the number of pieces each employee produces per hour, it can be determined who is the most productive employee.

To see who the most productive employee is:

1. In a worksheet, enter your own data or the data shown in Figure 1–1.

2. Select cells D2:D7.

3. Enter the following formula: =C2/(B2∗24).

4. Press <Ctrl+Enter> to fill the selected cell range with the current entry.

5. From the toolbar select Home and go to Number.

6. Click the dropdown arrow and select Format Cells.

7. Select the Number tab and then select Number from the Category list.

8. Set Decimal places to 2.

9. Click OK.

Beckham is the most productive. He produces an average of just below 22 clocks per hour.

FIGURE 1–1

CALCULATE THE AGE OF A PERSON IN DAYS

A worksheet lists the names of friends in column A and their birth dates in column B. To calculate the number of days each person has been alive, enter the current date in cell B1 and perform the following steps:

To calculate the age of a person in days:

1. In a worksheet, enter your own data or the data shown in Figure 1–2.

2. Select cells C5:C9.

3. Enter the following formula: =$B$1-B5.

4. Press <Ctrl+Enter>.

5. From the toolbar select Home and go to Number.

6. Click the dropdown arrow and select Format Cells.

7. Select the Number tab and then select General from the Category list.

8. Click OK.

FIGURE 1–2

NOTE

The formula must have an absolute reference to cell B1, which is available by going to the formula bar, highlighting the cell reference, and pressing F4 until the appropriate reference appears or you can enter a “$” before the “B” and the “1.” This tells excel not to change either the “B” or the “1” when copying the formula to another cell.

CALCULATE A PRICE REDUCTION

All prices in a price list need to be reduced by a certain percentage. The amount of the price reduction is 15%; this is entered in cell C1.

To reduce all prices by a certain percentage:

1. In a worksheet, enter your own data or the data shown in Figure 1–3.

2. Select cell C1 and type −15%.

3. Select cells C4:C8.

4. Enter the following formula: =B4+(B4∗$C$1).

5. Press <Ctrl+Enter>.

FIGURE 1–3

NOTE

Please note that the formula must have an absolute reference to cell C1. Also, columns B and C are formatted with the Currency style, which is available by clicking on the $ button in the Home ribbon toolbar.

CONVERT CURRENCY

In a worksheet, currency need to be converted from dollars (column B) to euros (column C). The rate of exchange from dollars to euros is placed in cell C1; here we use 0.747.

To convert currency:

1. In a worksheet, enter your own data or the data shown in Figure 1–4.

2. Select cells C4:C8.

3. Enter the following formula: =B4∗$C$1.

4. Press <Ctrl+Enter>.

5. Press <Ctrl+1> to show the dialog Format Cells.

6. Select the Number tab and then select Currency from the Category list.

7. Choose the required € Euro format.

8. Click OK.

FIGURE 1–4

NOTE

To convert euros back to dollars, use the following formula: =C4/$C$1.

CONVERT FROM HOURS TO MINUTES

As a task, time in a timesheet needs to be converted from hours to minutes.

To convert time to minutes:

1. In a worksheet, enter your own data or the data shown in Figure 1–5.

2. Select cells B4:B8.

3. Enter the following formula: =A4∗24∗60.

4. Press <Ctrl+Enter>.

5. Format cells B4:B8 as general by pressing <Ctrl+1> and then selecting the Number tab and then General from the Category list.

6. Click OK.

FIGURE 1–5

NOTE

To convert a minutes format to an hours-and-minutes format, use the formula =B4/24/60. Remember to format the cells with a time format, as shown in cell C4 in Figure 1–5.

DETERMINE FUEL CONSUMPTION

In a worksheet, fuel consumption data is recorded. Each time you refill your gas tank, record the following data: date, miles traveled, and gallons purchased. Then reset the mileage counter. To calculate the fuel consumption of your vehicle, perform the following steps:

To determine fuel consumption:

1. In a worksheet, enter your own data or the data shown in Figure 1–6.

2. Select cells D5:D10.

3. Enter the following formula: =B5/C5.

4. Press <Ctrl+Enter>.

FIGURE 1–6

CALCULATE YOUR IDEAL AND RECOMMENDED WEIGHTS

Formulas for calculating ideal body weight first came into existence in 1871, when a French surgeon, Dr. P. P. Broca, created this formula (known as Broca’s index):

Weight (in kg) should equal height (in cm) − 100, plus or minus 15% for women or 10% for men

In recent years, the body mass index (BMI) has become the standard for calculating ideal weight.

To determine ideal and recommended weights:

1. In a worksheet, enter your own data or the data shown in Figure 1–7.

2. Select cell B5 and type the following formula to determine your ideal weight (BMI = body mass index): =(B3-100)∗0.9.

3. Select cell B7 and type the following formula to calculate your recommended weight: =B4-100.

4. Calculate the total difference in cells D6 and D7 by simple subtraction.

5. Calculate the difference in percentage in cells E6 (=1-B4/B5) and E7 (=1-B4/B6).

6. Press <Ctrl+Enter> to show the dialog Format Cells.

7. Select the Number tab and then select Percentage from the Category list.

8. Set Decimal places to 2 and click OK.

FIGURE 1–7

THE QUICK CALENDAR

To create a simple calendar, use the Fill command in combination with a formula.

To create a quick calendar:

1. Select cell A1 and type the following formula: =TODAY().

2. Select cell A2 and type the following formula: =A1+1.

3. Select cells B1:G1.

4. From the Edit menu, select Fill and Right.

5. In cell A2, type =A1.

6. Drag the bottom-right corner of cell A2 with the mouse cursor rightward through cell F2.

7. Press <Ctrl+1> to show the dialog Format Cells.

8. Select Custom under Category.

9. Enter the custom format ddd and press OK.

FIGURE 1–8

DESIGN YOUR OWN TO-DO LIST

Generate your own to-do list by entering the hours of the day in column A and making space for your daily tasks in column B.

To generate your own to-do list:

1. Select cell B1 and type =TODAY().

2. Select cell A3 and type 7:00 a.m.

3. Select cell A4 and type the following formula in the Formula Bar: =A3+(1/24).

4. Select cells A4:A13.

5. Go to the Editing group and choose the boxed downward arrow.

6. Click on Down.

FIGURE 1–9

NOTE

To get increments of half an hour, use the formula =A3+(1/48). To display the time in column A as shown in Figure 1–9, select Cells from the Home tab, click the Number group, select Time from the Category list, select 1:30 p.m., and click OK.

INCREMENT ROW NUMBERS

Standard row numbering in Excel is often used, but you can also create your own numbering system in a table, such as incrementing by 10 as described below.

To increment row numbers by 10:

1. Select cell A2 and type 0.

2. Select cell A3 and type the following formula: =A2+10.

3. Select cells A3:A12.

4. Select Editing from the ribbon, choose the downward button, and select Down.

FIGURE 1–10

NOTE

If the value of cell A2 is changed, the values in all the other cells change, too.

CONVERT NEGATIVE VALUES TO POSITIVE

A worksheet contains negative values. To convert all the negative values to positive values, perform the following steps.

To convert negative values to positive values:

1. Enter a series of negative values in cells B1:B10.

2. Select cell C1 and type -1.

3. Copy this cell.

4. Select cells B1:B10.

5. In the Home tab, in the Clipboard group, click Paste, and then click Paste Special.

6. In the Paste Special dialog box, under Paste, select Multiply.

7. Click OK.

FIGURE 1–11

NOTE

After this, C1 can be cleared.

CALCULATE SALES TAXES

In this exercise, tax on an item needs to be calculated. We can also find the original price, given the tax rate and the final price.

To calculate the price with tax:

1. Select cell A2 and type 8%.

2. Select cell B2 and type 120.

3. Select cell C2 and type the following formula: =B2+(B2∗A2).

To calculate the original price:

1. Select cell A4 and type 8%.

2. Select cell C4 and type 129.60.

3. Select cell B4 and type the following formula: =C4/(1+A4).

FIGURE 1–12

COMBINE TEXT AND NUMBERS

In this example, we want to combine text and numbers. Use the & operator to accomplish this.

To combine cells containing text and numbers:

1. Select cell B1 and type computers.

2. Select cell B2 and type 5.

3. Select cell B4 and type the following formula in the Formula Bar: ="You ordered " & B2 & " " & B1 & " today!".

FIGURE 1–13

NOTE

Each cell reference must be placed between & operators, and additional text must be surrounded by quotation marks.

COMBINE TEXT AND DATE

Excel has a problem combining cells that contain text and dates. This results in the date’s showing up as a number value, because Excel has lost the format. To get the desired result, use the following workaround.

To combine text and date:

1. Select cell A1 and type actual status.

2. Select cell D1 and type the following formula: =TODAY().

3. Select cell A3 and type the following formula: =A1& " " &TEXT(D1,"MM/DD/YYYY").

FIGURE 1–14

COMBINE TEXT AND TIME

This example shows how to combine text and time successfully.

To combine text and time:

1. Select cell A1 and type Shutdown.

2. Select cell D1 and press <Ctrl+Shift+:> to insert the current time.

3. Select cell A3 and type the following formula: =" Today " & A1 & " at " & TEXT(D1,"hh:mm").

FIGURE 1–15

GENERATE A SPECIAL RANKING LIST

You can use Excel to generate a special ranking list. Let us say a worksheet contains a few values, some of which are repeated. To rank the list in a particular order, follow these instructions.

To rank a list in a particular order:

1. Select cell A1 and type Value.

2. In cells A2:A12 enter a selection of values from 10 to 20.

3. Select cell A2.

4. In the Home tab, click on the AZ icon in the Editing group.

5. Select Sort Smallest to Largest.

6. Select cell B1 and type Rank.

7. Select cell B2 and type 1.

8. Select cells B3:B12 and type the following formula: =B2+(A2<A3).

9. Press <Ctrl+Enter>.

FIGURE 1–16

DETERMINE AVERAGE OUTPUT

In a worksheet, the start and end production dates of a machine’s operation are given, as well as its output during this period. How do you calculate the average daily production?

To calculate the average daily production:

1. Select cell B1 and type 10/18/2004.

2. Select cell B2 and type 11/13/2002.

3. Type 55900 in cell B3.

4. Select cell B5 and type the following formula: =B3/(B1-B2).

FIGURE 1–17

DETERMINE STOCK GAINS AND LOSSES

Imagine your stocks have fallen 11.5% in value in one day. What is the percentage of gain that will be needed the next day to compensate for the loss?

To determine the gain/loss of a stock:

1. Select cell C2 and type 1000.

2. Select cell B3 and type 11.50%.

FIGURE 1–18

3. Select cell C3 and type the following formula: =C2-(C2∗$B$3).

4. Select cell B4 and type the following formula: =B3/(1-B3).

5. Select cell C4 and type the following formula: =C3+(C3∗$B$4).

6. Be sure to format column C as Currency.

EVALUATE PROFITABILITY

You have some products for sale, and you want to know which one is the most profitable. Use conditional formatting for this purpose.

To determine the most profitable product:

1. In a new worksheet, type the cost of each product in column B and the corresponding price in column C.

2. Select cells D2:D6 and type the following formula: =1-(B2/C2).

3. Press <Ctrl+Enter>.

4. In the Home tab, in the Styles group, click the arrow next to Conditional Formatting.

5. Select New Rule and select the options shown to highlight the top 1 value.

6. Click Format, select the Fill tab, choose a color, and click OK.

FIGURE 1–19

FIGURE 1–20

NOTE

Product pr04 has the greatest profit margin as calculated in column D. The conditional formatting highlights the cell automatically.

DETERMINE PERCENTAGE OF COMPLETION

To manage a project, it is necessary to determine the percentage of completion. This can be accomplished with the following calculation.

To calculate percentage of completion:

1. In a worksheet, enter data in columns A, B, and D as shown in Figure 1–21.

2. Select cell E2 and type =B2+B3.

3. Select cell E3 and enter the target value of 200.

4. In cell E5, type the formula =E3-E2 to get the difference between the target and the number already produced.

5. Calculate the percentage of missing products in cell E6 with this formula: =1-E2/E3.

6. Select cell E8 and calculate the percentage of production by using this formula: =100%-E6.

FIGURE 1–21

CONVERT MILES PER HOUR TO KILOMETERS PER HOUR

A worksheet contains speed in miles per hour. To convert the data to kilometers per hour, use the following calculation.

To convert miles per hour to kilometers per hour:

1. In a worksheet, enter the data shown or use data of your own creation in Figure 1–22.

2. Select cell D1 and enter the conversion value 0.621371.

3. Select cells B2:B8 and type the following formula: =A2/$D$1.

4. Press <Ctrl+Enter>.

FIGURE 1–22

NOTE

To convert the other way around, from kilometers per hour to miles per hour, use the formula =B2∗$D$1.

CONVERT FEET PER MINUTE TO METERS PER SECOND

A worksheet contains speed data. To convert feet per minute to meters per second, use the calculation described as follows.

To convert feet per minute to meters per second:

1. In a worksheet, enter the data shown in Figure 1–22, or use your own data.

2. Select cell D1 and enter the conversion value 196.858144.

3. Select cells B2:B10 and type the following formula: =A2/$D$1.

4. Press <Ctrl+Enter>.

FIGURE 1–23

NOTE

To convert the other way around, from meters per second to feet per minute, use the formula =B2∗$D$1.

CONVERT LITERS TO BARRELS, GALLONS, QUARTS, AND PINTS

In a worksheet, data is input as liters. To convert the value to different scales, use the following formulas.

To convert liters to barrels, gallons, quarts, and pints:

1. Select cell B1 and enter 150.

2. Select cell B3 and type the formula =$B$1/158.98722 to convert to barrels.

3. Select cell B4 and type the formula =$B$1/3.78541 to convert to gallons.

4. Select cell B5 and type the formula =$B$1/1.101241 to convert to quarts.

5. Select cell B6 and type the formula =$B$1/0.5506 to convert to pints.

FIGURE 1–24

CONVERT FROM FAHRENHEIT TO CELSIUS

To convert temperatures from Fahrenheit to Celsius, you can use the formula =(Fahrenheit–32)∗5/9, or you can use the calculation described here.

To convert from Fahrenheit to Celsius:

1. In a worksheet, enter some temperatures in Fahrenheit in column A.

2. Select cells B2:B13 and type the following formula: =(A2-32)∗(5/9).

3. Press <Ctrl+Enter>.

FIGURE 1–25

CONVERT FROM CELSIUS TO FAHRENHEIT

To convert temperatures from Celsius to Fahrenheit, you can use the formula =(Celsius ∗9/5)+32, or you can use the calculation described here.

FIGURE 1–26

To convert from Celsius to Fahrenheit:

1. In a worksheet, enter some temperatures in Celsius in column A.

2. Select cells B2:B13 and type the following formula: =(A2∗9/5)+32.

3. Press <Ctrl+Enter>.

CALCULATE TOTAL WITH PERCENTAGE

Let us say you want to buy a new car. The listed price of the car is $25,500, and the tax to be added is 8%. After negotiation of a sales discount of 10%, the final price needs to be calculated.

To calculate the final price:

1. Select cell B1 and enter 25500.

2. Select cell B2 to enter the tax rate of 8%.

3. Select cell B3 and enter the discount rate of 10%.

4. Select cell B5 and type the following formula: =B1∗(1+B2)∗(1-B3).

FIGURE 1–27

NOTE

The formula =B1∗(1–B3)∗(1+B2) also works for this example, as shown in the result in C5. The order of multiplication does not matter.

MONITOR THE DAILY PRODUCTION PLAN

A worksheet is used to monitor daily production. The target is defined as 1,500 pieces per day. To calculate the percentage of the daily goal produced, perform the following steps.

To monitor daily production:

1. Select cell B1 and enter the predefined target: 1500.

2. Select cells C4:C11 and type the following formula: =B4/$B$1.

3. Press <Ctrl+Enter>.

4. In the Home tab, go to the Number group and click on the % sign.

5. In the same group, click the button, “Increase Decimal,” twice. That way you set decimal places to 2.

FIGURE 1–28

CALCULATE THE NUMBER OF HOURS BETWEEN TWO DATES

Excel has a problem calculating the difference between two dates in hours. You can verify this by opening a new worksheet and typing the starting date including time (3/20/2010 1:42 p.m.) in cell A2. In cell B2, type the end date and time (3/24/2010 7:42 a.m.). Then subtract A2 from B2 in cell C2. The calculation generates 1/3/1900 6:00 p.m., which is incorrect. If the result is displayed as #####, you’ll need to extend the width of column C. Cells A2 and B2 need to be formatted as follows by selecting the expansion icon for the Numbers panel:

FIGURE 1–29

To properly format the difference in hours:

1. Select cell C2.

2. In the Home tab, go to the Number group and click on the expansion icon at the lower right.

3. In the Number tab, click on Custom from Category.

4. Type the custom format [h]:mm.

5. Click OK. This gives the correct answer.

FIGURE 1–30

DETERMINE THE PRICE PER POUND

A worksheet lists food products in column A. Column B shows the corresponding weight in pounds, and column C contains the total price. What is the price per pound?

To calculate the price per pound:

1. In a workshop, enter the data shown in Figure 1–31, or use your own data.

2. Select cells D2:D8.

3. Type the following formula: =C2/B2.

4. Press <Ctrl+Enter>.

FIGURE 1–31

DETERMINE HOW MANY PIECES TO PUT IN A BOX

Let us say a container can hold 10 boxes and each box can hold up to 300 items. The customer requires a total of 500 items. How many items must be packed in each box, given a number of boxes?

To determine the number of pieces in each box:

1. Select cell A2 and enter 10.

2. Select cell B2 and enter 50.

3. Select cell D2 and type =B2∗A2.

4. In cells A4:A7 enter the number of boxes from 2 to 9.

5. Select cells B4:B7 and type the following formula: =$B$2∗($A$2/A4).

6. Press <Ctrl+Enter>.

7. Select cells D4:D7 and type the formula =B4∗A4.

8. Press <Ctrl+Enter>.

FIGURE 1–32

NOTE

Some entries in column A may result in a number with a decimal point in column B. These will require additional calculations on your part to determine exactly how many pieces fit in the given number of boxes so that the customer receives exactly 500 whole pieces.

CALCULATE THE NUMBER OF EMPLOYEES REQUIRED FOR A PROJECT

The number of employees needed for a project needs to be calculated. To do this, enter the available time (14 days) for the project in cell A2. Cell B2 contains the number of working hours per day (8.5). Cell C2 shows the current number of employees (5). Now we can calculate how many employees are needed to reduce the project’s duration or change the number of daily working hours of the employees.

To calculate the desired number of employees:

1. Enter different combinations of desired days in column A and daily working hours in column B.

2. Select cell E2 and insert the formula =A2∗B2∗C2 to calculate the total working hours of the project.

3. Select cells C4:C9 and type the following formula: =ROUNDUP(C$2∗A$2∗B$2/(A4∗B4),0).

4. Press <Ctrl+Enter>.

5. Select cells E4:E9 and type the following formula: =A4∗B4∗C4.

6. Press <Ctrl+Enter>.

FIGURE 1–33

DISTRIBUTE SALES

In a company, each sale is assigned to a salesperson. The sale of 30 pieces totals $199,000. Each salesperson sold an individual amount of goods. Calculate the corresponding sales for each person.

To calculate the total amount of sales for each employee:

1. Select cell B1 and enter the total amount of sales: $199000.

2. Select cell B2 and enter the total number of sold goods: 30.

3. In columns A and B, enter the names of the salespeople and the number of pieces they sold.

4. Select cells C5:C10 and type the following formula: =B5∗$B$1/$B$2.

5. Press <Ctrl+Enter>.

FIGURE 1–34

NOTE

Check out the AutoSum of the selected range in the status bar.

CALCULATE YOUR NET INCOME

People often talk about their gross income. To calculate net income, it is necessary to consider the tax percentage, using the following calculation.

To calculate net income:

1. Select cell B1 and enter the tax as a percentage: 33%.

2. In cell B2, enter the gross income: $3500.

3. Select cell B3 and type the formula =B2∗B1 to calculate the tax amount.

4. Determine the net income in cell B4 with the formula =B2-B3.

FIGURE 1–35

NOTE

The amounts in cells B1 and B2 can be changed.

CALCULATE THE PERCENTAGE OF PRICE REDUCTION

A digital camera is on sale. The camera’s original price is $250, but it is now available for $131. What is the percentage of the reduction?

To calculate the price reduction as a percentage:

1. Select cell B2 and enter the original price: $250.

2. In cell B3, enter the sales price: $131.

3. Calculate the absolute difference in cell B4 with the formula =B2-B3.

4. Determine the percentage of price reduction in cell B5 using the following formula: =B4/B2.

5. Go to the Number group in the Home tab and select Percentage in the uppermost category.

FIGURE 1–36

DIVIDE AND DOUBLE EVERY THREE HOURS

In an experiment, bacteria divide and double every three hours. How many bacteria will there be at the end of one day (24 hours) given a starting number?

To calculate the total amount of bacteria after 24 hours:

1. Enter values from 1 to 4 in cells B2:B8.

2. Select cells C2:C8 and type the following formula: =A2^(24/B2).

3. Press <Ctrl+Enter>.

4. Press Ctrl+1 and select the Number tab and Number in Category.

5. Set Decimal Places to 0, tick the Use 1000 Separator check box.

6. Click OK.

FIGURE 1–37

NOTE

To insert the ^ character, press the <^> key on the keyboard followed by a <Space>.

CALCULATE THE AVERAGE SPEED

In this example, someone travels from New York to Los Angeles with an average speed of 90 miles per hour. On the way back, the average speed is 75 miles per hour. What is the overall average speed?

To calculate the average speed, the speed in each direction needs to be taken into consideration.

To calculate the overall average speed:

1. In cell C2, enter 90.

2. In cell C3, enter 75.

3. In cell C4, type the following formula: =(C2+C3)/2.

FIGURE 1–38

CALCULATE NUMBER OF CHARACTERS IN A STRING

In this example, we need to calculate the number of characters in a string, or the number of phrases separated by a delimiter. In this example, we are going to use the function SUBSTITUTE.

To determine the number of characters in a string, simply determine the difference between what the length of the string is and what the length of the string is after you remove the characters for which you are trying to determine the count. In this example, the phrase listed in cell B5 is 44 characters long including the spaces using the LEN function. After we remove the spaces using the SUBSTITUTE function in cell D5, the length of the string is down to 35. The difference, 9, is the number of spaces in the string.

You can perform the same logic for any character (or phrase) you wish. You can determine the number of other characters in the string by replacing the space within the SUBSTITUTE function in cell D5 with any other character you wish. Row 6 contains the same logic to determine how many lower-case a’s are contained within the same sentence.

1. In cell C5, type the formula: =LEN(B5).

2. In cell D5, type the formula: =LEN(SUBSTITUTE (B5," ",""))

3. In cell F5, type the formula: =C5-D5

4. In cell G5, type the formula: =LEN(B5)-LEN(SUBSTITUTE(B5," ",""))

NOTE

Step 4 displays how to combine the previous 3 steps into one cell.

You can also use the SUBSTITUTE function to determine the number of phrases separated by any delimiter. In this example, we have a list of names separated by semi-colons. How many names are in the list? The difference between this example and the previous example is that we assuming that there is one more of the item we are counting; therefore, we must add 1 to our answer. The length of the original string displays in cell B8. After using the SUBSTITUTE function in cell D8 and applying the LEN function to it in cell C8, we determine that there are four semi-colons. We further assume that the last name is not followed by a semi-colon, so we add one to our final formula in cell E8. If cell B8 had ended with a semi-colon without any other names following it, then we would not include the ‘+1’ in the F8 formula.

1. In cell C8, type the formula: =LEN(B8).

2. In cell D8, type the formula: =SUBSTITUTE (B8,";","")

3. In cell F8, type the formula: =C8-D8+1

4. In cell G8, type the formula: =LEN(B8)-LEN(SUBSTITUTE(B8,";",""))+1

FIGURE 1–39

NOTE

Step 4 displays how to combine the previous 3 steps into one cell.

CHAPTER 2

LOGICAL FUNCTIONS

USE THE AND FUNCTION TO COMPARE TWO COLUMNS

Two columns in a worksheet need to be evaluated. If the value in column A is greater than 20 and the value in column B is greater than 25, both values are valid.

To compare two columns:

1. In cells A2:A10, enter values from 1 to 100.

2. In cells B2:B10, enter values from 1 to 100.

3. Select cells C2:C10 and type the following formula: =AND(A2>20,B2>25).

4. Press <Ctrl+Enter>.

FIGURE 2–1

NOTE

If both criteria are valid, Excel shows the value as TRUE; otherwise, it is FALSE.

USE THE AND FUNCTION TO SHOW SALES FOR A SPECIFIC PERIOD OF TIME

This example checks all rows for a specific time period using the AND function. The function returns TRUE if all the arguments are TRUE and FALSE if one or more arguments are FALSE.

NOTE

Up to 30 conditions can be used in one formula.

To show sales in a period of time:

1. Select cell B1 and enter the start date.

2. Select cell B2 and enter the end date.

3. The range A5:A16 contains dates ranging from 09/11/2009 to 09/22/2009.

4. The range B5:B16 contains sales amounts.

5. Select cells C5:C16 and type the following formula: =AND(A5>B$1,A5<=$B$2).

6. Press <Ctrl+Enter>.

FIGURE 2–2

USE THE OR FUNCTION TO CHECK CELLS FOR TEXT

A worksheet contains several words in column A. Each row has to be checked for the words “new” or “actual” in column A. The OR function is used for this task. The function returns TRUE if either argument is true and FALSE if both arguments are not true.

NOTE

Up to 30 conditions can be used in one formula.

To use the OR function to check for two or more criteria:

1. Enter in range A2:A10 words like “new,” “actual,” and “old.”

2. Select cells B2:B10 and type the following formula: =OR(A2="New",A2="actual").

3. Press <Ctrl+Enter>.

FIGURE 2–3

USE THE OR FUNCTION TO CHECK CELLS FOR NUMBERS

A worksheet contains several values in column A. Each row has to be evaluated based on certain the specific value in column A. The OR function is used for this task. The function returns TRUE if any argument is TRUE and FALSE if all arguments are FALSE.

NOTE

Up to 30 conditions can be used in one formula.

To check for two or more criteria:

1. Enter in range A2:A12 values from –43 to 100.

2. Select cells B2:B12 and type the following formula: =OR(A2=1,A2>=99,A2<0).

3. Press <Ctrl+Enter>.

FIGURE 2–4

USE THE XOR FUNCTION TO CHECK FOR MUTUALLY EXCLUSIVE CONDITIONS

A worksheet contains several values in column A and another set of values in column B. The columns must contain in the same row one number above 900 but not both. The XOR function is used for this task. The function returns TRUE if only one argument is TRUE, FALSE if both arguments are TRUE, and FALSE if all arguments are FALSE.

To check for the specified criteria:

1. Enter in range A2:A12 values from 0 to 1,000.

2. Enter in range B2:B12 values from 0 to 1,000.

3. Select cells C2:C12 and type the following formula: =XOR(A2>=900,B2>=900).

4. Press <Ctrl+Enter>.

FIGURE 2–5

USE THE IF FUNCTION TO COMPARE COLUMNS AND RETURN A SPECIFIC RESULT

As shown in earlier examples, Excel returns the value TRUE or FALSE when using the OR and AND functions. The IF function can also be used to conduct conditional tests on values and formulas.

This example compares two columns and shows the result in column C.

To return specific text after comparing values:

1. Enter in range A2:A12 values from 0 to 1,000.

2. Enter in range B2:B12 values from 0 to 1,000.

3. Select cells C2:C12 and type the following formula: =IF(A2>=B2,"Column A is greater or equal", "Column B is greater").

4. Press <Ctrl+Enter>.

FIGURE 2–6

USE THE IF FUNCTION TO CHECK FOR LARGER, EQUIVALENT, OR SMALLER VALUES

In the previous example, two different messages were used as the result for comparing values. To check for three conditions in column A and present the result as “Column A is larger,” “equal,” or “Column A is smaller,” perform the following steps.

To compare columns and show the result:

1. Copy the previous example.

2. Select cells C2:C12 and type the following formula: =IF(A2>B2,"Column A is larger", IF(A2=B2,"Equal", "Column A is smaller")).

3. Press <Ctrl+Enter>.

FIGURE 2–7

NOTE

Up to seven IF functions can be combined in one cell. To combine more than seven functions, use the customized solution near the end of this chapter.

COMBINE IF WITH AND TO CHECK SEVERAL CONDITIONS

In this example, Excel evaluates which condition meets the criteria and returns the result in the same row.

To combine the IF and functions:

1. Copy the content of cells C2:C5 in Figure 2–8 to your Excel table.

2. Frame the table as shown in the screenshot.

3. Select cell A2 and enter any kind of sales value, e.g., 120.

4. In cell B2, type the following formula: =IF(AND($A$2<=100,$A$2),"Sales value is","").

5. In cell B3, type the following formula: =IF(AND ($A$2>100,$A$2<=150),"Sales value is","").

6. In cell B4, type the following formula: =IF(AND ($A$2>150,$A$2<=200),"Sales value is","").

7. In cell B5, type the following formula: =IF($A$2>200,"Sales value is","").

FIGURE 2–8

USE THE IF FUNCTION TO DETERMINE THE QUARTER OF A YEAR

After entering an initial value, Excel can automatically fill worksheet cells with the names of weekdays or months. Open a new worksheet and type the word “January” in cell A2. Then drag the lower-right point of this cell down to A13 to let Excel create a list containing the months of the year. In this example, we want to indicate which months fall into which quarter.

To determine the quarter of a year in which a particular month falls:

1. Select cells B2:B13 and type the following formula: =IF(OR(A2="January",A2="February",A2="March"),"1st quarter", IF(OR(A2="April",A2="May",A2="June"),"2nd quarter", IF(OR(A2="July",A2="August",A2="September"),"3rd quarter","4th quarter"))).

2. Press <Ctrl+Enter>.

FIGURE 2–9

USE THE IF FUNCTION TO CHECK CELLS IN WORKSHEETS AND WORKBOOKS

To use an IF statement not only in a worksheet but also in a linked worksheet or workbook, start typing part of the formula, for example, “=IF(,” then navigate to another worksheet or open up a workbook, select the desired cell, and go back to the first worksheet to finish the formula.

To use the IF function to check out cells in another worksheet: Type =IF(Sheet8!A2"january","wrong","OK").

To use the IF function to check out cells in another workbook: Type =IF('C:\Held\Formulas\Files\[Formulas.xls] Sheet35'!$A$1<>1,"wrong","OK").

NOTE

For this to work, the referenced worksheets or workbooks must exist. This functionality can be checked by changing the name of the worksheet or the file reference.

USE THE IF FUNCTION TO CALCULATE WITH DIFFERENT TAX RATES

If at least two sales tax rates exist, you can use the IF function to calculate each one individually. Simply combine several IF functions, depending on the calculation.

To calculate the price after tax:

1. In column A, enter some prices.

2. In column B, enter different tax percentages (0, 8, and 10 for this example).

3. Select cells C2:C10 and type the following formula: =IF(B2=8,A2/100*8,IF(B2=10,A2/100*10,A2/100*0)).

4. Press <Ctrl+Enter>.

5. Select cells D2:D10 and type the formula =A2+C2.

6. Press <Ctrl+Enter>.

FIGURE 2–10

USE THE IF FUNCTION TO CALCULATE THE COMMISSIONS FOR INDIVIDUAL SALES

A company has a policy for individual commissions depending on sales, as shown below:

Sale < $100

3%

Sale >= $100 and < $500

5%

Sale >= $500

8%

To calculate the commissions:

1. Enter different sales amounts in column A.

2. Select cells B2:B12 and type the following formula: =A2*IF(A2>=500,0.08,IF(A2>=100,0.05,0.03)).

3. Press <Ctrl+Enter>.

FIGURE 2–11

USE THE IFS FUNCTION TO CALCULATE THE COMMISSIONS FOR INDIVIDUAL SALES

A company has a policy for individual commissions depending on sales, as shown below:

Sale < $100

3%

Sale >= $100 and < $500

5%

Sale >= $500

8%

To calculate the commissions:

1. Enter different sales amounts in column A.

2. Select cells E2:E12 and type the following formula: =A2*IFS(A2<100,0.03,A2<500,0.05,TRUE,0.08)

3. Press <Ctrl+Enter>.

FIGURE 2–12

USE THE IF FUNCTION TO COMPARE TWO CELLS

The following tip is a solution for comparing two cells line by line. Prepare a new worksheet, filling the first two columns with the values 0 and 1 as shown in Figure 2–13.

To compare cells line by line:

1. Select cells C2:C11 and type the following formula: =IF(A2&B2="11","OK",IF(A2&B2="10","First Value is OK",IF(A2&B2="01","Second Value is OK","Both Values are FALSE"))).

2. Press <Ctrl+Enter>.

FIGURE 2–13

USE THE IFS FUNCTION TO COMPARE TWO CELLS

The following tip is a solution for comparing two cells line by line. Prepare a new worksheet, filling the first two columns with the values 0 and 1 as shown in Figure 2–14.

To compare cells line by line:

1. Select cells D2:D11 and type the following formula: =IFS(A2&B2="11","OK",A2&B2="10","First Value is OK",A2&B2="01","Second Value is OK",TRUE,"Both Values are FALSE")

2. Press <Ctrl+Enter>.

FIGURE 2–14

USE THE SWITCH FUNCTION TO COMPARE TWO CELLS

The following tip is a solution for comparing two cells line by line. Prepare a new worksheet, filling the first two columns with the values 0 and 1 as shown in Figure 2–15.

To compare cells line by line:

1. Select cells E2:E11 and type the following formula: =SWITCH(A2&B2,"10","First Value is OK","01","Second Value is OK","11","OK","00","Both Values are FALSE")

2. Press <Ctrl+Enter>.

FIGURE 2–15

USE THE INT FUNCTION WITH THE IF FUNCTION

To see if one value is a whole number and can be evenly divided by another value, use the IF function in combination with the INT function.

To see if a whole number can be evenly divided by 4:

1. Select cells B2:B10 and type the following formula: =IF(INT(A2/4)=A2/4,"whole number divisible by 4",FALSE).

2. Press <Ctrl+Enter>.

Alternately:

1. Select cells C2:C10 and type the following formula: =IF(A2/4-INT(A2/4)=0,"whole number divisible by 4", FALSE).

2. Press <Ctrl+Enter>.

FIGURE 2–16

USE THE TYPE FUNCTION TO CHECK FOR INVALID VALUES

Sometimes Excel cannot interpret some values, especially imported data. As an example, let us say a cell contains an apparent value but the calculation leads to an incorrect result. To prevent this, use the IF function in combination with TYPE to check for invalid data in the worksheet. This example would enter the text “invalid value” in column B if the value entered in column A is not numeric.

To show invalid values in a worksheet:

1. Enter some values or text in column A.

2. Select cells B2:B11 and type the following formula: =IF(AND(TYPE(A2)=1,A2<>""),A2,"invalid value").

3. Press <Ctrl+Enter>.

FIGURE 2–17

USE NESTED IF FUNCTIONS TO COVER MULTIPLE POSSIBILITIES

There are several methods to provide multiple results or calculations based upon a cell value. Here is one method using the basic IF function.

To insert multiple conditions:

1. Select cell A2 and enter 12.

2. Select cell B2 and type the following formula: =IF(A2=1,A2,IF(A2=2,A2*2,IF(A2=3,A2*3,IF(A2=4,A2*4, IF(A2=5,A2*5,IF(A2=6,A2*6,IF(A2=7,A2*7,IF(A2=8,A2*8, IF(A2=9, A2*9,IF(A2=10,A2*10,IF(A2=11,A2*11,IF(A2=12,A2*12,))))))))))))

3. Press <Enter>.

FIGURE 2–18

USE IFS FUNCTION TO COVER MULTIPLE POSSIBILITIES

Another method to get the same result as the last example is new to Excel 2016. Here is one method using the IFS function.

To insert multiple conditions:

1. Select cell A2 and enter 12.

2. Select cell C2 and type the following formula: =IFS(A2=1,A2,A2=2,A2*2,A2=3,A2*3,A2=4,A2*4,A2=5,A2*5,A2=6,A2*6,A2=7,A2*7,A2=8,A2*8,A2=9,A2*9,A2=10,A2*10,A2=11,A2*11,A2=12,A2*12)

3. Press <Enter>.

FIGURE 2–19

USE SWITCH FUNCTION TO COVER MULTIPLE POSSIBILITIES

Another method to get the same result as the last two examples is new to Excel 2016. Here is one method using the SWITCH function.

To insert multiple conditions:

1. Select cell A2 and enter 12.

2. Select cell D2 and type the following formula: =A2*SWITCH(A2,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12)

3. Press <Enter>.

FIGURE 2–20

USE THE IF FUNCTION TO CHECK WHETHER A DATE IS IN THE PAST OR THE FUTURE

In this example, we want to check whether a particular date is in the past or the future. To do so, the TODAY() function is used with IF to compare dates with the actual date and show its result.

To compare dates—variant A:

1. Select cells B2:B16 and type the following formula: =IF(NOT(A2>TODAY()),"Past", "Future").

2. Press <Ctrl+Enter>.

To compare dates—variant B:

1. Select cells C2:C16 and type the following formula: =IF(A2>=TODAY(),IF(A2=TODAY(),"Today", "Future"),"Past").

2. Press <Ctrl+Enter>.

FIGURE 2–21

USE THE IF FUNCTION TO CREATE YOUR OWN TIMESHEET

In this last example we create our own timesheet, step by step. First, press <Shift+F11> to insert a new worksheet. Then create the following timesheet as an example:

We need to consider that the daily target of eight hours is still fulfilled when an employee is ill (IL), on holiday (HO), or in training (TR). For other days, the number of working hours must be calculated.

FIGURE 2–22

To calculate the daily working hours:

1. Select cell F2:F6 and type the following formula: =IF(OR(C2="TR",C2="IL",C2="HO"),E2,D2-C2).

2. Press <Ctrl+Enter>.

FIGURE 2–23

USE THE IFERROR FUNCTION TO DISPLAY A DEFAULT

Sometimes when we use a formula referencing other cells, the cells contain invalid data. There are a few different approaches to tackling this issue. The best way is to fix the data by using data validation to ensure correct data is entered. But even when this is accomplished, the formula used on it can still produce an error for a variety of other reasons. You can change the format of the cell to not display the error, or you can use the IFERROR function to display either nothing or a phrase that is more useful to the user. In the first example, using the FIND function we are looking for a space within the phrase “HelloToMe” in cell B3; since there is not a space, the FIND function returns an error. But if we wrap that function inside the IFERROR function, we have the opportunity to display something other than “#VALUE”. In this example, we display a message letting the user know that there are no spaces in the phrase.

1. In cell D3, type the formula: =FIND(" ",B3)

2. In cell E3, type the formula: =IFERROR(FIND(" ",B3),"There are no spaces in cell B3").

In the second example, we have a formula that divides by zero and we wish to display a more meaningful message than just '#DIV/0!' In this case, we display the message that is more descriptive.

1. In cell D4, type the formula: =B4/C4

2. In cell E3, type the formula: =IFERROR(B4/C4,"Cell C4 is zero − cannot divide by zero").

FIGURE 2–24

CHAPTER 3

TEXT FUNCTIONS

USE THE LEFT AND RIGHT FUNCTIONS TO SEPARATE A TEXT STRING OF NUMBERS

A worksheet contains a list of 10-digit numbers that need to be separated into two parts: a three-digit part and a seven-digit part. Use the LEFT and RIGHT functions to do this. The LEFT function returns the first character or characters in a text string, based on the number of characters specified. The RIGHT function returns the last character or characters in a text string based on the number of characters specified.

To separate a text string of numbers:

1. In a worksheet, enter a series of 10-character numbers in cells A2:A10. The numbers can also contain letters.

2. Select cells B2:B10 and type the following formula: =LEFT(A2,3).

3. Press <Ctrl+Enter>.

4. Select cells C2:C10 and type the following formula: =RIGHT(A2,7).

5. Press <Ctrl+Enter>.

FIGURE 3–1

USE THE LEFT FUNCTION TO CONVERT INVALID NUMBERS TO VALID NUMBERS

In this example, invalid numbers need to be converted to valid numbers. The invalid numbers contain a minus sign at the right end of the text. Excel cannot interpret this, so the minus sign in the text needs to be moved to the left of the numbers. First, check the length of each number with the LEN function. This function returns the number of characters in a text string. Then use the LEFT function to move the minus sign.

LEN(text)

text: The text whose length you want to be determined. A space is considered a character.

To cut off the last character and display a negative value:

1. In a worksheet, enter a series of numbers in cells A2:A10 that have a minus sign at the end.

2. Select cells B2:B10 and type the following formula: =-LEFT(A2,LEN(A2)-1).

3. Press <Ctrl+Enter>.

FIGURE 3–2

USE THE SEARCH FUNCTION TO SEPARATE FIRST NAME FROM LAST NAME

This task demonstrates how to separate first and last names. In a worksheet, full names are listed in column A. We want to copy the first name to column B. The SEARCH function can be used to determine the space between the parts of the text string. This function returns the position of the searched character inside a text string:

SEARCH(find_text, within_text, start_num)

find_text: The text or character for which you are searching. Wildcard characters, question marks (?), and asterisks (*) can be used in find_text. A question mark matches any single character, and an asterisk matches any sequence of characters. To find a question mark or asterisk, type a tilde (~) before the character.

within_text: The text within which you want to search for find_text.

start_num: The start position for the search function within the text; if there is no start_num defined inside the function, Excel sets it to 1.

To separate the first and last names:

1. In a worksheet, enter a series of full names in cells A2:A10.

2. Select cells B2:B11 and type the following formula: =LEFT(A2,SEARCH(" ",A2)-1).

3. Press <Ctrl+Enter>.

FIGURE 3–3

USE THE MID FUNCTION TO SEPARATE LAST NAME FROM FIRST NAME

In a worksheet, names are listed in column A, and the last name needs to be copied to column B. As in the previous example, the space between the first and last names needs to be determined with the SEARCH function. This function returns the position of the desired character inside a text string starting from start_num. The MID function then returns a specific number of characters starting from a desired position inside a text string.

MID(text, start_num, num_chars)

text: Text string containing the desired characters.

start_num: Position of the first character to extract from the text.

num_chars: Number of characters to be extracted.

To separate the last name from the first name:

1. In a worksheet, enter a series of full names in cells A2:A10.

2. Select cells B2:B11 and type the following formula: =MID(A2,SEARCH(" ",A2)+1,100).

3. Press <Ctrl+Enter>.

FIGURE 3–4

USE THE MID FUNCTION TO SUM THE DIGITS OF A NUMBER

A worksheet contains four-digit numbers in column A. The four digits in each number need to be added together and the result shown in column B. To do so, the four digits of a cell are extracted by the MID function and summed.

To determine the cross sum (the sum of digits in a number):

1. In a worksheet, enter a series of four-digit numbers in cells A2:A10.

2. Select cells B2:B10 and type the following formula: =MID(A2,1,1)+MID(A2,2,1)+MID(A2,3,1)+MID(A2,4,1).

3. Press <Ctrl+Enter>.

FIGURE 3–5

USE THE EXACT FUNCTION TO COMPARE TWO COLUMNS

There are two ways to compare two columns. With the IF function, it does not matter if the text is written in upper or lower case. The EXACT function, on the other hand, can distinguish between upper and lower case.

EXACT(text1, text2)

text1: The first text string.

text2: The second text string.

To compare two columns:

1. In a worksheet, copy columns A and B from Figure 3–6.

2. Select cells C2:C8 and type the following formula: =EXACT(A2,B2).

3. Press <Ctrl+Enter>.

4. Select cells D2:D8 and type the following formula: =IF(A2=B2,TRUE,FALSE).

5. Press <Ctrl+Enter>.

FIGURE 3–6

NOTE

Differences in formatting do not matter. Both functions will still work, as shown in cells A6 and B6; B6 contains the same underlying numeric value of the date in A6. Extraneous blanks in cells, as shown in row 7, also do not matter.

USE THE SUBSTITUTE FUNCTION TO SUBSTITUTE CHARACTERS

A worksheet contains values in column A that are formatted as text in Excel 2016. These can still be summed because the format does not affect the content. How would these values work if converted to just text? Use the SUBSTITUTE formula to replace specific characters in text or in a cell.

SUBSTITUTE(text, old_text, new_text, instance_num)

text: The text or the reference to a cell containing text in which characters are to be substituted.

old_text: Text that should be replaced.

new_text: Text that replaces old_text.

instance_num: Specifies which instance of old_text is to be replaced by new_text. If omitted, every instance of old_text is replaced.

To use SUBSTITUTE and force Excel to calculate:

1. Format column A as text.

2. Enter a series of numbers in cells A2:A10. Notice that Excel tags them with green triangles in the upper-left corner to indicate the numbers have been entered as text.

3. Select cells B2:B10 and type the following formula: = SUBSTITUTE(A2,"","")).

4. Press <Ctrl+Enter>.

5. Select cell A12, type the following formula: =SUM(A2:A10), and press <Enter>.

6. Select cell B12, type the following formula: =SUM(B2:B10), and press <Enter>.

FIGURE 3–7

USE THE SUBSTITUTE FUNCTION TO SUBSTITUTE PARTS OF A CELL

In this example, the "-" character needs to be deleted. But only the first occurrence of this character should be deleted. To do this, type any kind of text and numbers in column A, as shown in the following screenshot, using the "-" character in different positions and in a variety of occurrences.

To substitute parts of a cell:

1. Select cells B2:B9 and type the following formula: =SUBSTITUTE(A2,"-","",1).

2. Press <Ctrl+Enter>.

FIGURE 3–8

NOTE

If you want to substitute the second occurrence of this character, use the following formula: =SUBSTITUTE(A2,"-","",2).

USE THE SUBSTITUTE FUNCTION TO CONVERT NUMBERS TO WORDS

A worksheet contains the numbers 1 to 5 in column A. Use the SUBSTITUTE function to change each number to a word. That is, change 1 to one, 2 to two, 3 to three, 4 to four, and 5 to five.

To convert each number to a word:

1. In column A, type a series of numbers using 1, 2, 3, 4, and 5.

2. Select cells B2:B10 and type the following formula: =(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A2,1,"one-"),2,"two-"),3,"three-"),4,"four-"),5,"five-")).

3. Press <Ctrl+Enter>.

FIGURE 3–9

USE THE SUBSTITUTE FUNCTION TO REMOVE WORD WRAPPING IN CELLS

To wrap text in a cell, you can select cells from the Home tab, select the Alignment group, and click the Wrap Text icon. Another way to do this is to type text into the first row of a cell, then press <Alt+Enter>, type text into the next row, and continue as desired.

If you want to disable word wrap, the SUBSTITUTE and CHAR functions can be used together. CHAR returns the character specified by a number. The ASCII character numerical equivalent for word wrap is 10.

To delete word-wrap:

1. In cells A2 and A3 type text with word wraps.

2. Select cells B2:B3 and type the following formula: =SUBSTITUTE(A2,CHAR(10)," ").

3. Press <Ctrl+Enter>.

FIGURE 3–10

USE THE SUBSTITUTE FUNCTION TO COMBINE AND SEPARATE COLUMNS

The & operator is used to combine several columns into one column. To include a separator between parts in addition to blank spaces, you can specify the separator just once while using the SUBSTITUTE function as follows.

To combine and separate at the same time:

1. In columns A through D, type any kind of data.

2. Select cells E2:E9 and type the following formula: =SUBSTITUTE(A2&" "&B2&" "&C2&" "&D2," "," - ").

3. Press <Ctrl+Enter>.

FIGURE 3–11

USE THE REPLACE FUNCTION TO REPLACE AND CALCULATE

The following worksheet contains an employee’s work hours.

FIGURE 3–12

The format of columns B and C cannot be used to calculate time. Note that the triangle in the upper-left corner indicates the numbers have been entered as text. Rather than a period, a colon needs to be placed between the numbers to indicate time. Therefore, the period needs to be replaced using the REPLACE function in combination with SEARCH. The REPLACE function replaces part of a text string with a different text string, based on the number of characters specified. The syntax for the SEARCH function was provided earlier in this chapter.

REPLACE(old_text, start_num, num_chars, new_text)

old_text: Original text in which some characters are to be replaced.

start_num: Position of the character in old_text that is to be replaced with new_text.

num_chars: Number of characters in old_text to be replaced.

new_text: Text that will replace characters in old_text.

To replace periods with colons and calculate:

1. In a worksheet, copy the data shown in Figure 3–13.

2. Select cells D2:D10 and type the following formula: =(REPLACE(C2,SEARCH(".",C2),1,":")-REPLACE(B2,SEARCH(".",B2),1,":")).

3. Press <Ctrl+Enter>.

FIGURE 3–13

USE THE FIND FUNCTION TO COMBINE TEXT AND DATE

The following worksheet contains daily tasks in column A and their corresponding dates in column B. The task here is to combine the data and change the format of the dates. Take a closer look at the following screenshot:

FIGURE 3–14

The text string XXX needs to be replaced by the dates in column B. To do this, the starting position of the text string needs to be determined by using the FIND function. The REPLACE function will replace the XXX text string with the date. The string must be present for this to work, and capitalization matters.

FIND(find_text, within_text, start_num)

find_text: Text to find. Wildcard characters are not allowed.

within_text: Text containing find_text.

start_num: Specifies the first character in the search. If omitted, Excel sets start_num to 1.

To combine and format data at the same time:

1. In a worksheet, copy the data shown in Figure 3–15.

2. Select cells C2:C6 and type the following formula: =REPLACE(A2,FIND("XXX",A2,1),3,TEXT(B2,"MM-DD-YYYY")).

3. Press <Ctrl+Enter>.

FIGURE 3–15

USE THE UPPER FUNCTION TO CONVERT TEXT FROM LOWERCASE TO UPPERCASE

The UPPER function is used to convert a text string to all uppercase letters. This function has the following syntax:

UPPER(text)

text: Text to be converted to all uppercase letters. The text can be either a reference or a text string.

To convert a text string to uppercase:

1. In cells A2:A8, type any text in lowercase letters.

2. Select cells B2:B8 and type the following formula: =UPPER(A2).

3. Press <Ctrl+Enter>.

FIGURE 3–16

USE THE LOWER FUNCTION TO CONVERT TEXT FROM UPPERCASE TO LOWERCASE

To convert all letters to lowercase in a text string, use the LOWER function. This function has the following syntax:

LOWER(text)

text: Text to be converted to all lowercase letters. The text can be either a reference or a text string.

To convert a text string to lowercase:

1. In cells A2:A8, type any text in uppercase letters.

2. Select cells B2:B8 and type the following formula: =LOWER(A2).

3. Press <Ctrl+Enter>.

FIGURE 3–17

USE THE PROPER FUNCTION TO CONVERT INITIAL CHARACTERS FROM LOWERCASE TO UPPERCASE

To convert the first letter in each word to uppercase and all other letters to lowercase, the PROPER function is used. This function capitalizes the first letter in a text string and any letters that follow characters other than a letter (such as a space). All other letters will be changed to lowercase.

This function has the following syntax:

PROPER(text)

text: Text enclosed in quotation marks, a formula that returns text, or a reference to a cell that contains the text that should have initial capital letters.

To convert a text string to proper case:

1. In cells A2:A6 type any kind of text using different capitalization patterns.

2. Select cells B2:B6 and type the following formula: =PROPER(A2).

3. Press <Ctrl+Enter>.

FIGURE 3–18

USE THE FIXED FUNCTION TO ROUND AND CONVERT NUMBERS TO TEXT

To round numbers and return the result as text, use the FIXED function. This function rounds a number to the specified number of decimals, returning the result as text with or without commas.

FIXED(number, decimals, no_commas)

number: The number to round and convert to text.

decimals: The number of digits to the right of the decimal point. If omitted, Excel sets it to 2.

no_commas: A logical value that prevents FIXED from including commas when set to TRUE. If no_commas is FALSE or omitted, the returned text includes commas.

To round and convert numbers to text:

1. In cells A2:A10, type values with decimals.

2. Select cells B2:B10 and type the following formula: =FIXED(A2,-1,FALSE).

3. Press <Ctrl+Enter>.

4. Select cells C2:C10 and type the following formula: =FIXED(A2,-2,FALSE).

5. Press <Ctrl+Enter>.

FIGURE 3–19

USE THE TRIM FUNCTION TO DELETE SPACES

Column A of a worksheet contains text with spaces at the left and right side of the text or between words. This could be a problem if, for example, data is used for evaluation and when cells are compared with other cells. Use the TRIM function to remove all spaces from a text string except for the single spaces between words.

To delete unneeded spaces from text:

1. In cells A2:A5, type text with leading and trailing spaces.

2. Select cells B2:B5 and type the following formula: =TRIM(A2).

3. Press <Ctrl+Enter>.

FIGURE 3–20

USE THE TRIM FUNCTION TO CONVERT “TEXT-NUMBERS” TO REAL NUMBERS

In this example, numbers entered as text need to be converted to values. To do this, use the VALUE and TRIM functions in combination to get the correct result. The VALUE function converts a text string that represents a number to a number, and the TRIM function deletes all leading and trailing spaces.

To convert text that represents a number to a value:

1. Format column A as text.

2. In cells A2:A10, type a series of numbers with trailing spaces.

3. Select cells B2:B10 and type the following formula: =VALUE(TRIM(A2)).

4. Press <Ctrl+Enter>.

FIGURE 3–21

USE THE CLEAN FUNCTION TO REMOVE ALL NON-PRINTABLE CHARACTERS

If data is imported from other applications, it is possible for this data to contain characters that may not be printable. In this case, the CLEAN function can be used to remove all non-printable characters from text.

To delete non-printable characters:

1. Type any text in cells A2:A5. Make sure that some of the cells contain non-printable characters.

2. Select cells A2:A5 and type the following formula: =CLEAN(A2).

3. Press <Ctrl+Enter>.

USE THE REPT FUNCTION TO SHOW DATA IN GRAPHIC MODE

To demonstrate data in a chart-like view, you can use a special character in a symbol font and repeat the character. To do so, use the REPT function. This function repeats a character a given number of times.

To show data in a simple chart:

1. In cells A2:A11 type numbers from 1 to 10.

2. Select cells B2:B11 and type the following formula: =REPT("n",A2).

3. Press <Ctrl+Enter>.

4. Press Ctrl + 1.

5. Select the Font tab.

6. Select Wingdings from the Font list.

FIGURE 3–22

USE THE REPT FUNCTION TO SHOW DATA IN A CHART

To show data in a chart-like view, you can define a character and repeat this character a specified number of times using the REPT function.

To show data in a chart:

1. In cells B2:B10, type percentages in the range of 1% to 100%.

2. Select cells C2:C10 and type the following formula: =REPT("|",B2*100).

3. Press <Ctrl+Enter>.

FIGURE 3–23

USE THE CHAR FUNCTION TO CHECK YOUR FONTS

To check a few fonts at the same time, open a new worksheet and format columns B through D with the Arial, Wingdings, Webdings, and Terminal fonts. Use the CHAR function to return the character specified by a number in column A.

To check installed fonts:

1. In cell A1, type 1.

2. Press <Ctrl> and drag the right corner of cell A1 down to cell A256.

3. Select cells B1:E255 and type the following formula: =CHAR($A2).

4. Press <Ctrl+Enter>.

FIGURE 3–24

USE THE CHAR FUNCTION TO DETERMINE SPECIAL CHARACTERS

To use special characters, it is necessary to figure out how to get them. The CHAR function will return the character specified by a number in column A. Note that some fonts may have different special characters.

To determine special characters:

1. Copy column A as shown below to your worksheet.

2. Select cells B2:B16 and type the following formula: =CHAR(A2).

3. Press <Ctrl+Enter>.

FIGURE 3–25

USE THE CODE FUNCTION TO DETERMINE THE NUMERIC CODE OF A CHARACTER

To return the numeric, or ASCII, code for the first character in a text string, use the CODE function. This function returns the code corresponding to the currently used character set.

To determine the numeric code of a character:

1. In cells A2:A11, type letters of the alphabet in both upper- and lowercase.

2. Select cells B2:B11 and type the following formula: =CODE(A2).

3. Press <Ctrl+Enter>.

FIGURE 3–26

USE THE UNICHAR FUNCTION TO DETERMINE THE UNICODE CHARACTER FROM A NUMBER

Unicode is an expansion of the ASCII mapping that allows many more symbols to be interpreted by the encoding. It is becoming more popular through its integration with Java. A Unicode character can be returned from a number representing its encoding by using the UNICHAR function. Notice that the Unicode characters and numbers are the same for the ASCII subset.

To determine Unicode characters:

1. Copy column A as shown below to your worksheet.

2. Select cells B2:B11 and type the following formula: =UNICHAR(A2).

3. Press <Ctrl+Enter>.

FIGURE 3–27

USE THE UNICODE FUNCTION TO DETERMINE THE NUMERIC UNICODE VALUE OF A CHARACTER

To reverse the process shown in the previous example, use the UNICODE function to show the Unicode numeric encoding of the character.

To determine the numeric Unicode value of a character:

1. In cells A2:A11, type letters of the alphabet in both upper- and lowercase.

2. Select cells B2:B11 and type the following formula: =UNICODE(A2).

3. Press <Ctrl+Enter>.

FIGURE 3–28

USE THE DOLLAR FUNCTION TO CONVERT NUMBERS TO CURRENCY IN TEXT FORMAT

The DOLLAR function converts a number to text format and applies a currency symbol. The currency format will be rounded to the specified decimal place.

DOLLAR(number, decimals)

number: A number and a reference to a cell that contains a number, or a formula that calculates a value.

decimals: The number of digits to the right of the decimal point. If negative, the number is rounded to the left of the decimal point. If omitted, Excel sets it to 2.

To convert numbers to currency:

1. In cells A2:A10, type numeric values.

2. Select cells B2:B10 and type the following formula: =DOLLAR(A2).

3. Press <Ctrl+Enter>.

FIGURE 3–29

USE THE T FUNCTION TO CHECK FOR VALID NUMBERS

Reviewing Figure 3–30, you will notice that some numbers are listed, but there are also references to text and other values. You can check whether a number is a real value in an Excel worksheet by using the T function. This function checks whether a value is text. If it is text, T returns the text; if it is not, T returns empty text.

To check for valid numbers:

1. Enter some values in column A and change the format for some of them to text (using the Cells option from the Format menu).

2. Select cells B2:B10 and type the following formula: =T(A2).

3. Press <Ctrl+Enter>.

FIGURE 3–30

USE THE TEXT FUNCTION TO COMBINE AND FORMAT TEXT

In a daily sales record, employee names are listed in column A and their daily sales are entered in column B. There are two tasks here: We need to determine the percentage of the weekly sales goal ($1,000) that was met by the daily sales, and we want to combine the information from columns A and B.

FIGURE 3–31

To combine and format text:

1. In a worksheet, copy the data shown in Figure 3–32.

2. Select cells C2:C9 and type the formula =B2/1000.

3. Press <Ctrl+Enter>.

4. Select cells D2:D9 and type the following formula: =A2&" sold "&TEXT(B2,"$0.00")&" today. That's "&TEXT(C2,"0.0%")&" of the weekly goal."

5. Press <Ctrl+Enter>.

FIGURE 3–32

USE CONCATENATE FUNCTION TO COMBINE TEXT

In a daily sales record, employee names are listed in column A and their daily sales are entered in column B. Let us continue from the previous example only to rewrite the functions in column D. This example will be the first of three methods in combining strings. We will first use the function CONCATENATE. Go to the worksheet CONCATENATE.

Keeping the objective in mind to create a sentence from the existing data,

FIGURE 3–33

To combine text using CONCATENATE.

1. In a worksheet, copy the data shown in Figure 3–34.

2. Select cells D2:D9 and type the following formula: =CONCATENATE(A2," sold ",TEXT(B2,"$0.00")," today. That's ",TEXT(C2,"0.0%")," of weekly goal.")

3. Press <Ctrl+Enter>.

FIGURE 3–34

USE CONCAT FUNCTION TO COMBINE TEXT

CONCAT was created for Excel 2016 for two reasons: one to shorten the length of the function and second to be compatible with other programs that already use some version of CONCAT. Additionally, the function does contain one new feature different from its predecessor; namely, it allows you to enter a range of cells rather than having to add cells individually. This comes in handy and makes it easier to read when adjacent cells will be concatenated as in the example below.

FIGURE 3–35

To combine text using CONCAT:

1. In a worksheet, copy the data in columns A through F shown in Figure 3–36.

2. Select cells G2:G9 and type the following formula: =CONCAT(A2,".",B2,".",C3,".",D3:F3)

3. Press <Ctrl+Enter>.

You will notice a range D3:F3 was entered as the last argument saving extra paramters passed.

FIGURE 3–36

USE TEXTJOIN FUNCTION TO COMBINE TEXT

TEXTJOIN was added to simplify the most standard uses of CONCATENATE/CONCAT. Instead of adding a delimiter between each phrase in a string you wish to create, TEXTJOIN automatically does it for you resulting in less typing. Additionally, if any of your fields are blank, you have the option to tell TEXTJOIN to skip the delimiter that would otherwise be added to the final string.

FIGURE 3–37

To combine text using TEXTJOIN:

1. In a worksheet, copy the data in columns A through F shown in Figure 3–38.

2. Select cells G2:G9 and type the following formula: =TEXTJOIN(",.",TRUE,A2:F2)

3. Press <Ctrl+Enter>.

The first parameter passed is a comma and a space representating what is inserted between each cell. The second parameter TRUE tells the formula to ignore any blank cells – in other words if a cell is blank, do not place the delimiter between itself and the next cell. The final parameter is a range of cells for which to perform the function. You will notice in cell G3 that since the Street Type is blank, no delimiter is inserted reducing double delimiters.

FIGURE 3–38

USE ARRAYTOTEXT FUNCTION TO COMBINE TEXT

** Available in Microsoft 365 – may not be available in Excel 2021 or previous versions of Excel **

ARRAYTOTEXT is similar to TEXTJOIN in that it combines text and separates the text using a delimiter with a few differences.

ARRAYTOTEXT will only use a comma as a delimiter while TEXTJOIN offers the option of using any delimiter or phrase you wish as a separator between cells.

ARRAYTOTEXT does not have the option to ignore blanks as TEXTJOIN does.

To combine text using ARRAYTOTEXT:

1. In a worksheet, copy the data in columns A through B shown in Figure 3–39. The cells in rows 5 and 7 are intentionally left blank

2. In cell D2, type the following formula: =ARRAYTOTEXT(A2:B9,FALSE)

3. Press <Enter>.

The first parameter is the range of cells you wish to combine into one cell separated by a comma. The second parameter, FALSE, tells the formula to display it in an “easy to read” format. This is known as the “Consise” format.

4. In the same worksheet in cell D3, type the following formula: =ARRAYTOTEXT(A2:B9,TRUE)

5. Press <Enter>.

In this case, the second parameter, TRUE, tells the formula to display it in a strict array format. This is known as the “Strict” format and can be readily used in other array formulas. You will also notice in this format, each new row of data is separated by a semi-colon while each item in the row is separated by a comma. Text in this format are displayed using double-quotes while numbers are displayed as is.

6. In the same worksheet in cell D4, type the following formula: =TEXTJOIN("~",TRUE,A2:B9)

7. Press <Enter>.

FIGURE 3–39

The TEXTJOIN is included here to highlight the differences mentioned at the beginning of this section; namely, unlike the the ARRAYTOTEXT, with TEXTJOIN you can use any any character or phrase you wish and you have the option of excluding blank cells (in this case cells A5, B5, A7, B7).

Although the displays are similar, ARRAYTOTEXT is more user-friendly when working with link data types such as for stocks and geography described in Chapter 15.

USE VALUETOTEXT FUNCTION TO DISPLAY TEXT FROM ANY CELL VALUE

** Available in Microsoft 365 – may not be available in Excel 2021 or previous versions of Excel **

To display text from cell values using VALUETOTEXT:

1. In a worksheet, copy the data in columns A through B shown in Figure 3–40. The cells in rows 5 and 7 are intentionally left blank

2. In cell D2, type the following formula: = VALUETOTEXT(A2:B9,FALSE)

3. Press <Enter>

4. In cell G2, type the following formula: = VALUETOTEXT(A2:B9,TRUE)

5. Press <Enter>.

FIGURE 3–40

The first parameter in both formulas is the range of cells whose values you wish to display as text. The formula typed in cell D2 with the second paramater as FALSE will display the text values of the of the range entered as is. The formula typed in cell G2 with the second parameter as TRUE will display text within double-quotes and numbers as is.

You will also notice that you only need to type in the formula in one cell for the entire range. The function will automatically display all the texts in the same number of rows and columns as the original range being converted.

CHAPTER 4

DATE AND TIME FUNCTIONS

USE CUSTOM FORMATTING TO DISPLAY THE DAY OF THE WEEK

A worksheet contains dates in column A. Use this tip to get the corresponding day of the week of each of these dates.

To display weekdays using customized formatting:

1. Select cells B2:B10 and type the formula =A2.

2. Press <Ctrl+Enter>.

3. Press <Ctrl + 1> to bring up the ‘Format Cells’ popup window.

4. Select the Number tab expansion icon and click Custom in Category.

5. In the Type box, change the number format to dddd.

6. Press OK.

FIGURE 4–1

USE THE WEEKDAY FUNCTION TO DETERMINE THE WEEKEND

How do you find out whether a date falls on a weekend? To answer this question, you can either use the previous tip or use the more convenient WEEKDAY function. This function returns the day of the week as a number corresponding to a date. The returned number is given as an integer, ranging from 1 (Sunday) to 7 (Saturday), by default.

To determine the weekend:

1. Using the worksheet from the previous example, select cells C2:C10 and type the following formula: =IF(OR(WEEKDAY(A2)=7,WEEKDAY(A2)=1),"weekend","").

2. Press <Ctrl+Enter>.

FIGURE 4–2

NOTE

In column B use the custom format dddd to check the result of column C.

USE THE TODAY FUNCTION TO CHECK FOR FUTURE DATES

In a worksheet, dates in column A need to be checked to see if they are in the future. The actual date can be determined by using the TODAY function and can be compared with the dates in the worksheet using the IF function. If dates are in the future, the result in column B should be Y; otherwise, it should be N.

To check for future dates:

1. In cell C1, type the formula =TODAY() to show the current date.

2. Select cells B2:B10 and type the following formula: =IF(A2<=TODAY(),"N","Y").

3. Press <Ctrl+Enter>.

4. You can verify this by changing any of the dates in cells A2:A10 to any date after, same as today, or before today’s date. You will only see a ‘Y’ in the Future column if the date is tomorrow or later.

FIGURE 4–3

USE THE TEXT FUNCTION TO CALCULATE WITH THE TODAY FUNCTION

A project starts today and ends 10 days later. These dates are shown in cells B1 and B2. The end date has to be calculated based on the start date, and the dates need to be combined with additional text to form the message shown in cell A4.

To calculate with the TODAY function:

1. In cell B1 type the formula =TODAY().

2. In cell B2 type the formula =B1 + 10 to add ten days to the current date.

3. Select cell A4 and type the following formula: ="The project starts on " & TEXT(B1,"MM/DD/YYYY") & " and ends on " & TEXT(B2,"MM/DD/YYYY").

4. Press <Enter>.

FIGURE 4-4

NOTE

The TEXT function (TEXT(value, format_text)) converts a value to text in a specific number format. In this example, format_text is shown as MM = month (two digits), DD = day (two digits), and YYYY = year (four digits).

USE THE NOW FUNCTION TO SHOW THE CURRENT TIME

The previous tip described how to get the current date. Now we want to determine the current time. The NOW function returns the serial number of the current date and time. Microsoft Excel stores dates as sequential numbers so they can be used in calculations. By default, January 1, 1900, is number 1; therefore, January 1, 2006, is number 38718 because it is 38,717 days after January 1, 1900. A decimal point and numbers to its right are added to represent the time; numbers to the left of the decimal point represent the date. For example, the serial number .5 represents the time noon. The NOW() function is not updated continuously.

To show the current time:

1. In cell A1 type the formula =NOW() and press <Enter>.

2. Ensure that cell A1 is selected and choose Cells from the Format menu.

3. In the Number tab, select Date under Category.

4. Select the format 3/14/12 1:30 p.m. (This will show the current date and time when selected.) Depending on your location, this format may look different. The point is to select the format with the month, day, year along with the time in meridian (AM or PM).

5. Press <Enter>.

FIGURE 4–5

USE THE NOW FUNCTION TO CALCULATE TIME

To calculate with time, it is helpful to know that Excel stores the time as a decimal value. For example, 0.5 is noon, 0.75 is 6:00 a.m., and so on.

To calculate with time:

1. In cell B1 type the formula =NOW().

2. In cell B2 type the formula =B1+0.25 to add six hours to the current time in cell B1.

3. Type the following formula in cell C1: ="The meeting starts at " & TEXT(B1,"hh:mm") & " and ends at " & TEXT(B2,"hh:mm").

4. Press <Enter>.

FIGURE 4–6

USE THE DATE FUNCTION TO COMBINE COLUMNS WITH DATE PARTS

The worksheet shown in Figure 4–7 uses three columns showing dates. Column A lists years; column B lists months, using numbers in the range 1 to 12; and column C contains the days of a month, in the range 1 to 31. These columns need to be combined to show one formatted date. To do this, use the DATE function.

DATE(year, month, day)

year: This argument can be from one to four digits. Microsoft Excel for Windows uses the 1900 date system.

month: A number representing the month of the year (1 to 12).

day: A number representing the day of the month (1 to 31).

To combine values of cells into one date:

1. Select cells D2:D10 and type the following formula: =DATE(A2,B2,C2).

2. Press <Ctrl+Enter>.

NOTE

Excel knows which years are leap years and thus provides correct results even when incorrect data is entered, as in row 3. Excel will also add the correct number of months even if the months are more than 12. Try entering 15 in cell B5 and determine how the resulting date was calculated.

FIGURE 4–7

USE THE LEFT, MID, AND RIGHT FUNCTIONS TO EXTRACT DATE PARTS

The worksheet in Figure 4–8 contains date values in column A. Excel cannot interpret these values as dates. To show the date in a correct format, the values of column A need to be extracted to year, month, and day.

To extract, combine, and display the correct format:

1. Select cells B2:B10 and type the following formula: =DATE(LEFT(A2,4),MID(A2,FIND(".",A2,1)+1,2),RIGHT(A2,2)).

2. Press <Ctrl+Enter>.

FIGURE 4–8

NOTE

The first four digits need to be transferred with the LEFT function. Then use the FIND function to detect the decimal point. On the right of the first decimal point (+1), two digits are interpreted as the month using the MID function. On the right side of the second decimal point, use the RIGHT function to extract two digits as the day value. You could have also used the MID function in place of both the LEFT and RIGHT since the decimal point is the same for all.

USE THE TEXT FUNCTION TO EXTRACT DATE PARTS

A worksheet contains date values in column A as text that cannot be interpreted by Excel as date values. As in the previous example, the text has to be extracted, but the result should be specially formatted as shown in the screenshot below.

To extract, combine, and show a specially formatted date:

1. Select cells B2:B10 and type the following formula: =TEXT(DATE(RIGHT(A2,4),MID(A2,3,2),MID(A2,1,2)),"YYYY-MM-DD").

2. Press <Ctrl+Enter>.

FIGURE 4–9

NOTE

First, transfer the last four digits with the RIGHT function. Then use the MID function twice to get the two digits for the month and those for the day. With the TEXT function, the date can be formatted individually.

USE THE DATEVALUE FUNCTION TO RECALCULATE DATES FORMATTED AS TEXT

Figure 4–10 shows start and end dates in columns A and B. Excel cannot interpret the columns as dates, because they are formatted as text. To convert and calculate these types of dates, use the DATEVALUE function. This function returns the serial number of the date represented by the “text date.”

Let us determine the difference between start and end dates.

To calculate the difference between text dates:

1. Select cells C2:C10.

2. Type the following formula: =DATEVALUE(B2)-DATEVALUE(A2).

3. Press <Ctrl+Enter>.

FIGURE 4–10

USE THE YEAR FUNCTION TO EXTRACT THE YEAR PART OF A DATE

As shown in Figure 4–11, column A of a worksheet contains a list of dates formatted in different ways. To determine the year corresponding to a date, use the YEAR function. This function returns the year as an integer in the range 1900 to 9999. If the year is not specified, as in cell A9, the year is assumed to be the current year.

To extract the year as part of a date:

1. In cells A2:A10, generate a list of dates using different formats.

2. Select cells B2:B10 and type the following formula: =YEAR(A2).

3. Press <Ctrl+Enter>.

FIGURE 4–11

USE THE MONTH FUNCTION TO EXTRACT THE MONTH PART OF A DATE

For this tip, use the worksheet from the previous example. Column A contains dates formatted in different ways. To determine the month part of a date, use the MONTH function. This function returns the month corresponding to a date as an integer in the range 1 to 12.

To extract the month part of a date:

1. In cells A2:A10, generate a list of dates using different formats.

2. Select cells B2:B10 and type the following formula: =MONTH(A2).

3. Press <Ctrl+Enter>.

FIGURE 4–12

USE THE DAY FUNCTION TO EXTRACT THE DAY PART OF A DATE

Once again, use the worksheet from the previous two examples. Column A contains dates in different formats. To determine the day part of a date, use the DAY function. This function returns the day corresponding to a date as an integer in the range 1 to 31.

To extract the day as part of a date:

1. In cells A2:A10 generate a list of dates using different formats.

2. Select cells B2:B10 and type the following formula: =DAY(A2).

3. Press <Ctrl+Enter>.

FIGURE 4–13

NOTE

If the day part is missing (see rows 5 and 6), the function returns the value 1.

USE THE MONTH AND DAY FUNCTIONS TO SORT BIRTHDAYS BY MONTH

The worksheet in Figure 4–14 contains a list of employees and their birthdays. This list has to be sorted by month, which is not possible with Excel’s usual sort function. Use this tip to insert a supporting column to convert the month and day dates to serial values.

To sort birthdays by month:

1. In cells A2:B10 generate a list of employees and their birthdays.

2. Select cells C2:C10 and type the following formula: =MONTH(B2)*100+DAY(B2).

3. Press <Ctrl+Enter>.

4. Select cell C1.

5. From the Home tab choose the Editing bar.

6. Click on Sort & Filter and choose Sort smallest to largest.

7. Format the column as General to display serial values rather than dates.

FIGURE 4–14

USE THE DATE FUNCTION TO ADD MONTHS TO A DATE

Let us say we want to add a number of months to a given start date. In a new worksheet, list different start dates in column A. In column B, enter the number of months to be added to or subtracted from the start date. Based on that data, the end date can be calculated.

To add months to or subtract months from dates:

1. In cells A2:A10 list some start dates, as shown in Figure 4–15.

2. In cells B2:B10 list the number of months to add or subtract.

3. Select cells C2:C10 and type the following formula: =DATE(YEAR(A2),MONTH(A2)+B2,DAY(A2)).

4. Press <Ctrl+Enter>.

FIGURE 4–15

NOTE

To determine an end date in the past, put a minus sign in front of the number of months.

USE THE EOMONTH FUNCTION TO DETERMINE THE LAST DAY OF A MONTH

To find the last day of a month, use the EOMONTH function (EOMONTH(start_date, offset_months)). This function returns the date of the last day of the month that is offset_months from start_date. If the function is not available, load the Analysis ToolPak add-in. From the File tab, choose Options. Select Add-Ins. From the dropdown Manage list, select Excel Add-Ins and click GO. In the Add-Ins dialog, tick the Analysis ToolPak box and click OK.

To determine the last day of a month:

1. In cells A2:A10, enter some dates.

2. In cells B2:B10, enter the desired offset from the start date (positive or negative values).

3. Select cells C2:C10 and type the following formula: =EOMONTH(A2,B2).

4. Press <Ctrl+Enter>.

FIGURE 4–16

USE THE DAYS360 FUNCTION TO CALCULATE WITH A 360-DAY YEAR

If there is an accounting system installed that is based on 12 30-day months, the DAYS360 function can be used. This function returns the number of days between two dates based on a 360-day year.

Here is the syntax:

DAYS360(start_date, end_date, method)

start_date: The start date.

end_date: The end date.

method: A logical value that specifies which method to use (U.S. or European).

U.S. (NASD) method: Used if method is FALSE. If the starting date is the 31st of a month, it is the 30th of the same month. If the ending date is the 31st of a month and the starting date is earlier than the 30th of the month, the ending date is the first of the next month; otherwise, the ending date is the 30th of the same month.

European method: Used if method is TRUE. Starting or ending dates on the 31st of a month are the 30th of the same month.

To calculate with 360-day years:

1. In a worksheet, copy the data in columns A and B from Figure 4–17.

2. Select cells C2:C10 and type the following formula: =DAYS360(A2,B2,FALSE).

3. Press <Ctrl+Enter>.

FIGURE 4–17

USE THE WEEKDAY FUNCTION TO CALCULATE WITH DIFFERENT HOURLY PAY RATES

Many companies calculate payroll using hourly rates for each employee. The hourly rates depend on which days are worked, as work performed on the weekend is often paid at a higher rate than work performed Monday through Friday.

In this example, different hourly rates are defined based on which days are worked. Column A lists the dates, column B has the custom format DDD to show the day of the week, and column C lists the number of hours worked.

To calculate with different hourly pay rates:

1. In a worksheet, enter the data shown in columns A, B, and C in Figure 4–18.

2. Select cell F2 and enter 12.50 (hourly rate for Monday through Friday).

3. Select cell F5 and enter 18.50 (hourly rate for Saturday and Sunday).

4. Select cells D2:D10 and type the following formula: =IF(OR(WEEKDAY(A2)=1,WEEKDAY(A2)=7),C2*$F$5,C2*$F$2).

5. Press <Ctrl+Enter>.

FIGURE 4–18

USE THE WEEKNUM FUNCTION TO DETERMINE THE WEEK NUMBER

To determine the week number of a date (a quite common practice in Europe) use the WEEKNUM function. If the WEEKNUM function is not available, load the Analysis ToolPak add-in. From the File tab, choose Options. Select Add-Ins. From the dropdown Manage list, select Excel Add-Ins and click GO. In the Add-Ins dialog, tick the Analysis ToolPak box and click OK.

This function returns a number that indicates where the week falls numerically within a year.

To determine the week number:

1. Type different dates of the year in cells A2:A10.

2. Select cells B2:B10 and type the following formula: =WEEKNUM(A2).

3. Press <Ctrl+Enter>.

FIGURE 4–19

USE THE EDATE FUNCTION TO CALCULATE MONTHS

If a few months need to be added to or subtracted from a date, the EDATE function is especially useful. This function returns a serial number that represents the date that is the indicated number of months before or after a specified date (offset).

In this example, column A of a worksheet contains the start dates. In column B, enter the offset in months to be added or subtracted. The result should show up in column C.

To use EDATE and add or subtract a number of months to start dates:

1. Enter different start dates in column A.

2. Enter offset months in column B.

3. Select cells C2:C10 and type the following formula: =EDATE(A2,B2).

4. Press <Ctrl+Enter>.

FIGURE 4–20

NOTE

To use the EDATE function, the Analysis ToolPak add-in needs to be installed as described in the previous example.

USE THE WORKDAY FUNCTION TO CALCULATE WORKDAYS

A worksheet is used to schedule a project. The project contains the start date and five major steps. Each step is estimated to take a certain number of days to accomplish. To determine the correct end date, weekends and additional days off needs to be taken into consideration. To perform this task, use the WORKDAY function from the Analysis ToolPak add-in. This function returns a date that is the indicated number of workdays before or after a date. Workdays exclude weekends and any dates identified as holidays. The syntax is as follows:

WORKDAY(start_date, days, holidays)

start_date: The start date.

days: The total number of available days, not counting weekends and holidays, before or after start_date. Both positive and negative values are acceptable.

holidays: (optional) One or more dates that are to be excluded from the work schedule.

To determine the end date of a project:

1. In cell C2, enter the start date of the project.

2. In column B, enter the estimated days to finish each step.

3. In cell D2, type the following formula: =WORKDAY(C2,B2,$F$2:$F$8).

4. In cells F2:F8, additional holidays can be listed individually.

5. In cell C3, type the formula =D2+1.

6. Fill cell C3 down to C6 and cell D2 down D6.

FIGURE 4–21

USE THE NETWORKDAYS FUNCTION TO DETERMINE THE NUMBER OF WORKDAYS

In this example, a project has to be scheduled. Each of the five steps has a fixed start and end date. To determine the number of complete workdays between the start and end dates, the NETWORKDAYS function from the Analysis ToolPak add-in can be used. This function excludes weekends and any dates identified as non-workdays and holidays. The syntax is as follows:

NETWORKDAYS(start_date, end_date, holidays)

start_date: The start date.

end_date: The end date.

holidays: (optional) One or more dates that are to be excluded from the work schedule.

To determine the number of workdays:

1. In column B, type the start date of each step.

2. In column C, type the end date of each step.

3. List additional holidays in cells F2:F6.

4. Select cells D2:D6 and type the following formula: =NETWORKDAYS(B2,C2,$F$2:$F$6).

5. Press <Ctrl+Enter>.

FIGURE 4–22

USE THE YEARFRAC FUNCTION TO CALCULATE AGES OF EMPLOYEES

To calculate the difference between two dates, use the YEARFRAC function from the Analysis ToolPak add-in. This function calculates the fraction of the year represented by the number of whole days between start_date and end_date. The syntax is:

YEARFRAC(start_date, end_date, basis)

start_date: The start date.

end_date: The end date.

basis: The count basis to use: 0 or omitted = U.S. (NASD) 30/360, 1 = actual/actual, 2 = actual/360, 3 = actual/365, or 4 = European 30/360.

To calculate the age of employees based on the current date:

1. In column A, list the names of employees.

2. In column B, enter their birthdays.

3. Select cells C2:C10 and type the formula TODAY().

4. Press <Ctrl+Enter>.

5. Select cells D2:D10 and type the following formula: =YEARFRAC(B2,C2,0).

6. Press <Ctrl+Enter>.

FIGURE 4–23

USE THE DATEDIF FUNCTION TO CALCULATE AGES OF EMPLOYEES

To calculate the exact age of employees, use the undocumented DATEDIF function from the Analysis ToolPak add-in. This function calculates the exact number of years, months, and days between two dates. The syntax is:

DATEDIF(start_date, end_date, format)

start_date: The start date.

end_date: The end date.

format: Indicates the format to use. “y” gives the difference in years, “m” in months, “d” in days; “ym” gives the difference in months, ignoring the year; “yd” in days, ignoring the year; and “md” in days, ignoring the month and year.

To calculate the ages of employees:

1. In column A list the names of employees.

2. In column B enter their birthdays.

3. Select cells C2:C10 and type the formula TODAY().

4. Press <Ctrl+Enter>.

5. Select cells D2:D10 and type the following formula: =DATEDIF(B2,C2,"Y") & " years and " & DATEDIF(B2,C2,"YM") & " months".

6. Press <Ctrl+Enter>.

FIGURE 4–24

USE THE WEEKDAY FUNCTION TO CALCULATE THE WEEKS OF ADVENT

As a practical task using previously learned functions, the start date of each week of Advent can be calculated easily. Consider that Advent begins on the fourth Sunday before Christmas. Enter in a cell the date of Christmas and use the WEEKDAY function to calculate when each week of Advent begins.

To calculate when the weeks of Advent begin for 2013:

1. In cell B2 enter 12/25/2013.

2. In cell B3, enter this formula to find the first week of Advent: =B1-(WEEKDAY(B1,2))-21.

3. Enter this formula in cell B4: =B1-(WEEKDAY(B1,2))-14.

4. Enter this formula in cell B5: =B1-(WEEKDAY(B1,2))-7.

5. Enter this formula in cell B6: =B1-(WEEKDAY(B1,2)).

FIGURE 4–25

USE THE TIMEVALUE FUNCTION TO CONVERT TEXT TO TIME

In this example, a text string has to be converted to a valid time. Columns A and C contain different start and end times as part of a standardized text string. It is possible to extract the times and convert them to valid time values that can be used as the basis for calculations. To convert text into a valid time, use the TIMEVALUE function. This function returns the decimal number of the time represented by a text string. The decimal number is a value ranging from 0 to 0.99999999, representing the time from 0:00:00 (12:00:00 midnight) to 23:59:59 (11:59:59 p.m.).

To extract and convert text to time:

1. Select cells B2:B10 and type the following formula: =TIMEVALUE(MID(A2,8,5)).

2. Press <Ctrl+Enter>.

3. Select cells D2:D10 and type the following formula: =TIMEVALUE(MID(C2,6,5)).

4. Press <Ctrl+Enter>.

5. Select cells B2:B10 and D2:D10.

6. Press Ctrl + 1 and select the Number tab, click Time under Category, then select the 1:30:55 p.m. option in the Type box.

7. Click OK.

FIGURE 4–26

USE A CUSTOM FORMAT TO CREATE A TIME FORMAT

When you enter time values in cells, you need to type the colon between the hours and minutes. However, this is unnecessary if you use a custom format.

To create a customized time format:

1. Enter time values without colons and select the cells.

2. Press Ctrl + 1, select the Number tab, and click on Custom under Category.

3. Type 00":"00 as the custom format.

4. Click OK.

FIGURE 4–27

NOTE

You can also use the AutoCorrect options. Click the File tab and then click Options. Then click Proofing and afterwards click AutoCorrect Options. Type two commas in the Replace field and type the colon in the With field. Click Add to insert this option. Test this by typing 1200 in a cell. Excel corrects the input to 12:00.

USE THE HOUR FUNCTION TO CALCULATE WITH 100-MINUTE HOURS

Some companies record working time in 100-minute hours. For example, the time 6:45 a.m. is converted to 6:75, which sometimes makes further calculations easier. To convert to this format, extract the minutes from the time and divide them by 60 using the MINUTE function. This function returns the minutes of a time value. The minute is given as an integer, ranging from 0 to 59. The hours can be extracted with the HOUR function. This function returns the hour of a time value as an integer ranging from 0 (12:00 a.m.) to 23 (11:00 p.m.).

To convert normal time to 100-minute hours:

1. In cells A2:A10, list work dates.

2. In cells B2:B10, enter the start time for each day.

3. In cells C2:C10, record the end time for each day.

4. Select cells D2:D10 and type the following formula: =HOUR(C2-B2)+MINUTE(C2-B2)/60.

5. Press <Ctrl+Enter>.

FIGURE 4–28

USE THE TIME FUNCTION TO COMBINE SINGLE TIME PARTS

The worksheet in Figure 4–29 shows single time parts in each column. Column B contains hours, column C contains minutes, and column D contains seconds. All three columns need to be combined into one time, as shown in column E. To do this, use the TIME function. This function returns the decimal number for a particular time. The syntax is:

TIME(hour, minute, second)

hour: A number from 0 to 23 that represents the hour. Any value greater than 23 will be divided by 24, and the remainder will be treated as the hour value.

minute: A number from 0 to 59 that represents minutes. Any value greater than 59 will be converted to hours and minutes.

second: A number from 0 to 59 that represents seconds. Any value greater than 59 will be converted to hours, minutes, and seconds.

To combine single time parts into a valid time:

1. Select cells E2:E10 and type the formula =TIME(B2,C2,D2).

2. Press <Ctrl+Enter>.

3. From the Format menu, select Cells.

4. Select the Number tab and click Custom under Category.

5. Enter hh:mm:ss as the custom format.

6. Click OK.

FIGURE 4–29

CHAPTER 5

BASIC STATISTICAL FUNCTIONS

USE THE MAX FUNCTION TO DETERMINE THE LARGEST VALUE IN A RANGE

This example finds the largest value in the range A3:D11 by using the MAX function. The function’s return value is the largest value in a set.

MAX(number1, number2, ...)

number1, number2, ...: From 1 to 255 numbers for which you want to find the largest value. It is possible to use a cell reference; however, the cells must contain numbers or values that can be converted to numbers. You can also use a range of values that can number more than 255

To determine the largest value:

1. In cells A3:D11 type any values.

2. In cell B1 type the formula =MAX(A3:D11).

3. Press <Enter>.

FIGURE 5–1

NOTE

In Chapter 10, you will learn how to automatically mark and shade the largest value in a range.

USE THE MIN FUNCTION TO DISCOVER THE LOWEST SALES VOLUME FOR A MONTH

In a company, employee sales are monitored. Columns B to E contain the sales for the first four months of the year. To determine the lowest sales for a given month, use the MIN function. The function’s return value is the smallest value in a set.

MIN(number1, number2, ...)

number1, number2, ...: From 1 to 30 numbers for which you want to find the smallest value. It is possible to use a cell reference; however, the cells must contain numbers or values that can be converted to numbers.

To determine the lowest monthly sales:

1. In a worksheet, copy the range A1:E10 shown in Figure 5–2.

2. Select cells B12:E12 and type the following formula: =MIN(B2:B10).

3. Press <Ctrl+Enter>.

FIGURE 5–2

NOTE

In Chapter 10, you will learn how to automatically shade the smallest value in each column.

USE THE MINIFS FUNCTION TO DISCOVER THE LOWEST SALES VOLUME FOR A MONTH BASED ON CRITERIA

Similar scenario to the previous example with the addition of the Region column. Column B contains the region in which the salespeople work. Columns C to F contain the sales for the first four months of the year. To determine the lowest sales for a given month in the “West” region, use the MINIFS function. The function’s return value is the smallest value in a set based upon criteria.

MINIFS(min_range,criteria_range1, criteria1,[criteria_range2, criteria2],...)

Min_range is the range of values (must be numbers) from which to determine the minimum. Up to 126 criteria can be placed in the function after the min_range. In this example, we only use one – the region with a value of “West”

To determine the lowest monthly sales for the West region:

1. In a worksheet, copy the range A1:F10 shown in Figure 5–3.

2. Copy the range B12:B16 shown in Figure 5–3

3. Select cells C12:F12 and type the following formula: =MIN(C2:C10)

4. Press <Ctrl+Enter>

5. Select cells C13:F16 and type the following formula: =MINIFS(C$2:C$10,$B$2:$B$10,$B13)

6. Press <Ctrl+Enter>.

NOTE

There is no dollar sign in front of the letter “C” in the formula above. Nor is there a dollar sign in front of the “13.” The reason is that when these formulas are copied to other cells the “C” and the “13” will change according to what column and row the formula is in.

FIGURE 5–3

USE THE MAXIFS FUNCTION TO DISCOVER THE HIGHEST SALES VOLUME FOR A MONTH BASED ON CRITERIA

Similar scenario to the previous example but seeking the highest sales amount. Column B contains the region in which the salespeople work. Columns C to F contain the sales for the first four months of the year. To determine the highest sales for a given month in the “West” region, use the MAXIFS function. The function’s return value is the highest value in a set based upon criteria.

MAXIFS(max_range,criteria_range1, criteria1,[criteria_range2, criteria2],...)

Max_range is the range of values (must be numbers) from which to determine the maximum. Up to 126 criteria can be placed in the function after the Max_range. In this example, we only use one – the region with a value of “West”

To determine the highest monthly sales for the West region:

1. In a worksheet, copy the range A1:F10 shown in Figure 5–4.

2. Select cells C13:F13 and type the following formula: =MAXIFS(C2:C10,$B$2:$B$10,"West")

3. Press <Ctrl+Enter>.

NOTE

You can also use a similar technique used in the MINIFS scenario by adding the names of the regions to cells B13:B16 and change the third parameter in the formula above from “West” to $B13 without the dollar sign in front of the “13.”

FIGURE 5–4

USE THE MIN FUNCTION TO DETECT THE SMALLEST VALUE IN A COLUMN

To determine the smallest value in a single column, the MIN function is used. This function returns the smallest value in a set of values. The syntax is described in the previous tip.

To determine the smallest value in a column:

1. In column A, type any values down to cell A10.

2. Select cell B1 and type the following formula: =MIN(A1:A10).

3. Press <Enter>.

FIGURE 5–5

NOTE

The MIN function can be used to determine the smallest value in a row. For the smallest value in the first row, use the formula =MIN(1:1). To get the smallest value of the first three rows, use the following function: =MIN(1:3). If you do not need to get the smallest value in the entire row, you can simplify it to a range such as =MIN(C2:H2).

USE THE SMALL FUNCTION TO FIND THE SMALLEST VALUES IN A LIST

To determine the smallest value in a list, we can use the MIN function. However, the easiest way to find multiple small values of a range is by using the SMALL function. This function returns the nth smallest value in a set of data.

SMALL(array, n)

array: An array or range of numerical data in which you want to find the nth smallest value.

n: The position from the smallest in the array or range of data to return.

To determine the three smallest values of a range:

1. In cells A1:A10, enter any values from 100 to 999.

2. Select cell C1 and type the following formula =SMALL($A$1:$A$10,1) to get the smallest value.

3. In cell C2 type the formula =SMALL($A$1:$A$10,2) to get the second smallest value.

4. In cell C3 type the formula =SMALL($A$1:$A$10,3) to get the third smallest value.

FIGURE 5–6

USE THE LARGE FUNCTION TO FIND THE HIGHEST VALUES

To determine the highest value in a list, we use the MAX function. To find out multiple high values of a range, the LARGE function can be used. This function returns the nth highest value in a set of data.

LARGE(array, n)

array: Array or range of numerical data in which we want to find the nth highest value.

n: The position from the highest in the array or range of data to return.

To determine the three highest values of a range:

1. In cells A2:C10, type any values from 0 to 99.

2. Number cells A12, A13, and A14 with 1, 2, and 3.

3. Select cells B12:D14 and type the following formula: =LARGE(B$2:B$10,$A12).

4. Press <Ctrl+Enter>.

FIGURE 5–7

USE THE INDEX, MATCH, AND LARGE FUNCTIONS TO DETERMINE AND LOCATE THE BEST SALESPERSON

As seen in the previous tips, it is easy to find out the highest value in a list. But how do you find the one person on a sales team who sold the most? And how do you find out how much ahead of the others he or she is?

Start with the LARGE function to determine the highest sales. Then use the INDEX and MATCH functions to retrieve the name of the employee.

To determine and locate the employee with the most sales:

1. In cells B2:B10 type the daily sales of the employees.

2. Select cell D3 and type the following formula: =INDEX($A$2:$A$10,MATCH(LARGE($B$2:$B$10,1),$B$2:$B$10,0)).

3. Press <Enter>.

4. Select cell D6 and type the following formula: =LARGE($B$2:$B$10,1)-LARGE($B$2:$B$10,2).

5. Press <Enter>.

FIGURE 5–8

USE THE SMALL FUNCTION TO COMPARE PRICES AND SELECT THE CHEAPEST OFFER

A worksheet displays offers from different suppliers. To decide which is the best offer, the SMALL function can be used to determine the lowest price. As in the previous tip, you can use the INDEX and MATCH functions to get the names of the companies.

To find out the three cheapest offers and their suppliers:

1. In cells B2:B10, enter the offers.

2. Number the cells C2:C4 with 1, 2, and 3.

3. Select cells D2:D4 and type the following formula: =INDEX($A$2:$A$10,MATCH(SMALL($B$2:$B$10,C2),$B$2:$B$10,0)).

4. Press <Ctrl+Enter>.

5. Select cells E2:E4 and type the following formula: =SMALL($B$2:$B$10,C2).

6. Press <Ctrl+Enter>.

FIGURE 5–9

USE THE AVERAGE FUNCTION TO CALCULATE THE AVERAGE OUTPUT

In this example, the output of three production lines has been recorded for several days. Now the average of the three highest outputs of each line must be calculated. For this task, Excel provides the AVERAGE function, which returns the average, or arithmetic mean, of the arguments.

AVERAGE(number1, number2, ...)

number1, number2, ...: From 1 to 30 numeric arguments for which you want to determine the average. It is also possible to use a cell reference, as shown in this example.

To calculate the average of the three highest capacities of each production line:

1. In cells B2:D10, type the output of each production line.

2. Select cells B12:D12 and type the following formula: =AVERAGE(LARGE(B2:B10,1),LARGE(B2:B10,2),LARGE(B2:B10,3)).

3. Press <Ctrl+Enter>.

FIGURE 5–10

USE THE SUBTOTAL FUNCTION TO SUM A FILTERED LIST

When using the Filter option in the Data menu, it is not advisable to use the SUM function to sum filtered rows, because it sums all rows, including those that are hidden. Instead, use the SUBTOTAL function to get the subtotal of a list or database that is visible.

SUBTOTAL(function_num, ref1, ref2, ...)

function_num: A number from 1 to 11 that specifies a particular function to use for calculating subtotals. (1 = AVERAGE, 2 = COUNT, 3 = COUNTA, 4 = MAX, 5 = MIN, 6 = PRODUCT, 7 = STDEV, 8 = STDEVP, 9 = SUM, 10 = VAR, and 11 = VARP.)

ref1, ref2, ...: From 1 to 254 ranges or references for which a subtotal is desired.

To sum a filtered list:

1. In cells B2:B10, type group numbers from 1 to 3.

2. In cells C2:C10, type the daily sales for each group.

3. From the Data menu, select Filter | AutoFilter.

4. Select group 1 in the column B filter.

5. Select cell C12 and type the following formula: =SUBTOTAL(9,C2:C10).

FIGURE 5–11

USE THE COUNT FUNCTION TO COUNT CELLS CONTAINING NUMERIC DATA

To count all cells that contain numbers, use the COUNT function. Empty cells, logical values, text, and error values are ignored.

COUNT(value1, value2, ...)

value1, value2, ...: From 1 to 255 arguments of any type of data. However, all but numeric data is ignored.

To count the number of cells that contain numbers:

1. In cells A1:A10, type data (numeric and text).

2. Select cell C1 and type the following formula: =COUNT(A1:A10).

3. Press <Enter>.

FIGURE 5–12

NOTE

Arguments that are date and time values are counted as numeric, too.

USE THE COUNTA FUNCTION TO COUNT CELLS CONTAINING DATA

To count all cells that are not empty and contain data in a range or array, use the COUNTA function.

COUNTA(value1, value2, ...)

value1, value2, ...: 1 to 30 arguments representing the values to be counted.

To count all cells containing data:

1. In cells A1:A10, type any kind of data (numeric and text).

2. Select cell C1 and type the following formula: =COUNTA(A1:A10).

3. Press <Enter>.

FIGURE 5–13

NOTE

The COUNTA function does not count empty cells.

USE THE COUNTA FUNCTION TO COUNT CELLS CONTAINING TEXT

To count all cells that contain text data, use a combination of functions in one formula. The number of cells with any kind of data is counted with the COUNTA function. All numeric cells are counted with the COUNT function. Just subtract the results of the COUNT function from the results of the COUNTA function, using the same range, to get all cells containing text.

To count only cells with text:

1. In cells A1:A10 type any kind of data (numeric and text).

2. Select cell C1 and type the following formula: =COUNTA(A1:A10)-COUNT(A1:A10).

3. Press <Enter>.

FIGURE 5–14

USE THE COUNTBLANK FUNCTION TO COUNT EMPTY CELLS

Occasionally it may be useful to determine how many cells in a range are empty. You can use the COUNTBLANK function to count all empty cells in a range of cells.

COUNTBLANK(range)

range: The range in which to count blank cells.

To count all empty cells in a specified range:

1. In cells A1:A10 type data (numeric and text). Be sure to leave some of the cells empty.

2. Select cell C1 and type the following formula: =COUNTBLANK(A1:A10).

3. Press <Enter>.

FIGURE 5–15

USE THE COUNTA FUNCTION TO DETERMINE THE LAST FILLED ROW

In this example, the last row that was filled in on a worksheet needs to be determined. If all cells of a column contain data and are not empty, the COUNTA function can be used. Define as the range the entire column in order to count all filled cells.

To determine the last filled row:

1. In cells A1:A10 type data (numeric and text).

2. Select cell B1 and type the following formula: =COUNTA(A:A).

3. Press <Enter>.

FIGURE 5–16

NOTE

To determine the last column of a worksheet that was filled, use the function =COUNTA(1:1), as shown in cell B2.

USE THE SUBTOTAL FUNCTION TO COUNT ROWS IN FILTERED LISTS

When using the Filter option in the Data menu, it is recommended that the COUNT and COUNTA functions not be used, because in a filtered worksheet they count both visible and hidden rows. Instead, use the SUBTOTAL function to get the subtotal of a list or database that is visible. The syntax for the SUBTOTAL function and its function number parameter values were presented earlier in this chapter.

To count rows in a filtered list:

1. In cells B2:B10, type group numbers from 1 to 3.

2. In cells C2:C10, type the daily sales of each group.

3. From the Data menu, select Filter | AutoFilter.

4. Select group 1 in the column B filter.

5. Select cell C12 and type the following formula: =SUBTOTAL(2,C2:C10) & "rows in filter".

FIGURE 5–17

NOTE

Use the function =SUBTOTAL(3,B2:B10) & "rows in filter" in cell B12 to count the filtered cells as seen in Figure 5–17.

USE THE RANK, RANK.EQ, RANK.AVG FUNCTIONS TO DETERMINE THE RANK OF SALES

To rank the sales over a period of days, use the RANK, RANK.EQ, or RANK.AVG function. The RANK function is now considered a compatibility function meaning that it exists for use in older versions of Excel and may be removed someday. The RANK.EQ is the upgrade for RANK and RANK.AVG contains an additional refinement in output. All the RANK functions return a number that is the rank of a value. RANK and RANK.EQ provide the same result while RANK.AVG will provide the average if more than one number is contained in the data. In this example, the list can be sorted to display sales in rank order.

RANK(number, ref, order), RANK.EQ(number, ref, order), RANK,AVG(number, ref, order)

number: The number for which we want to find the rank.

ref: A reference to a list of numbers. Only numeric values are considered.

order: A number that specifies the ranking method. If order is 0 or omitted, the numbers are ranked in descending order. If order is a nonzero value, the numbers are ranked in ascending order.

To rank a list in descending order:

1. In cells A2:A10, enter dates.

2. In cells B2:B10, enter the sales for each date.

3. Select cells C2:C10 and type the following formula: =RANK(B2,$B$2:$B$10).

4. Press <Ctrl+Enter>.

5. Select cells D2:D10 and type the following formula: =RANK.EQ(B2,$B$2:$B$10).

6. Press <Ctrl+Enter>.

7. Select cells E2:E10 and type the following formula: =RANK.AVG(B2,$B$2:$B$10).

8. Press <Ctrl+Enter>.

FIGURE 5–18

NOTE 1

If you want to rank in ascending order add a 1 or TRUE as the third parameter. An example would be =RANK.EQ(B2,$B$2:$B$10,1).

NOTE 2

You will also notice that some of the RANK.AVG column contains decimals. Because there are ties, instead of putting the ties at the same rank, the RANK.AVG function “averages” the ranks the same values as a group will take up. There are two examples of this: two $2,000 days and three $6,000 days. For the former, the two $2,000 days take the 7th and 8th rank resulting in (7+8)/2 or 7.5; the three $6,000 days take up the 2nd, 3rd, and 4th ranks resulting in an average (2+3+4)/3 or 3.

USE THE MEDIAN FUNCTION TO CALCULATE THE MEDIAN SALES

In this example, the average and median sales for a month need to be determined. Use the data shown in Figure 5–19 and calculate the average sales in cell E2. To calculate the median of the sales, use the MEDIAN function. The median is a value in the middle of a set of values; i.e., half the values are above the median and half the values are below it.

MEDIAN(number1, number2, ...)

number1, number2,…: From 1 to 30 numbers for which you want to find the median.

To calculate the median sales:

1. In cells A2:A13, type the months.

2. In cells B2:B13, type the monthly sales.

3. Select cell E1 and type the following formula: =MEDIAN(B2:B13).

4. Press <Enter>.

FIGURE 5–19

NOTE 1

You can find the average, as shown in cell E2, by using the formula =AVERAGE(B2:B13).

NOTE 2

If there are an odd number of values, say 13, the MEDIAN will be the middle number in a sorted listed. If there are an even number as in this example, 12, the MEDIAN will be the average of the two middle numbers of a sorted list.

USE THE QUARTILE, QUARTILE.INC, QUARTILE.EXC FUNCTIONS TO CALCULATE QUARTILES

The QUARTILE, QUARTILE.INC, and QUARTILE.EXC functions return the quartile of a data set. Quartiles are used to divide populations into four classes, each containing one-fourth of the total population. As is the RANK function, the QUARTILE function is now considered a compatibility function which may eventually not be included in future Excel versions. It only exists for compatibility with older versions of Excel. QUARTILE.INC and QUARTILE.EXC are the updated versions with slightly different functionality.

QUARTILE(array, quart), QUARTILE.INC(array, quart), QUARTILE.EXC(array, quart)

array: An array or cell range of numeric values for which you want to find the quartile value.

quart: For QUARTILE and QUARTILE.INC, a number from 0 to 4 that specifies the value to return. (0 = Minimum value, 1 = First quartile (25th percentile), 2 = Median value (50th percentile), 3 = Third quartile (75th percentile), 4 = Maximum value).

For QUARTILE.EXC, a number from 1 to 3 that specifies the value to return. (1 = First quartile (25th percentile), 2 = Median value (50th percentile), 3 = Third quartile (75th percentile).

As a result of this distinction in the “quart” parameter, QUARTILE.INC and QUARTILE.EXC will produce slightly different results.

To determine the quartiles into which employee telephone use falls:

1. In cells A2:A10, type the names of your employees.

2. In cells B2:B10, type the number of phone calls each employee makes per month.

3. In cell E2, type the following formula: =QUARTILE($B$2:$B$10,0).

4. In cell E3, type the following formula: =QUARTILE($B$2:$B$10,1).

5. In cell E4, type the following formula: =QUARTILE($B$2:$B$10,2).

6. In cell E5, type the following formula: =QUARTILE($B$2:$B$10,3).

7. In cell E6, type the following formula: =QUARTILE($B$2:$B$10,4).

8. In cell F2, type the following formula: =QUARTILE.INC($B$2:$B$10,0).

9. In cell F3, type the following formula: =QUARTILE.INC($B$2:$B$10,1).

10. In cell F4, type the following formula: =QUARTILE.INC($B$2:$B$10,2).

11. In cell F5, type the following formula: =QUARTILE.INC($B$2:$B$10,3).

12. In cell F6, type the following formula: =QUARTILE.INC($B$2:$B$10,4).

13. In cell G3, type the following formula: =QUARTILE.INC($B$2:$B$10,1).

14. In cell G4, type the following formula: =QUARTILE.INC($B$2:$B$10,2).

15. In cell G5, type the following formula: =QUARTILE.INC($B$2:$B$10,3).

FIGURE 5–20

USE THE STDEV, STDEV.S, STDEV.P FUNCTIONS TO DETERMINE THE STANDARD DEVIATION

In this example, the standard deviation of the number of phone calls must be determined. Use the STDEV, STDEV.S, and STDEV.P functions for this purpose. STDEV is a compatibility function is replaced by the STDEV.S and the STDEV.P functions each with slightly different output. This function measures how widely values in a set differ from the average, or mean, value.

The “P” in STDEV.P stands for POPULATION and will output a standard deviation as if the provided input range of numbers is the exact group of numbers in the population. In other words, if we pass it a range of 10 numbers, then the output is the exact standard deviation for those ten numbers.

The “S” in STDEV.S stands for SAMPLE and will output a standard deviation as if the provided input range of numbers is a sample from a larger set of numbers. If we, for example, pass the function a range of 10 numbers, the function treats this as if these 10 numbers are part of a larger set of numbers; therefore, the Standard Deviation using the STDEV.S will always be larger than the STDEV.P, because there is more uncertainty about the standard deviation since we do not have all the numbers.

STDEV(number1, number2, ...), STDEV.S(number1, number2, ...), STDEV.P(number1, number2, ...)

number1, number2, ...: From 1 to 255 numerical arguments that represent a population sample.

To determine the standard deviation for employee phone calls:

1. In cells A2:A10, type the names of your employees.

2. In cells B2:B10, type the number of phone calls each employee makes per month.

3. Select cell E1 and type the following formula: =AVERAGE(B2:B10).

4. Press <ENTER>.

5. Select cell E2 and type the following formula: =STDEV(B2:B10).

6. Press <ENTER>.

7. Select cell E3 and type the following formula: =STDEV.S(B2:B10).

8. Press <ENTER>.

9. Select cell E4 and type the following formula: =STDEV.P(B2:B10).

10. Press <Enter>.

FIGURE 5–21

USE THE FORECAST.LINEAR FUNCTION TO DETERMINE FUTURE VALUES

In this example, a farm sells milk by the gallons and in order to estimate how much they require in future months, the FORECAST.LINEAR function can be used. By inputting the gallons that have been sold (demand) in past months, the farm can determine an estimate of how many gallons will be demanded in the months ahead. This is a simple estimation and ahead in the chapter, we can determine the confidence of the accuracy of this estimation. But for now we simply get a starting estimate for the rest of the year. As so, we will use a “linear” type of forecast which assumes each month will following a linear pattern of the previous months.

FORECAST.LINEAR(X,Known_ys,Known_xs)

X is the point, in this case a date, for which you wish to predict a value. The point must be a natural progression from its previous values. In other words, a numeric progression that is even with the rest; follow a pattern a consistent time period. Known_ys are the gallons sold in the past and Known_xs are the dates.

To determine the number of gallons that will be demanded from September 2017 to December 2017, assume the farm just completed August and have real data of the number of gallons sold from January to August.

1. In cells A2:13, type a period of time – in this example we used the first day of each month in the year.

2. In cells B2:B9, type in the number of gallons sold for each month from January to August. Leave September thru December blank as we will be predicting the gallons sold for each of these months.

3. Highlight cells B10 to B13 and type the following formula in the formula bar: =FORECAST.LINEAR($A10,$B$2:$B$9,$A$2:$A$9).

4. Press <Ctrl-Enter>.

FIGURE 5–22

USE THE FORECAST.ETS FUNCTION TO DETERMINE FUTURE VALUES

Using the same example of gallons of milk sold over time in the previous example, Instead of using a linear forecasting model which assumes the same trend in the future as in the past, we now use an exponential forecasting tool which forecasts the future based upon greater attention to the difficulties of the past. By using the exponential method, we are assuming in this example that the values will not always increase in future months.

FORECAST.ETS(Target_date, Values, Timeline, [Seasonality], [Data_completion])

Target_date is the current date for which we are determining a future value, the Values are the known gallons sold in previous months and the Timeline is the previous months in which we know the number of gallons sold. Seasonality is an optional value that helps determine previous groupings of difficulties. Its default value is 1, meaning in this example the formula will treat each month as a “season” – you could enter a 2, 3 or 4, for example, to look at several months as a season. The final parameter which is optional is the Data_completion which will be either 1 or 0: a 1 forces the formula to interpolate a value for a given date that is blank or zero; if you place a 0 for this parameter, it will use a zero value which can, at least in our example, produce wide variances in future predictions. For this example, we will use the defaults for Seasonality and Data_completion

To determine the number of gallons that will be demanded from September 2017 to December 2017, assume the farm just completed August and have real data of the number of gallons sold from January to August.

1. In cells A2:13, type a period of time – in this example we used the first day of each month in the year.

2. In cells B2:B9, type in the number of gallons sold for each month from January to August. Leave September thru December blank as we will be predicting the gallons sold for each of these months.

3. Highlight cells B10 to B13 and enter the following formula in the formula bar: =FORECAST.ETS($A10,$B$2:$B$9,$A$2:$A$9).

4. Press <Ctrl-Enter>.

FIGURE 5–23

USE THE FORECAST.ETS.CONFINT FUNCTION TO DETERMINE CONFIDENCE IN FUTURE VALUES

Using the previous example, we arrive at future values based on previous values. But how accurate are these future numbers? What confidence do we have in using these predictions for our farm business? For this confidence determination, we use the FORECAST.ETS.CONFINT which contains in it a confidence level. The values derived are a plus or minus range based upon a confidence interval. For example, we wish to determine with a 90% confidence level the lowest or highest number of gallons that are sold for future months.

FORECAST.ETSCONFINT(Target_date, Values, Timeline, [Seasonality], [Data_completion])

Target_date is the current date for which we are determining a future value, the Values are the known gallons sold in previous months and the Timeline is the previous months in which we know the number of gallons sold. Confidence_level is how much confidence we wish to insert into our final values. A common value used by most statisticians is 95%, but for our example we will use 90% - meaning that we have 90% confidence in the values that are calculated. Seasonality is the same parameter used in the FORECAST.ETS function described in the previous example and is an optional value that helps determine previous groupings of difficulties.

With a 90% confidence level, what is the lowest predicted value of gallons sold and what is the highest predicted value of gallons sold for the future months of September to December?

1. Use columns A-B from the previous example, highlight cells C10 to C13 then enter the following formula in the formula bar: =FORECAST.ETS.CONFINT($A10,$B$2:$B$9,$A$2:$A$9,0.9).

2. Press <Ctrl-Enter>.

3. Highlight cells D10 to D13, enter the formula =B10-C10

4. Highlight cells E10 to E13, enter the formula =B10+C10.

Columns D and E now display the mininum and maximum number of gallons predicted to be sold based upon a 90% confidence level.

FIGURE 5–24

USE THE FORECAST.ETS.SEASONALITY FUNCTION TO FUTURE VALUE PATTERNS

Using the previous example with the future values entered in for the months from September to December, let us determine if there are any patterns during the entire period. We can then use this as a number for the Seasonality parameter that is optional in the other FORECAST.ETS functions. Since many times patterns are not month to month (or period to period), we can attain a more accurate future value if we know the time length of a pattern. Sometimes it can be one month and sometimes it can mimic the weather patterns of three months. Whatever the case, the FORECAST.ETS.SEASONALITY function assists us in determining a pattern for a more accurate prediction of the future.

FORECAST.ETS.SEASONALITY(Values, Timeline, [Data_completion], [Aggregation])

Values are the known gallons sold in previous months and the Timeline is the previous months in which we know the number of gallons sold. Data_completion is used to fill in blanks or zeros of missing data or to exclude them. Aggregation is to either aggregate or average values with the same date. In this case, we have different dates for each value.

In this example, we know the number of gallons of Milk sold from January to August. So, what is the pattern from month to month? Does it increase, decrease or is the pattern grouped by a number of months?

1. Enter the following formula for cell E2 in the formula bar: =FORECAST.ETS.SEASONALITY(B$2:$B$9,$A$2:$A$9).

2. Press <Ctrl-Enter>.

Cell E2 tells us that, in general, the pattern of number of gallons sold repeats itself every two periods (in this case months). We can then input this number in the optional Seasonality parameter of the previously explained FORECAST functions.

FIGURE 5–25

USE THE CORREL FUNCTION TO DETERMINE DATA CORRELATION

Sometimes we need to know how accurate a forecasting model is or how accurately we can predict values in a formula. In order to determine this, we can measure the correlation between two data sets. In other words, how accurate does one set of data points determine the value of another set of data points. We use three examples to show the value of correlation.

When determining a correlation between two sets of numbers, the range in correlation will be between −1 and 1. The closer to either −1 or 1, the better the predictability of the data set. The closer to zero, means the two sets of data are not at all related. Furthermore, if the two sets of data approach 1 or −1, the two data sets are highly correlated and either data set will be a good predictor of the other data set when used in a forecasting model. The difference between 1 and −1 is positive or negative correlation. In other words, if two data sets have a correlation of 1, they are positively correlated in the same direction. If the two data sets approach −1, they are correlated in opposite directions and are said to be negatively correlated. The examples will clarify. In each example, you are comparing two sets of numbers to determine how much the X numbers can predict a Y number.

1. In cell D4, type the formula: =CORREL(B4:B8,C4:C8)

2. In cell H4, type the formula: =CORREL(F4:F8,G4:G8)

3. In cell L4, type the formula: =CORREL(J4:J8,K4:K8)

In the first example, the numbers are highly correlated in the positive direction. In other words, if we plug a 6 as an X in the formula used to calculate Y using X, there is a high probability that Y will be a 6 also.

Data Set 2 shows us how two sets of numbers are negatively correlated. If we enter another number such as 6 in the formula that links X to Y, chances are the value of Y will be 0. They are highly correlated, but in the opposite direction.

Data Set 3 group of numbers are not at all correlated meaning that whatever number we enter for X, it will be difficult to estimate a Y. This is usually the case when the correlation value is between −.5 and .5.

FIGURE 5–26

USE THE AVERAGE, GEOMEAN, HARMEAN, TRIMMEAN TO DETERMINE MEANINGFUL AVERAGES

Depending on the type of data you are averaging, there are four different average (or mean) functions that you can use to provide more meaning to your analysis. Taking the simple average price of a house over a period of 30 years does not provide, as itself, information we can use. But if we could average the relationship between prices as they grew over the years, we might have more useful information.

Some averages may be more useful if we excluded the extremely high or low values because these may be considered anomalies.

In this section we are going to compare the following averages:

AVERAGE(enter 255 numbers or a range) – this is the “mean” or simple average that most people think of when we add up all the values and divide by the number of values.

GEOMEAN(enter 255 numbers or a range) – this is used when the numbers depend on each other in some manner: examples would be viewing inflation or stock prices over a number of years. Each year is loosely connected to the previous year and the next year.

HARMEAN(enter 255 numbers or a range) – this is an average of numbers that gives more weight to the smaller numbers in the set. Or said another way, reduces the impact of larger numbers in the set. This is used a lot in average ratios, for example.

TRIMMEAN(array, fraction to exclude from the average) – this is an average the same as AVERAGE except that you are excluding a percentage of the extremely high and small numbers.

1. In a worksheet, copy the range A1:D12 shown in Figure 5–27.

2. In the same worksheet, copy the range H3:H7 shown in Figure 5–27.

3. In cell E3, type the following formula: = AVERAGE($B$2:$B$12).

4. Press <Enter>.

5. In cell E4, type the following formula: = MEDIAN($B$2:$B$12).

6. Press <Enter>.

7. In cell E5, type the following formula: =GEOMEAN($B$2:$B$12).

8. Press <Enter>.

9. In cell E6, type the following formula: =HARMEAN($B$2:$B$12).

10. Press <Enter>.

11. In cell E7, type the following formula: =TRIMMEAN($B$2:$B$12, 0.2).

12. Press <Enter>.

13. In cell F5, type the following formula: =(B2*B3*B4*B5*B6*B7*B8*B9*B10*B11*B12)^(1/11).

14. Press <Enter>.

15. In cell F6, type the following formula: =11/((1/B2)+(1/B3)+(1/B4)+(1/B5)+(1/B6)+(1/B7)+(1/B8)+(1/B9)+(1/B10)+(1/B11)+(1/B12)).

16. Press <Enter>.

17. In cell F7, type the following formula: =AVERAGE(B3:B11).

18. Press <Enter>.

FIGURE 5–27

NOTE

Cells F5:F7 contain the raw formulas of how the GEOMETRIC, HARMONIC, and TRIM means are calculated.

CHAPTER 6

MATHEMATICAL FUNCTIONS

USE THE SUM FUNCTION TO SUM A RANGE

In this example, all values of a range in a worksheet need to be added, with the sum appearing in cell A11. To do this, use the SUM function, which returns the sum of all numbers in a range of cells.

SUM(number1, number2, ...)

number1, number2, ...: From 1 to 30 arguments to be summed. Cell references are also valid.

To sum a range:

1. In cells A1:A10, enter any values from 1 to 100. Figure 6–1 shows that we used dollar amounts.

2. In cell A11, type the following formula: =SUM(A1:A10).

3. Press <Enter>.

FIGURE 6–1

NOTE

To perform this task a little faster, just select cell A11 and click on the ∑ icon (AutoSum) in the Editing bar under the Home tab. Then press <Enter> to display the result of the calculation.

USE THE SUM FUNCTION TO SUM SEVERAL RANGES

To sum several ranges, simply refer to each of them, separated by commas, using the SUM function from the previous tip.

To sum several ranges:

1. In cells A2:A10, enter prices from $1 to $100.

2. Select cells B2:B10 and type the formula =A2*8% to calculate the tax amount.

3. Press <Ctrl+Enter>.

4. In cells D2:D10, type some discount values from –1 to –3.

5. In cell B12 sum all three columns with the following function: =SUM(A2:A10,B2:B10,D2:D10).

6. Press <Enter>.

FIGURE 6–2

NOTE

To place a border around all cells used in the function, select cell B12 and press <F2>. The function will be displayed as well.

USE THE SUMIF FUNCTION TO DETERMINE SALES OF A TEAM

In this example, all the sales of different teams need to be summed. You can use the SUMIF function to add all cells in a range, specified by a given criterion.

SUMIF(range, criteria, sum_range)

range: A range of cells to be evaluated.

criteria: The criteria that specifies which cells to add. This can be a number, expression, or text.

sum_range: The actual cells to be summed.

To sum specified data:

1. In cells A2:A10, enter a team number from 1 to 3.

2. List all team members in cells B2:B10.

3. In cells C2:C10, enter the daily sales of each employee.

4. List the numbers 1, 2, 3 for each team in cells E2:E4.

5. Select cells F2:F4 and type the following formula: =SUMIF($A$2:$A$10,E2,$C$2:$C$10).

6. Press <Ctrl+Enter>.

FIGURE 6–3

NOTE

Towards the end of this chapter, you will find an upgrade to this function called SUMIFS in which you can add more than one criterion.

USE THE SUMIF FUNCTION TO SUM COSTS HIGHER THAN $1,000

This tip can be used to determine the sum of all phases for which costs are higher than $1,000. To sum just those cells, use the SUMIF function. It adds the cells that are specified by a given criterion.

To sum specified costs:

1. In cells A2:A11, enter the distinct phases.

2. Enter the cost of each phase in cells B2:B11.

3. In cell D1, enter 1000 as the given criterion.

4. Select cell D2 and type the following formula: =SUMIF(B2:B11,">" & D1).

5. Press <Enter>.

FIGURE 6–4

NOTE

If the criteria should not be linked to a cell reference, use this formula: =SUMIF(B2:B11,">1000").

USE THE SUMIF FUNCTION TO SUM COSTS UP TO A CERTAIN DATE

Figure 6–5 contains a dynamic worksheet with daily costs. To sum all costs in a specified timeframe, use the SUMIF function.

To sum costs up to a certain date:

1. In cells A2:A11, list dates from 11/09/10 to 11/18/10.

2. In cells B2:B11, enter the corresponding costs for each day.

3. In cell E1, enter the date 11/16/10.

4. Select cell E2 and type the following formula: =SUMIF(A2:A11,"<=" & E1,B2:B11).

5. Press <Enter>.

FIGURE 6–5

NOTE

To check the calculated result, select cells B2:B9 and watch the displayed sum in the Excel status bar.

USE THE COUNTIF FUNCTION TO COUNT PHASES THAT COST MORE THAN $1,000

In this example, some project phases are listed in a worksheet. To determine how many phases cost more than $1,000, use the COUNTIF function. This function counts the number of cells in a range that meet the specified criteria.

COUNTIF(range, criteria)

range: The range of cells.

criteria: The criterion that specifies which cells to count. This can be a number, expression, or text.

To count specified phases:

1. In cells A2:A11, enter the distinct phases.

2. Enter the costs of each phase in cells B2:B11.

3. In cell D1 enter 1000 as the given criterion.

4. Select cell D2 and type the following formula: =COUNTIF(B2:B11,">" & D1).

5. Press <Enter>.

FIGURE 6–6

NOTE 1

If the criteria should not be linked to a cell reference, use this formula: =COUNTIF(B2:B11,">1000").

NOTE 2

Towards the end of this chapter, you will find an upgrade to this function called COUNTIFS in which you can add more than one criterion.

USE THE COUNTIF FUNCTION TO CALCULATE AN ATTENDANCE LIST

For this task, an attendance list needs to be generated and the number of those who are present each day determined. Generate the list shown in Figure 6–7. Column A contains the dates, and column B uses the user-defined format DDD to determine the day of the week. In columns C to G, the letter “X” is entered for each person in attendance.

To calculate the attendance for each day:

1. Select cells H2:H11 and type the formula =COUNTIF(C2:G2,"X") to get the attendance for each day.

2. Press <Ctrl+Enter>.

3. Select cells C13:G13 and type the formula =COUNTIF(G2:G11,"X") to count the attendance of each employee.

4. Press <Ctrl+Enter>.

FIGURE 6–7

USE THE SUMPRODUCT FUNCTION TO CALCULATE THE VALUE OF THE INVENTORY

In this example, the costs of all products in a warehouse need to be summed to obtain the value of the entire inventory. To do this, use the SUMPRODUCT function. This function multiplies corresponding components in the given arrays and returns the sum of those products.

SUMPRODUCT(array1, array2, array3, ...)

array1, array2, array3, ...: From 2 to 30 arrays whose components are to be multiplied and then added.

To calculate the inventory value:

1. Enter the data shown in columns A and B in Figure 6–8. The quantity of each product is listed along with the cost of each unit.

2. Select cell B12 and type the following formula: =SUMPRODUCT(B2:B10,A2:A10).

3. Check the result by selecting cells D2:D10 and typing the following formula: =A2*B2.

4. Press <Ctrl+Enter>.

5. Sum this range in cell D12.

FIGURE 6–8

USE THE SUMPRODUCT FUNCTION TO SUM SALES OF A TEAM

The worksheet below contains the sales of different teams. As discussed earlier, summing the sales of each team can be done with the SUMIF function. Another way to get a result is by using the SUMPRODUCT function.

To sum the sales of Team 1:

1. Use the values in Figure 6–9 to fill in columns A and B.

2. Select cell B12 and type the following formula: =SUMPRODUCT((A2:A10=1)*(B2:B10)).

3. To check the result, select cells D2:D10 and type the following formula: =IF(A2=1,B2,"").

4. Press <Ctrl+Enter> to enter the formula in the selected range of cells.

5. Select cell D12 and enter the following formula: =SUM(D2:D10).

FIGURE 6–9

USE THE SUMPRODUCT FUNCTION TO MULTIPLY AND SUM AT THE SAME TIME

The salary of each team needs to be calculated. The teams’ numbers, daily working hours, and daily payment are recorded in a table. To calculate the total salary for each team, the working hours need to be multiplied by the payment and summed for each day worked. Use the SUMPRODUCT function to get the result.

To multiply and sum in one operation for each team:

1. In a worksheet, copy the range A2:E11 shown in Figure 6–10.

2. Select cells C13:C15 and type the following formula: =SUMPRODUCT((($C$2:$C$11=B13)*($E$2:$E$11))).

3. Press <Ctrl+Enter>.

FIGURE 6–10

USE THE ROUND FUNCTION TO ROUND NUMBERS

In this example, all numbers need to be rounded. Use the Excel built-in ROUND function to round a number to a specified number of digits.

ROUND(number, num_digits)

number: The number to be rounded.

num_digits: The number of digits the number will be rounded to. If greater than 0, the number is rounded to num_digits decimal places. If 0, the number is rounded to the nearest integer. If less than 0, the number is rounded to the left of the decimal point.

To round numbers:

1. In cells A2:A10, enter numbers with a decimal point.

2. In cells B2:B10, enter the number of decimal places the number should be rounded to.

3. Select cells C2:C10 and type the following formula: =ROUND($A2,$B2).

4. Press <Ctrl+Enter>.

FIGURE 6–11

USE THE ROUNDDOWN FUNCTION TO ROUND NUMBERS DOWN

To cut off numbers to a specific decimal place or round numbers down in a worksheet, use the ROUNDDOWN function. This function rounds a number down, toward zero.

ROUNDDOWN(number, num_digits)

number: Any real number to be rounded down.

num_digits: The number of digits the number will be rounded down to. If greater than 0, the number is rounded to num_digits decimal places. If 0, the number is rounded to the nearest integer. If less than 0, the number is rounded to the left of the decimal point.

To round down numbers:

1. In cells A2:A10, enter numbers with a decimal point.

2. In cells B2:B10, enter the number of decimal places the number should be rounded down to.

3. Select cells C2:C10 and type the following formula: =ROUNDDOWN($A2,$B2).

4. Press <Ctrl+Enter>.

FIGURE 6–12

USE THE ROUNDUP FUNCTION TO ROUND NUMBERS UP

Like the ROUNDDOWN function explained in the previous tip, the ROUNDUP function can be used to round up numbers in a worksheet.

ROUNDUP(number, num_digits)

number: Any real number to be rounded up.

num_digits: The number of digits the number will be rounded up to. If greater than 0, the number is rounded to num_digits decimal places. If 0, the number is rounded to the nearest integer. If less than 0, the number is rounded to the left of the decimal point.

To round up numbers:

1. In cells A2:A10, enter numbers with a decimal point.

2. In cells B2:B10, enter the number of decimal places the number should be rounded up to.

3. Select cells C2:C10 and type the following formula: =ROUNDUP($A2,$B2).

4. Press <Ctrl+Enter>.

FIGURE 6–13

USE THE ROUND FUNCTION TO ROUND TIME VALUES TO WHOLE MINUTES

A worksheet contains time values including hours, minutes, and seconds as shown in Figure 6–14. The task is to round the minutes to whole minutes by using the standard ROUND function. Note that a day has 24 hours, which is 1,440 minutes.

To round different time values to whole minutes:

1. In cells A2:A10, list some time values in this format: 12:02:59 a.m.

2. Select cells B2:B10 and type the following formula: =ROUND(A2*1440,0)/1440.

3. Press <Ctrl+Enter>.

FIGURE 6–14

USE THE ROUND FUNCTION TO ROUND TIME VALUES TO WHOLE HOURS

As in the previous tip, a worksheet contains time values including hours, minutes, and seconds as shown in Figure 6–15. To round these time values to whole hours, use the standard ROUND function. Recall that a day has 24 hours.

To round time values to whole hours:

1. In cells A2:A10 list some time values in this format: 12:02:59 a.m.

2. Select cells B2:B10 and type the following formula: =ROUND(A2*24,0)/24.

3. Press <Ctrl+Enter>.

FIGURE 6–15

USE THE MROUND FUNCTION TO ROUND PRICES TO 5 OR 25 CENTS

In this example, prices need to be rounded to the nearest 5 or 25 cents. Use the MROUND function, which returns a number rounded to the desired multiple.

MROUND(number, multiple)

number: The value to be rounded.

multiple: The multiple to which the number will be rounded.

To round prices to a multiple of 5 or 25 cents:

1. In cells A2:A10, list some prices with a decimal point.

2. Select cells B2:B10 and type the following formula: =MROUND(A2,0.05).

3. Press <Ctrl+Enter>.

4. Select cells C2:C10 and type the following formula: =MROUND(A2,0.25).

5. Press <Ctrl+Enter>.

FIGURE 6–16

NOTE

To use this function, you need to have the Analysis ToolPak installed and loaded. From the Tools menu, select the Add-Ins option. Select the desired add-in and click OK.

USE THE MROUND FUNCTION TO ROUND VALUES TO THE NEAREST MULTIPLE OF 10 OR 50

Sometimes it is necessary to round up values to the nearest multiple of 10 or 50. To perform this task, use the MROUND function from the Analysis ToolPak add-in. MROUND returns a number rounded to the desired multiple.

To round values to the nearest multiple of 10 or 50:

1. In cells A2:A10, list any kind of values.

2. Select cells B2:B10 and type the following formula: =MROUND(A2,10).

3. Press <Ctrl+Enter>.

4. Select cells C2:C10 and type the following formula: =MROUND(A2,50).

5. Press <Ctrl+Enter>.

FIGURE 6–17

NOTE

To use this function, you need to have the Analysis ToolPak installed and loaded as described in the previous tip.

USE THE CEILING/CEILING.MATH FUNCTIONS TO ROUND UP PRICES TO THE NEAREST $100

For this example, all prices need to be rounded up to whole $100 units. To do this, use the CEILING or CEILING.MATH function. The CEILING function is a compatibility function and will eventually be replaced by the CEILING.MATH function. These functions return a number that is rounded up to the nearest multiple of significance. The CEILING.MATCH function has the added parameter of rounding towards zero or away from zero for negative numbers.

CEILING(number, significance)

number: The value to be rounded.

significance: The multiple to which the number will be rounded up.

CEILING.MATH(number, significance, mode)

number: The value to be rounded.

significance: The multiple to which the number will be rounded up.

mode: FALSE or 0 will round a negative number towards 0 while TRUE or 1 will round a negative number away from 0

To round up values to multiples of $100:

1. In cells A2:A10, list some prices.

2. Select cells B2:B10 and type the following formula: =CEILING(A2,100).

3. Select cells C2:C10 and type the following formula: =CEILING.MATH(A2,100,FALSE).

4. Press <Ctrl+Enter>.

5. Select cells D2:D10 and type the following formula: =CEILING.MATH(A2,100,TRUE).

6. Press <Ctrl+Enter>.

FIGURE 6–18

NOTE

CEILING.MATH using FALSE as the mode parameter yields the exact same values CEILING.

USE THE FLOOR/FLOOR.MATH FUNCTION TO ROUND DOWN PRICES TO THE NEAREST $100

As seen in the previous example, it is easy to round up prices to multiples of $100. To round numbers down to the nearest multiple of significance, use the FLOOR or the FLOOR.MATH function. Like the CEILING function, the FLOOR function will also eventually not be available. The only difference between the two is the FLOOR.MATH has an extra parameter that describes how to round negative numbers – they can round either away from zero or towards zero.

FLOOR(number, significance)

number: The value to be rounded.

significance: The multiple to which the number will be rounded down.

FLOOR.MATH(number, significance, mode)

number: The value to be rounded.

significance: The multiple to which the number will be rounded down.

mode: FALSE or 0 will round a negative number away from 0 while TRUE or 1 will round a negative number towards 0.

To round down values to multiples of $100:

1. In cells A2:A10, list some prices.

2. Select cells B2:B10 and type the following formula: =FLOOR(A2,100).

3. Press <Ctrl+Enter>.

FIGURE 6–19

NOTE

The mode parameters in the CEILING.MATH and the FLOOR.MATH functions are the opposite. A FALSE or 0 in CEILING.MATH rounds the number towards zero the FLOOR.MATH mode parameter uses FALSE to round a number away from zero. The converse is true if the parameters are set to TRUE or 1.

USE THE PRODUCT FUNCTION TO MULTIPLY VALUES

Normally, values in a worksheet are multiplied with the * operator in formulas like =A1*B1. However, Excel also provides a useful function to do the same calculation. Use the PRODUCT function to multiply all the given numbers and return the product.

PRODUCT(number1, number2, ...)

number1, number2, ...: From 1 to 30 numbers to be multiplied.

As an example, calculate a price reduction with the PRODUCT function using a standard factor in cell D1.

To calculate the price reduction:

1. In cells A2:A10, list some prices.

2. Enter in cell D1 the value 0.15 to calculate a 15% price reduction.

3. Select cells B2:B10 and type the following formula: =PRODUCT(A2,$D$1).

4. Press <Ctrl+Enter>.

FIGURE 6–20

USE THE PRODUCT FUNCTION TO MULTIPLY CONDITIONAL VALUES

In this example, values are listed in columns A and B. Excel should calculate the product of each value in a row, but only if both values exist. If one or both values are missing, the result is an empty cell, as shown in column C. To get the desired results, use the PRODUCT function in combination with the IF and OR functions as described below.

To multiply conditional values:

1. In cells A2:A10 enter some numbers for value 1.

2. In cells B2:B10 enter some numbers for value 2.

3. Select cells C2:C10 and type the following formula: =IF(OR(A2="",B2=""),"",PRODUCT(A2,B2)).

4. Press <Ctrl+Enter>.

FIGURE 6–21

NOTE

The following formula produces the same result: =IF(OR(A2="",B2=""),"", A2 * B2).

USE THE QUOTIENT FUNCTION TO RETURN THE INTEGER PORTION OF A DIVISION

The opposite of PRODUCT, which was used in the previous tip, is QUOTIENT. This function calculates the integer portion of a division operation and discards the remainder. To use this function, you must first install and load the Analysis ToolPak add-in.

QUOTIENT(numerator, denominator)

numerator: The dividend.

denominator: The divisor.

To calculate the integer portion:

1. Select cells A2:A10 and enter the number 100.

2. Press <Ctrl+Enter>.

3. In cells B2:B10, enter any values as the divisors.

4. Select cells C2:C10 and type the following formula: =QUOTIENT(A2,B2).

5. Press <Ctrl+Enter>.

FIGURE 6–22

NOTE

To avoid incorrect calculations (division with zero) and the error value shown in cells C5 and C10, use the following formula: =IF(ISERROR(QUOTIENT(A10,B10)),"",QUOTIENT(A10,B10)).

USE THE POWER FUNCTION TO CALCULATE SQUARE AND CUBE ROOTS

To raise numbers to the power of another number, the POWER function is used. It can also be used to calculate the root.

POWER(number, power)

number: The base number, which can be any real number.

power: The exponent.

NOTE

The operator ^ can be used instead of POWER, so =POWER(3,2) could be written like this: =3^2.

To calculate roots using the POWER function:

1. In cells A2:A10, list some values.

2. Select cells B2:B10 and type the formula =POWER((A2),1/2) to calculate the square root.

3. Press <Ctrl+Enter>.

4. Select cells C2:C10 and type the formula =POWER((A2),1/3) to calculate the cube root.

5. Press <Ctrl+Enter>.

FIGURE 6–23

NOTE

To use the ^ operator, type =A2^(1/2) to calculate the square root and =A2^(1/3) to determine the cube root.

USE THE POWER FUNCTION TO CALCULATE INTEREST

Imagine you won $1,000 and wanted to save it in a bank account. Depending on the bank, the account could earn 2.5% to 5% in interest compounded annually. How many dollars would be in the bank account after several years if you saved it and did not touch it? Follow along with this example to find out.

To calculate the total amount of money saved depending on the interest rate:

1. Select cells A2:A10 and enter $1,000 as the starting amount.

2. Press <Ctrl+Enter>.

3. In cells B2:B10, enter different interest rates.

4. In cells C2:C10, enter the number of years the money will be saved.

5. Select cells D2:D10 and enter the following formula: =A2*POWER((1+B2/100),C2).

6. Press <Ctrl+Enter>.

FIGURE 6–24

USE THE MOD FUNCTION TO EXTRACT THE REMAINDER OF A DIVISION

This example contains the value 100 in cells A2:A10 and divisors in column B. The MOD function is used here to find the remainder of a division operation. The result has the same sign as the divisor.

MOD(number, divisor)

number: The number to find the remainder for.

divisor: The number to divide number by.

To extract the remainder of a division operation:

1. Select cells A2:A10 and enter 100.

2. Press <Ctrl+Enter>.

3. In cells B2:B10, enter different divisors.

4. Select cells C2:C10 and type the formula =A2/B2.

5. Press <Ctrl+Enter>.

6. Select cells D2:D10 and type the formula =MOD(A2,B2).

7. Press <Ctrl+Enter>.

FIGURE 6–25

NOTE

The function can also be expressed in terms of the mathematical INT function: MOD(n,d) = n–d*INT(n/d). Notice that the value in cell D10 is incorrect. See the following tip for a way to avoid this.

MODIFY THE MOD FUNCTION FOR DIVISORS LARGER THAN THE NUMBER

As seen in the previous tip, a problem occurs when the divisor is larger than the number for which you want to find the remainder. The result will always be the number itself. To manage this using the MOD function, follow these steps.

Handling divisors that are larger than the number:

1. Select cells A2:A10 and enter 100.

2. Press <Ctrl+Enter>.

3. In cells B2:B10, enter different divisors.

4. Select cells C2:C10 and type this formula: =A2/B2.

5. Press <Ctrl+Enter>.

6. Select cells D2:D10 and type this formula: =MOD(A2,B2)*(A2>B2).

7. Press <Ctrl+Enter>.

FIGURE 6–26

USE THE ROW FUNCTION TO MARK EVERY OTHER ROW

Sometimes it is necessary to mark every other row in a worksheet. Several functions can be used in combination to do this. Use the MOD, ROW, and IF functions together as described below.

To mark every other row:

1. Select cells A1:A10 and type the following formula: =IF(MOD(ROW(),2),"XXX"," ").

2. Press <Ctrl+Enter>.

NOTE

If every other column needs to be marked, use the following formula: =IF(MOD(COLUMN(),2),"XXX"," ").

FIGURE 6–27

NOTE

See Chapter 10, “Conditional Formatting with Formulas,” for additional tips on using the MOD function.

USE THE SUBTOTAL FUNCTION TO PERFORM SEVERAL OPERATIONS

The SUBTOTAL function can be used to calculate subtotals in a list or database. There are different subtotal operations available that are all covered by just one function. The syntax is provided.

To use the SUBTOTAL function for multiple calculations:

1. Copy the data shown in columns A and B in Figure 6–28.

2. Select cells C2:C10 and enter the daily sales of each team.

3. Calculate the average in cell F2 with the following formula: =SUBTOTAL(1,$C$2:$C$10).

4. Calculate the sum in cell F3 with the following formula: =SUBTOTAL(9,$C$2:$C$10).

5. Calculate the lowest sales value in cell F4 with the following formula: =SUBTOTAL(5,$C$2:$C$10).

6. Calculate the maximum value in cell F5 with the following formula: =SUBTOTAL(4,$C$2:$C$10).

FIGURE 6–28

USE THE SUBTOTAL FUNCTION TO COUNT ALL VISIBLE ROWS IN A FILTERED LIST

This example shows a filtered list. The task is to count all visible and used rows. Note that the COUNT and COUNTA functions can also be used in a non-filtered list. However, they also count hidden rows. To get the right result, use the SUBTOTAL function and use “3” as the function_num value. (See this function’s syntax in Chapter 5, “Basic Statistical Functions”.)

To count all visible rows in a filtered list:

1. Generate a filtered list like the one shown in Figure 6–29.

2. Select cell C13 and type the following formula: =SUBTOTAL(3,B2:B10).

3. Press <Enter>.

FIGURE 6–29

USE THE RAND FUNCTION TO GENERATE RANDOM VALUES

To generate randomized values, Excel provides the RAND function. This function returns a random number greater than or equal to 0 and less than 1. Each time the worksheet is calculated, a new random number is generated. This example generates randomized integer values from 1 to 999 in cells A2:D10 and then replaces the formulas with calculated values.

To generate integer random values:

1. Select cells A2:D10 and type the following formula: =INT(RAND()*1000).

2. Press <Ctrl+Enter>.

3. Press <Ctrl+C> to copy the filled cells.

4. In the Home tab, choose the dropdown arrow underneath Paste.

5. From Paste Values, choose Values (V).

FIGURE 6–30

NOTE

The values appearing in Figure 6–30 above will be different than the values you see on your worksheet since the RAND function displays different values each time it is re-calculated. To see new random values, press F9.

USE THE RANDBETWEEN FUNCTION TO GENERATE RANDOM VALUES IN A SPECIFIED RANGE

To generate randomized values in a specified range, such as from 1 to 49, use the RANDBETWEEN function. This function returns a random number in the range you specify, returning a new random number every time the worksheet is calculated. If this function is not available and returns the #NAME? error, install and load the Analysis ToolPak add-in.

RANDBETWEEN(bottom, top)

bottom: The lowest integer in the range.

top: The highest integer in the range.

To create random values from 1 to 49:

1. Select cells A2:D10 and type the following formula: =RANDBETWEEN(1,49).

2. Press <Ctrl+Enter>.

3. Press <Ctrl+C> to copy the filled cells.

4. In the Home tab, choose the dropdown arrow underneath Paste.

5. From Paste Values, choose Values (V).

FIGURE 6–31

NOTE

The values appearing in Figure 6–31 above will be different than the values you see on your worksheet since the RANDBETWEEN function displays different values each time it is re-calculated. To see new random values, press F9.

USE THE RANDARRAY FUNCTION TO GENERATE RANDOM VALUES IN A RANGE OF ROWS AND COLUMNS

RANDARRAY is a function only available in Microsoft 365 and is a variation of the RANDBETWEEN function. With RANDBETWEEN, you need to input this formula in every cell you wish to randomize a number. With RANDARRAY, however, you can input the number of rows and columns you wish to populate with a random number.

RANDARRAY(rows,columns,min,max,integer)

rows: The number of rows you wish to randomize.

columns: The number of columns you wish to randomize. The number of rows and columns tells you how many cells will be randomize. Example, 4 rows X 8 columns will populate 32 cells.

min: The lowest integer/decimal in the range.

max: The highest integer/decimal in the range

integer: TRUE or 1 tells Excel to only output integers while FALSE or 0 or blank will only output decimal numbers.

To create random integers from 100 to 1000 into a range of 5 rows and 5 columns:

1. Select cell A1 and type the following formula: =RANDARRAY(5,5,100,1000,TRUE).

2. Press <Enter>

To create random decimals from 100 to 1000 into a range of 5 rows and 5 columns:

1. Select cell G1 and type the following formula: =RANDARRAY(5,5,100,1000,FALSE).

2. Press <Enter>

FIGURE 6–32

USE THE EVEN AND ODD FUNCTIONS TO DETERMINE THE NEAREST EVEN/ODD VALUE

In addition to the standard functions for rounding up a number, there are other functions available, like EVEN and ODD. For example, to round up a number to the nearest even integer, use the EVEN function.

EVEN(number)

number: The value to be rounded.

To round up a number to the nearest odd value, use the ODD function.

ODD(number)

number: The value to be rounded.

To determine the nearest even/odd value:

1. In cells A2:A10, list some valid numbers with decimal points.

2. Select cells B2:B10 and enter the following function: =EVEN(A2).

3. Press <Ctrl+Enter>.

4. Select cells C2:C10 and enter the following function: =ODD(A2).

5. Press <Ctrl+Enter>.

FIGURE 6–33

USE THE ISEVEN AND ISODD FUNCTIONS TO CHECK IF A NUMBER IS EVEN OR ODD

To find out whether numbers are even or odd, use the ISEVEN or ISODD functions. ISEVEN returns TRUE if the number is even and FALSE if the number is odd, while ISODD returns TRUE if the number is odd and FALSE if the number is even.

ISEVEN(number)

ISODD(number)

number: The value to be evaluated. Non-integer values are truncated.

To check if a number is even or odd:

1. In cells A2:A10, enter some numbers.

2. Select cells B2:B10 and type the following formula: =IF(ISEVEN(A2),"X","").

3. Press <Ctrl+Enter>.

4. Select cell C2:C10 and type the following formula: =IF(ISODD(A2),"X","").

5. Press <Ctrl+Enter>.

FIGURE 6–34

NOTE

To use these functions, you will need to install and load the Analysis ToolPak add-in as described earlier.

USE THE ISODD AND ROW FUNCTIONS TO DETERMINE ODD ROWS

In this example, we need to determine whether a row number in a range is even or odd and then fill each odd row with the character “X.” Use the ISODD function in combination with IF and ROW() to get the result shown in Figure 6–34.

If this function is not available and returns an error, install, and load the Analysis ToolPak add-in.

To determine odd rows and mark them:

1. Select cells A1:E11 and type the following formula: =IF(ISODD(ROW()),"X","").

2. Press <Ctrl+Enter>.

FIGURE 6–35

NOTE

To mark all even rows, use the following formula: =IF(ISEVEN(ROW()),"X","").

USE THE ISODD AND COLUMN FUNCTIONS TO DETERMINE ODD COLUMNS

In this example, we want to determine whether a column’s index in a range is even or odd and then fill each odd row with the character “X.” Use the ISODD function in combination with IF and COLUMN() to get the result shown in Figure 6–35. If this function is not available and returns an error, install, and load the Analysis ToolPak add-in.

To determine odd columns:

1. Select cells A1:E11 and type the following formula: =IF(ISODD(COLUMN()),"X","").

2. Press <Ctrl+Enter>.

FIGURE 6–36

NOTE

To mark even columns, type the following formula: =IF(ISEVEN(COLUMN()),"X","").

USE THE ROMAN FUNCTION TO CONVERT ARABIC NUMERALS TO ROMAN NUMERALS

This tip explains how to convert an Arabic numeral to a Roman numeral. To get this result, use the ROMAN function, which returns the Roman value as text.

ROMAN(number, form)

number: The Arabic numeral to be converted.

form: (optional) A number from 0 to 4 that specifies the type of Roman numeral. Styles range from Classic to Simplified and become more concise (using fewer characters) as the value of form increases. If omitted, the Classic type is used.

To convert Arabic numerals to Roman numerals:

1. In cells A2:A10, enter valid numbers from 1 to 3999.

2. Select cells B2:B10 and type the following formula: =ROMAN(A2,0).

3. Press <Ctrl+Enter>.

FIGURE 6–37

USE THE ARABIC FUNCTION TO CONVERT ROMAN NUMERALS TO ARABIC NUMERALS

This tip explains how to convert a Roman numeral to an Arabic numeral. To get this result, use the ARABIC function, which returns the Arabic value as a number.

ARABIC(text)

text: The Roman numeral to be converted.

To convert Roman numerals to Arabic numerals:

1. In cells A2:A10, enter valid Roman numerals like those shown in Figure 6–37.

2. Select cells B2:B10 and type the following formula: =ARABIC(A2).

3. Press <Ctrl+Enter>.

FIGURE 6–38

USE THE BASE FUNCTION TO CONVERT DECIMAL NUMBERS TO BINARY NUMBERS

This tip explains how to convert the numeric base of a number, for example, from decimal to binary. To get this result, use the BASE function, which returns the numeric value as text in the new base.

BASE(number, radix, min_length)

number: The number value to be converted.

radix: The number representing the base into which the number should be converted. This must be a value from 2 to 36.

min_length: (optional) The minimum length of the returned string. This must be greater than 0.

To convert decimal (base 10) numbers to binary (base 2) numbers:

1. In cells A2:A10, enter valid numbers.

2. Select cells B2:B10 and type the following formula: =BASE(A2,2).

3. Press <Ctrl+Enter>.

FIGURE 6–39

USE THE DECIMAL FUNCTION TO CONVERT BINARY NUMBERS TO DECIMAL NUMBERS

This tip explains how to convert a value in a different numeric base to a decimal number. To get this result, use the DECIMAL function, which returns the decimal numeric value from a number in a different base.

DECIMAL(number, radix)

number: The number value to be converted.

radix: The number representing the base in which the number is represented. This value must be an integer.

To convert binary (base 2) numbers to decimal (base 10) numbers:

1. In cells A2:A10, enter binary numbers such as those used in Figure 6–39.

2. Select cells B2:B10 and type the following formula: =DECIMAL(A2,2).

3. Press <Ctrl+Enter>.

FIGURE 6–40

USE THE SIGN FUNCTION TO CHECK FOR THE SIGN OF A NUMBER

Excel provides the SIGN function to check the sign of a number. This function returns 1 if the number is positive, 0 if the number is 0, and –1 if the number is negative. If the user enters text instead of a number, the SIGN function returns the error code #VALUE!.

SIGN(number).

number: Any real number.

To check for the sign of a number:

1. In cells A2:A10, list numbers or text.

2. Select cells B2:B10 and type the following formula: =IF(ISERROR(SIGN(A2)),"",SIGN(A2)).

3. Press <Ctrl+Enter>.

FIGURE 6–41

NOTE

The same result for numeric values can also be generated by combining IF functions. Use this formula: =IF(A1>0;1;IF(A2<0;–1;0)).

USE THE SUMSQ FUNCTION TO DETERMINE THE SQUARE SUM

Excel provides the SUMSQ function to sum the squares of the arguments.

SUMSQ(number1, number2, ...)

number1, number2, ...: From 1 to 30 arguments that will have their squares summed. Instead of values, you can use a single array or a reference to an array separated by commas.

To determine the square sum:

1. In cells A2:A10, list valid numbers.

2. In cells B2:B10, list valid numbers.

3. Select cells C2:C10 and type the following formula: =SUMSQ(A2,B2).

4. Press <Ctrl+Enter>.

FIGURE 6–42

USE THE GCD FUNCTION TO DETERMINE THE GREATEST COMMON DIVISOR

In this example, the greatest common divisor (GCD) of two integers needs to be determined. To do so, use the GCD function. This function is available only if you have the Analysis ToolPak add-in installed.

GCD(number1, number2, ...)

number1, number2, ...: From 1 to 29 values for which you want to find the greatest common divisor. Non-integer values are truncated.

To determine the greatest common divisor:

1. In cells A2:A10 list any valid numbers.

2. In cells B2:B10 list any valid numbers.

3. Select cells C2:C10.

4. Type the following formula: =GCD(A2,B2).

5. Press <Ctrl+Enter>.

FIGURE 6–43

USE THE LCM FUNCTION TO DETERMINE THE LEAST COMMON MULTIPLE

This example shows how to determine the least common multiple (LCM) of two integers. Excel provides the LCM function through the Analysis ToolPak add-in. You will need to install and load the add-in to perform these steps.

LCM(number1, number2, ...)

number1, number2, ...: From 1 to 29 values for which you want to find the least common multiple. Non-integer values are truncated.

To determine the least common multiple:

1. In cells A2:A10, list any valid numbers.

2. In cells B2:B10, list any valid numbers.

3. Select cells C2:C10 and type the following formula: =LCM(A2,B2).

4. Press <Ctrl+Enter>.

FIGURE 6–44

USE THE SUMIFS FUNCTION TO DETERMINE SALES OF A TEAM AND GENDER OF ITS MEMBERS

This example uses the worksheet referred to in Figure 6–3; however, the table not only sums the sales of different teams but also sums the sales of each team by the gender of each member. You can use the SUMIFS function to add all cells in a range that are specified by several criteria.

The SUMIFS function syntax has the following arguments:

SUMIFS(sum_range, criteria_range1, criteria1, [criteria_range2, criteria2], ...)

sum_range: Required. One or more cells to sum, including numbers or names, ranges, or cells.

criteria_range1: Required. The first range in which to evaluate the associated criteria.

criteria_1: Required. The criteria in the form of a number, expression, cell reference, or piece of text that defines which cells in the criteria_range1 argument will be added.

criteria_range2, criteria2: Optional. Additional ranges and their associated criteria.

To sum specified data:

1. In cells A2:A10, enter a team number from 1 to 3.

2. In cells B2:B10, list the names of all team members.

3. In column C, enter the gender of each salesperson.

4. In cells D2:D10, enter the daily sales of each employee.

5. List the numbers 1, 2, 3, and the sales broken down by gender for each team in cells F2:F7 as shown in Figure 6–44.

6. Select cells H2:H7 and type the following formula: =SUMIFS($D$2:$D$10,$A$2:$A$10,F2,$C$2:$C$10,G2)

7. Press <Ctrl+Enter>.

FIGURE 6–45

NOTE

Up to 127 range/criteria pairs are allowed.

USE THE COUNTIFS FUNCTION TO COUNT PHASES THAT COST MORE THAN $1,000 WITHIN A CERTAIN DURATION

This example uses the worksheet referred to in Figure 6–6 with the addition of the duration of each project phase. To determine how many phases cost more than $1,000 and take two days or less, use the COUNTIFS function. This function counts the number of cells in a range that meet the specified criteria.

COUNTIFS(criteria_range1, criteria1, [criteria_range2, criteria2],…)

criteria_range1: Required. The first range in which to evaluate the associated criteria.

criteria1: Required. The criteria in the form of a number, expression, cell reference, or piece of text that defines which cells will be counted.

criteria_range2, criteria2, ... Optional. Additional ranges and their associated criteria.

To count specified phases:

1. In cells A3:A12, enter the distinct phases.

2. In cells B3:B12, enter the costs of each phase.

3. In cells C3:C12, enter the duration of each phase.

4. Enter 1000 in cell E2 and 2 in cell F2 as the given criteria.

5. Select cell E4 and type the following formula: =COUNTIFS(B3:B12,">" & E2,C3:C12,"<=" & F2).

6. Press <Enter>.

FIGURE 6–46

NOTE

Up to 127 range/criteria pairs are allowed.

COMPARE THE INT, TRUNC, AND ROUND FUNCTIONS

There are different methods in displaying numbers based on the accuracy required. Many financial functions depend on a high degree of accuracy especially when money is involved. Some programs calculate decimals out the the thousands or even further. Other programs do not require as much detail.

In this example, we will detail the differences between the INT, TRUNC, and ROUND functions. First the INT function simply cuts off all decimals and displays the number left of the decimal. The TRUNC functions cuts off all decimal places to the right of where you tell it. The ROUND functions rounds up or down at the decimal place you tell it.

For this example, we have three numbers on which to perform these functions in column B. The numbers across in row 3 are the number of decimals we are including in the TRUNC and ROUND functions. (In this example, we are using the ‘$’ to make it easier to copy and paste formulas without having to change the formulas.)

1. In cell D5, type the formula =INT($B5)

2. In cell E5, type the formula: =TRUNC($B5,E$3) – this tells the cell to cutoff all values to the right of the decimal point listed in cell E3.

3. In cell F5, type the formula: =ROUND($B5,F$3) – this tells the cell to round the value at the decimal point listed in cell E3.

4. Highlight cells D5 to F5, place the cursor over the lower right corner of cell F5 and drag the contents down to cell F7.

5. Highlight cells D5 to F7, right-click and copy.

6. Click in cell H5 and paste

7. Click in cell L5 and paste

You can see that in some instances TRUNC acts like an INT while in other instances TRUNC acts like a ROUND. And yet in other instances such as in our example of truncating to one decimal, it treats numbers in its own manner apart from the other two.

FIGURE 6–47

USE THE ABS FUNCTION TO RETURN ONLY POSITIVE DIFFERENCES BETWEEN NUMBERS

This example uses the ABS (absolute value) function to determine whether car speed is fuel efficient based upon optimal speed and a range above or below the optimal speed. ABS has only one parameter which is any number (decimal or integer)(positive or negative). If a negative number is passed to the function, the negative sign is taken out and the result is the positive number of the original number. Example, ABS(−8.2) = 8.2. If the number passed is a positive number, a positive number is returned.

In this scenario, let us assume that travelling at 60 mph (or 97 km/h) is the speed that provides us the best gas mileage. And let us further assume that if we travel within the range of 56 mph and 64 mph, we still maximize our fuel efficiency.

To determine if we are in the acceptable range of maximum fuel efficiency, from the worksheet depicted in Figure 6–48

1. Copy cells A1:C14 into your worksheet.

2. Select cells D5:D14 and enter the following formula: =C5-$B$1

3. Press <Ctrl+Enter>

4. Select cells E5:E14 and enter the following formula: =IF(ABS(D5)<=$B$2,"Yes","No")

5. Press <Ctrl+Enter>.

FIGURE 6–48

USE THE SQRT FUNCTION TO DETERMINE THE HYPOTENUSE OF A RIGHT TRIANGLE

This example uses the SQRT function to determine the distance of the longest side (or hypotenuse) in a right triangle which is defined as a triangle where one of its angles is 90°. If you wanted to buy a fence to surround a lawn in the shape of a right triangle and you know the measurements of any two sides, you could then calculate the measurement of the third side. Of course, you could measure it physically with many tools, but the goal here is to calculate it. In this example, knowing the two smallest sides of the right triangle, we can calculate the length of the longest side (or hypotenuse).

The following example is based on the Pythagorean Theorem which refers to the relationship between the lengths of the three sides in a right triangle. The sum of the square of the two smaller sides is equal to the square of the hypotenuse stated another way (side1)2 + (side2)2 = (hypotenuse)2.

In our equation we are going to work backwards to discover what the hypotenuse is. Our equation will be hypotenuse equals the square root of the sum of (side1)2 + (side2)2

1. Copy cells A1:B10 from the worksheet in Figure 6–49 and/or enter your own numbers into your worksheet.

2. Select cells C2:C10 and enter the following formula: =SQRT(A2^2+B2^2)

3. Press <Ctrl+Enter>

FIGURE 6–49

USE THE COMBIN FUNCTION TO DETERMINE THE NUMBER OF COMBINATIONS IN A LOTTERY

This example uses the COMBIN function to determine how many combinations exist in a lottery. In a lottery, there are two numbers: the number of selections and the pool of numbers from which to select. For example, in a lottery there may be 49 numbers from which to select but there are only six numbers selected which will be the winning combination.

1. From the worksheet in Figure 6–50, copy cells A1:A4 into your worksheet.

2. In cell B4, enter the following formula: =COMBIN(B2,B1)

3. Press <Enter>

4. In cell B2 enter a number that represents the pool of numbers in a lottery.

5. In cell B1 enter a number less or equal to the number you entered in cell B2 which represents the number of winning numbers.

FIGURE 6–50

USE THE FACT FUNCTION TO DETERMINE THE NUMBER OF COMBINATIONS IN A LOTTERY

This example uses the FACT function to determine how many combinations exist in a lottery. The word FACT is short for factorial which is the multiplication of all whole numbers from the selected number down to one and is denoted with an exclamation point. An example is 5! (or five factorial). The equation is 5 × 4 × 3 × 2 × 1 = 120.

8! (or eight factorial) is 8 × 7 × 6 × 5 × 4 × 3 × 2 × 1 which equals 40,320.

Another calculation to discover the number of combinations in a lottery is yielded by formula P!/(N! * (P-N)!) where P is the pool of numbers available in a lottery and N is the number of numbers that are drawn needed to win the lottery.

1. From the worksheet in Figure 6–51, copy cells A1:A4 into your worksheet.

2. In cell B4, enter the following formula: =FACT(B2)/(FACT(B1)*FACT(B2-B1))

3. Press <Enter>

4. In cell B2 enter a number that represents the pool of numbers in a lottery.

5. In cell B1 enter a number less or equal to the number you entered in cell B2 which represents the number of winning numbers.

FIGURE 6–51

USE THE LET AND IFS FUNCTIONS TO DETERMINE SALES BONUSES

LET is only available in Microsoft 365. The LET function allows you to enter variables with values to be used in a calculation – all are parameters within the LET function. The function was designed to improve performance (fewer calculations) and make formulas easier to read since the function contains everything in one formula.

The function has at least three parameters.

Variable Name: Any name you give a value which will be used in the calculation. This can be a letter or a phrase.

Variable Value: The value you give the variable named previously. This can be a number, formula, or a reference to another cell.

Calculation: A formula that uses the variable name and its value.

You can enter up to 126 Variable Name and Variable Value combinations.

A simple example is LET(x,5,y,6,x+y)

Read it this way. Let variable “x” have a value of 5 and let variable “y” have a value of 6. The last parameter is always the calculation. In this case, either x+y or 5+6 which equals 11. This is a simple example and there are certainly other methods and functions you can use to get the same result. But as stated earlier, this function improves performance and makes it easier to read since it is contained all in the same cell.

1. From the worksheet in Figure 6–52, copy cells A1:H10 into your worksheet.

2. Select cells I2:I10

3. In cell I2, enter the following formula: =LET(T,SUM(F2:H2),IFS(T>=$A$4,T*$C$4,T>=$A$3,T*$C$3,T>=$A$2,T*$C$2))

4. Press <Ctrl+Enter>

5. Select cells J2:J10

6. In cell J2, enter the following formula: =IFS(SUM(F2:H2)>=$A$4,SUM(F2:H2)*$C$4,SUM(F2:H2)>=$A$3,SUM(F2:H2)*$C$3,SUM(F2:H2)>=$A$2,SUM(F2:H2)*$C$2)

7. Press <Ctrl+Enter>

Within the LET statements in column I, the first parameter is the variable ‘T’ which represents the total sales for three months which is defined by the second parameter SUM(F2:H2). We could have named the variable anything such as TOTAL_SALES or X or ZB9939. Usually though you want to name it something meaningful and easy to read. The last parameter is an IFS statement that looks to see in what bonus group the total sales fall. You can see how often “T” is used in the formula (seven times). If we did not have the LET function, we would have to put the SUM(F2:H2) in every instance where “T” is. This is illustrated within the formulas in column J.

FIGURE 6–52

USE THE SEQUENCE FUNCTION TO GENERATE A SEQUENTIAL LIST OF DATES IN A ROW, COLUMN, OR AN ARRAY

To generate a sequential list of numbers in any number of rows or columns, use the SEQUENCE function. The four parameters for the SEQUENCE function are:

SEQUENCE(rows, columns, start, step)

Rows: The number of rows you wish to have in the array

Columns: The number of columns you wish to have in the array

Start: This will be the first number in the sequence – this is optional and defaults to 1 if not provided. This can be a negative number as well as a decimal number.

Step: The incremental value between numbers – this is optional and defaults to 1 if not provided. It can be a negative number as well as a decimal number.

To create a sequence of numbers starting at 1000 and decrementing by 10 in an array of six rows and 4 columns:

1. In cell A1 in a worksheet, type the following formula: =SEQUENCE(6,4,1000,-10)

2. Press <Enter>.

To create a sequence of dates one week a part in an array of 10 rows and 2 columns starting with the date 01/01/2021:

1. In cell G1, type the following formula: =SEQUENCE(10,2,DATE(2021,1,1),7)

2. Press <Enter>.

3. To format these columns into a date, select cells G1:H10,

4. Press <ctrl+1>

5. On the “Number” tab, click on “Date” in the Category box.

6. Select any date format to view the data as a date.

FIGURE 6–53

CHAPTER 7

BASIC FINANCIAL FUNCTIONS

USE THE SYD FUNCTION TO CALCULATE DEPRECIATION

In this tip, we calculate the depreciation of an investment. To do so, use the SYD function, which returns the sum-of-years’ digits depreciation of an asset for a specified period.

SYD(cost, salvage, life, per)

cost: The asset’s initial cost.

salvage: The value of the asset at the end of the depreciation period.

life: The number of periods over which the asset is depreciated.

per: The period. per must use the same units as life.

To calculate depreciation:

1. In cell B1 enter the cost of purchase.

2. In cell B2 enter in years the number of periods over which the purchase will be depreciated.

3. Enter the salvage value in cell B3. This is the value you expect to have at the end of the periods.

4. Calculate the depreciation in the fifth year in cell B5 with the following formula: =SYD($B$1,$B$3,$B$2,5).

5. Press <Enter>.

FIGURE 7–1

NOTE

SYD is calculated as follows: = ((cost–salvage)*(life–per+1)*2) / (life*(life+1)).

USE THE SLN FUNCTION TO CALCULATE STRAIGHT-LINE DEPRECIATION

Here we want to calculate the straight-line depreciation of an investment. Use the SLN function, which returns the straight-line depreciation of an asset for one period.

SLN(cost, salvage, life)

cost: The asset’s initial cost.

salvage: The value of the asset at the end of the depreciation period.

life: The number of periods over which the asset is depreciated.

To calculate depreciation:

1. In cell B1, enter the initial cost.

2. In cell B2, enter the number of periods as years.

3. Enter the salvage in cell B3.

4. Calculate the depreciation in the fifth year in cell B5 with the following formula: =SLN($B$1,$B$3,$B$2).

5. Press <Enter>.

FIGURE 7–2

USE THE PV FUNCTION TO DECIDE AN AMOUNT TO INVEST

In this example, you need to decide on an amount of money you want to invest. To solve this problem, you use the PV function, which returns the present value of an investment. This is the total amount that a series of future payments is worth now.

PV(rate, nper, pmt, fv, type)

rate: The interest rate per period.

nper: The total number of payment periods in an annuity.

pmt: The payment made each period, which is a constant value.

fv: The future value. This is the amount you want after the last payment is made.

type: A number that indicates when payments are due. 0 or omitted indicates the end of the period, and 1 indicates the beginning of the period.

To decide how much to invest:

1. In cell C1, enter the estimated return per year.

2. In cell C2, enter the number of periods in years.

3. In cell C3, enter the interest rate.

4. In cell C4, calculate the maximum investment amount with the following formula: =PV(C3,C2,C1).

5. Press <Enter>.

FIGURE 7–3

USE THE PV FUNCTION TO COMPARE INVESTMENTS

Two investments need to be compared. The amount of each investment, the number of periods, the interest, and the estimated return are given. To calculate and compare, use the PV function as described below.

To compare investments:

1. In cells B2 and C2, enter the investment amounts.

2. In cells B3 and C3, enter the interest rates.

3. In cells B4 and C4, enter the number of periods.

4. In cells B5 and C5, enter the estimated return of each investment.

5. Select cells B7:C7 and type the following formula: =-PV(B3,B4,B5).

6. Press <Ctrl+Enter>.

7. Select cells B8:C8 and type the formula =B7-B2.

8. Press <Ctrl+Enter>.

FIGURE 7–4

NOTE

Investment 2 is more expensive than Investment 1.

USE THE DDB FUNCTION TO CALCULATE USING THE DOUBLE-DECLINING BALANCE METHOD

The DDB function returns the depreciation of an asset for a specified period, using the double-declining balance method or some other method that can be specified.

DDB(cost, salvage, life, period, factor)

cost: The asset’s initial cost.

salvage: The value of the asset at the end of the depreciation period.

life: The number of periods over which the asset is being depreciated.

period: The period for which the depreciation is being calculated.

factor: The rate at which the balance declines. If factor is omitted, it is assumed to be 2, which specifies the double-declining balance method.

To use the double-declining balance method:

1. Enter the initial cost in cell B1, the number of periods in cell B2, and the salvage in cell B3.

2. Calculate the depreciation in the fifth year in cell B4 with the following formula: =DDB($B$1,$B$3,$B$2,5).

3. To calculate the depreciation after one day, type this formula in cell B5: =DDB($B$1,$B$3,$B$2*365,1).

4. To calculate the depreciation after the first month, use this formula in cell B6: =DDB($B$1,$B$3,$B$2*12,1).

FIGURE 7–5

USE THE PMT FUNCTION TO DETERMINE THE PAYMENT OF A LOAN

To determine the payment amount for a loan based on constant payments and a constant interest rate, use the PMT function. You can also determine the total cost of the loan including interest and principal by multiplying the number of periods by the periodic payment.

PMT(rate, nper, pv, fv, type)

rate: The interest rate of the loan.

nper: The total number of payments for the loan.

pv: The present value. This is also referred to as the principal.

fv: The future value. This is the amount you want after the last payment is made. If fv is omitted, it is assumed to be 0.

type: A number that indicates when payments are due. 0 or omitted indicates the end of the period, and 1 indicates the beginning of the period.

To determine the payment for a loan:

1. In cell B1, enter the interest rate.

2. In cell B2, enter the number of periods in months.

3. In cell B3, enter the amount of the loan.

4. In cell B5, calculate the payment after one month with the following formula: =-PMT($B$1/12,$B$2,$B$3).

5. In cell B7, calculate the total cost of the loan after it is paid off. Enter the formula: =$B$2*$B$5

6. Press <Enter>.

FIGURE 7–6

USE THE FV FUNCTION TO CALCULATE TOTAL SAVINGS ACCOUNT BALANCE

In this example, you want to save money for five months. The interest rate is 3.5%. Every month you deposit $500 in the bank. How much money is in your bank account after five months? This question can be answered by using the FV function. It returns the future value of an investment based on periodic, constant payments and a constant interest rate.

FV(rate, nper, pmt, pv, type)

rate: The interest rate per period.

nper: The total number of payment periods in an annuity.

pmt: The payment made each period, which is a constant value.

pv: The present value. This is the amount that a series of future payments is worth right now.

type: A number that indicates when payments are due. 0 indicates the end of the period, and 1 indicates the beginning of the period.

To calculate the total balance of an account with regular deposits and a constant interest rate:

1. Enter the current interest rate in cell B1 and the number of periods in cell B2.

2. In cell B3 enter the monthly amount to be put in the savings account.

3. In cell B4 type the formula =-FV(B1/12,B2,B3).

4. Press <Enter>.

FIGURE 7–7

USE THE RATE FUNCTION TO CALCULATE INTEREST RATE

Let us say a bank advertises that if you deposit $500 each month for 12 years, you will have $100,000 at the end of the period. What is the interest rate the bank is paying? To answer this question, use the RATE function, which returns the interest rate per period of an annuity.

RATE(nper, pmt, pv, fv, type, guess)

nper: The total number of payment periods in an annuity.

pmt: The payment made each period, which is a constant value.

pv: The present value. This is the amount that a series of future payments is worth right now.

fv: The future value. This is the amount you want after the last payment is made.

type: A number that indicates when payments are due. 0 or omitted indicates the end of the period, and 1 indicates the beginning of the period.

guess: A guess for what the interest rate will be. If omitted, Excel uses 10%.

To calculate the interest rate:

1. In cell B1, enter the number of periods in years.

2. In cell B2, enter the monthly amount to deposit.

3. In cell B3, enter the final value the bank has advertised.

4. In cell B5, type the following formula: =RATE(B1*12,-B2,0,B3,0)*12.

5. Press <Enter>.

FIGURE 7–8

USE THE INTRATE FUNCTION TO CALCULATE INTEREST OVER AN ENTIRE PERIOD

Let us say a bank advertises that if you initially deposit $100,000 then in two years you will have $200,000 in your account. What is the interest rate over the entire period? To answer this question, use the INTRATE function, which returns the interest rate for the entire period. This is different than the RATE function which describes the interest rate per period.

INTRATE(nper, pmt, pv, fv, type, guess)

settlement: The initial date of the investment.

maturity: The date you will cash in or the expiration date of the investment.

investment: The initial amount of the investment.

redemption: The amount received when the investment was cashed in.

To calculate the rate over the period (not the annual rate):

1. As in Figure 7–9, copy cells A1:B4 as a start into a blank worksheet.

2. In cell B1, enter the start date of the investment.

3. In cell B2, enter the end date of the investment.

4. In cell B3, enter the one-time investment amount.

5. In cell B4, enter the account balance of the initial investment (cell B3) at the end of the period (cell B2)

6. In cell D1, type the following formula: =INTRATE(B1,B2,B3,B4)

7. Press <Enter>.

FIGURE 7–9

USE THE NOMINAL FUNCTION TO CALCULATE REAL INTEREST RATE GIVEN AN ANNUAL RATE

Let us say a bank advertises that if you deposit any amount of money at a yearly interest rate, that it is actually compounded at certain times of the year. You may see that the interest rate is actually higher than you think. To calculate and to compare with other investments that are calculated differently, you can use the NOMINAL function.

NOMINAL(Effect Rate, Npery)

Effect_rate: The effective interest rate or the yearly interest rate in total.

Npery: The number of the compounding years.

To calculate the true rate of an investment:

1. As in Figure 7–10, copy cells A1:B2 as a start into a blank worksheet.

2. In cell B1, enter the annual rate of return.

3. In cell B2, enter the number of times in a year that the interest is compounded.

4. In cell D1, type the following formula: =NOMINAL(B1,B2)

5. Press <Enter>.

FIGURE 7–10

NOTE

Since an investment is compounded more than once in a year, the true rate is less than an overall rate. If you entered a 1 for the number of times per year the interest is calculated, the rates would be equal.

CHAPTER 8

DATABASE FUNCTIONS

USE THE DCOUNT FUNCTION TO COUNT SPECIAL CELLS

Using this tip, cells in a list can be counted by specific criteria. Use the DCOUNT function to count all cells that contain numbers in a column of a list or database that match specified conditions.

DCOUNT(database, field, criteria)

database: The range of cells in the list or database. The first row of the list contains column headings.

field: Indicates the column to use in the function. field can be provided as text with the column heading enclosed in double quotation marks or as a number representing the position of the column within the list: 1 for the first column, 2 for the second column, and so on.

criteria: The range of cells containing the specified conditions. Any range can be used for the criteria argument, as long as it includes at least one column heading and at least one cell below the column heading to specify a condition.

Use the following data for this tip.

FIGURE 8–1

You can manually count all products in the vegetable category with a price less than or equal to $2.50, or you can let Excel do the counting, as described next:

To count special cells:

1. Copy the range A1:E1, as shown in the preceding figure.

2. Select cell A14 and press <Ctrl+V>.

3. Select cell C15 and type vegetable.

4. In cell E15, type <=2.50 to define the search criteria.

5. In cell C17, type the following formula: =DCOUNT(A1:E10,E14,A14:E15).

6. Press <Enter>.

FIGURE 8–2

NOTE

The category in cell C15 can be changed. To count several categories, just type “meat” in cell C16 and change the formula in cell A17 to this: =DCOUNT(A1:E10,E14,A14:E16).

USE THE DCOUNT FUNCTION TO COUNT CELLS IN A RANGE BETWEEN X AND Y

Use the data in the previous example to continue working with the DCOUNT function. Here we want to count all products in the vegetable category that cost more than $1.75 but no more than $2.50.

To count cells in a specific range between x and y:

1. Copy the range A1:E1.

2. Select cell A14 and paste the copied cells with <Ctrl+V>.

3. Select cell C15 and type vegetable.

4. In cell E15 type >1.75.

5. In cell F15 type <=2.50.

6. In cell C17 type the following formula: =DCOUNT(A1:E10,E14,A14:F15).

7. Press <Enter>.

FIGURE 8–3

USE THE DCOUNTA FUNCTION TO COUNT ALL CELLS BEGINNING WITH THE SAME CHARACTER

Continuing with the previous example, now we want to count all cells that begin with the letter “b,” like bread, beef steak, and bananas. To do this, use the DCOUNTA function, which counts the non-blank cells in a column of a list or database that match the specified conditions.

The arguments are the same as those used with the DCOUNT function.

To count cells beginning with the letter “b:”

1. Copy the range A1:E1.

2. Select cell A14 and press <Ctrl+V>.

3. In cell B15, type b*.

4. In cell C17, type the following formula: =DCOUNTA(A1:E10,E14,A14:E15).

5. Press <Enter>.

FIGURE 8–4

USE THE DGET FUNCTION TO SEARCH FOR A PRODUCT BY NUMBER

In this example, enter a product number to let Excel search a list for the corresponding product. To do so, use the DGET function, which selects a value from a column of a list or database that matches specified conditions. This is like the VLOOKUP function used to lookup a value in a range or table a return associated information.

DGET(database, field, criteria)

database: The range of cells in the list or database. The first row of the list contains column headings.

field: Indicates the column to use in the function. field can be provided as text with the column heading enclosed in double quotation marks or as a number representing the position of the column within the list.

criteria: The range of cells containing the specified conditions.

To search for a product number:

1. Copy the range A1:B1.

2. Select cell D1 and press <Ctrl+V>.

3. In cell D2, enter the number 13.

4. In cell E2, type the following formula: =DGET(A1:B10,E1,D1:D2).

5. Press <Enter>.

FIGURE 8–5

USE THE DMAX FUNCTION TO FIND THE MOST EXPENSIVE PRODUCT IN A CATEGORY

This tip shows how to determine the most expensive product in a list specified by a category using the DMAX function. This function returns the largest number in a column of a list or database that matches specified conditions.

DMAX(database, field, criteria)

database: The range of cells in the list or database. The first row of the list contains column headings.

field: Indicates the column to use in the function.

criteria: The range of cells containing the specified conditions.

To find the most expensive vegetable:

1. Copy the range A1:E1.

2. Select cell A14 and press <Ctrl+V>.

3. In cell C15, enter vegetable as the search criteria.

4. In cell C17, type the following formula: =DMAX(A1:E10,E14,A14:E15).

5. Press <Enter>.

FIGURE 8–6

USE THE DMIN FUNCTION TO FIND THE LEAST EXPENSIVE PRODUCT IN A CATEGORY

For this example, use the same list of food products to determine the least expensive fruit. To do so, use the DMIN function to return the smallest number in a column of a list or database that matches specified conditions.

DMIN(database, field, criteria)

database: The range of cells in the list or database. The first row of the list contains column headings.

field: Indicates the column to use in the function.

criteria: The range of cells containing the specified conditions.

To find the least expensive fruit:

1. Copy the range A1:E1.

2. Select cell A14 and press <Ctrl+V>.

3. In cell C15, enter fruit as the search criteria.

4. In cell C17, type the following formula: =DMIN(A1:E10,E14,A14:E15).

5. Press <Enter>.

FIGURE 8–7

USE THE DMIN FUNCTION TO FIND THE OLDEST PERSON ON A TEAM

The oldest member of a team can be found by using the DMIN function. (To find the youngest person, use DMAX.) Dates are stored in Excel as integer values beginning with 1 for January 1, 1900 and incrementing by 1 for each subsequent day. For example, the date 11/16/2004 has the value 38307. The syntax for DMIN is described in the previous tip.

To find the oldest person on a team:

1. Copy to worksheet cells A1:C10 as shown in Figure 8–8.

2. Copy the range A1:C1.

3. Select cell A12 and press <Ctrl+V>.

4. In cell C13, enter 1 to search just inside team 1.

5. In cell C15, type the following formula: =DMIN(A1:C10,B1,A12:C13).

FIGURE 8–8

USE THE DSUM FUNCTION TO SUM SALES FOR A PERIOD

Sometimes a list has to be summed up if it matches particular conditions. For example, you might want to sum sales in a certain category or for a specified time period. Use the DSUM function, which adds the numbers in a column of a list or database that matches specified conditions.

DSUM(database, field, criteria)

database: The range of cells in the list or database. The first row of the list contains column headings.

field: Indicates the column to use in the function.

criteria: The range of cells containing the specified conditions.

To sum sales for a particular time period:

1. Copy to a worksheet cells A2:C10 as shown in Figure 8–9.

2. Copy the range A1:C1.

3. Select cell A12 and press <Ctrl+V>.

4. In cell D12, type Date.

5. Fill in the criteria range as shown in cells A13:D13.

6. In cell D15, type the following formula: =DSUM(A1:C10,C1,A12:D13).

7. Press <Enter>.

FIGURE 8–9

USE THE DSUM FUNCTION TO SUM ALL PRICES IN A CATEGORY THAT ARE ABOVE A PARTICULAR LEVEL

The list in the following figure shows the prices of a number of goods in different categories. To sum all prices in one category that are above a particular price, use the DSUM function. Here we will sum all prices in category A that are above $100.

To sum all prices in category A above $100:

1. Copy to worksheet cells A1:C10 as shown in Figure 8–10.

2. Copy range A1:C1.

3. Select cell A12 and press <Ctrl+V>.

4. In cell B13, enter A to search inside category A.

5. In cell C13, type the argument >100.

6. In cell C15, type the following formula: =DSUM(A1:C10,C1,A12:C13).

7. Press <Enter>.

FIGURE 8–10

USE THE DAVERAGE FUNCTION TO DETERMINE THE AVERAGE PRICE IN A CATEGORY

To determine the average price in a category, use the DAVERAGE function. This function averages the values in a column of a list or database that match specified conditions.

DAVERAGE(database, field, criteria)

database: The range of cells in the list or database. The first row of the list contains column headings.

field: Indicates the column to use in the function.

criteria: The range of cells containing the specified conditions.

To determine the average price of a category:

1. Copy to worksheet cells A1:C10 as shown in Figure 8–11.

2. Copy range A1:C1.

3. Select cell A12 and press <Ctrl+V>.

4. In cell B13, enter A to search inside category A.

5. In cell C15, type the following formula: =DAVERAGE(A1:C10,C1,A12:C13).

6. Press <Enter>.

FIGURE 8–11

CHAPTER 9

LOOKUP AND REFERENCE FUNCTIONS

USE THE ADDRESS, MATCH, AND MAX FUNCTIONS TO FIND THE POSITION OF THE LARGEST NUMBER

We learned in previous tips how to look up a single value in a list. Now we want to determine the position of the largest value in a list by combining three Excel functions. First, we use the MAX function to get the largest value, then we use the MATCH function to find its relative position, and finally we use the ADDRESS function to determine the exact cell address.

NOTE

The MAX function was described in Chapter 5.

MATCH(lookup_value, lookup_array, match_type)

lookup_value: The value that corresponds to the entry to be found in a table.

lookup_array: A contiguous range of cells that contain possible lookup values.

match_type: Specifies how Excel matches lookup_value with values in lookup_array. 1 specifies that MATCH is to find the largest value that is less than or equal to lookup_value; 0 specifies that MATCH is to find the first value equal to lookup_value; and –1 specifies that MATCH is to find the smallest value that is greater than or equal to lookup_value.

The ADDRESS function returns the exact cell address as text.

ADDRESS(row_num, column_num, abs_num, sheet_text)

row_num: The row number to be used in the cell reference.

column_num: The column number to be used in the cell reference.

abs_num: The type of reference to return. 1 or omitted indicates absolute, 2 indicates absolute row and relative column, 3 indicates relative row and absolute column, and 4 indicates relative.

sheet_text: The name of the worksheet to be used as the external reference. If omitted, no sheet name is used.

For example:

=ADDRESS(5,2) is an absolute reference to cell $B$5.

=ADDRESS(4,4,2) is an absolute row reference and relative column reference to cell D$4.

=ADDRESS(1,1,3) is a relative row reference and an absolute column reference to cell $A1.

Take a look at the following example.

To search for the cell reference of the greatest number:

1. In cells A2:A10, enter some numbers.

2. Select cell C2 and type the following formula: =ADDRESS(MATCH(MAX(A1:A10),A1:A10),1,4).

3. Press <Enter>.

FIGURE 9–1

USE THE ADDRESS, MATCH, AND MIN FUNCTIONS TO FIND THE POSITION OF THE SMALLEST NUMBER

As with the previous tip, we can find the cell address for the smallest value in a list. We will again use the ADDRESS and MATCH functions, but this time in combination with MIN.

The MIN function finds the smallest value in a list. MATCH returns the relative position of the value 2, which will be transferred to the ADDRESS function to determine the cell address as shown in the following figure.

To search for the smallest number:

1. In cells A2:A10, list some numbers.

2. Select cell C2 and type the following formula: =ADDRESS(MATCH(MIN(A1:A10),A1:A10,0),1).

3. Press <Enter>.

FIGURE 9–2

USE THE ADDRESS, MATCH, AND TODAY FUNCTIONS TO SUM SALES UP TO TODAY’S DATE

In a worksheet, daily sales are recorded. To sum all listed sales until today’s date, use the functions learned from previous tips, including the TODAY function, which returns the actual date. MATCH returns the relative position of TODAY, which will be transferred to the ADDRESS function to determine the cell address, as seen in cell E2 of Figure 9–3. With the SUM and INDIRECT functions, you can sum all sales up to today and get the desired result.

To sum sales up to today:

1. In cells A2:A7 list dates in ascending order.

2. In cells B2:B7, enter the daily sales amounts.

3. Select cell E1 and type the formula =TODAY() to get the current date.

4. In cell E2, type the following formula: =ADDRESS(MATCH(TODAY(),$A$1:$A$7,1),2).

5. Determine the sum in cell E3 with the following formula: =SUM(B2:INDIRECT(E2)).

NOTE

INDIRECT(ref_text) returns the reference specified by a text string.

6. Press <Enter>.

FIGURE 9–3

USE THE XMATCH FUNCTION TO FIND WHO SOLD COOKIE BOXES AT OR NEAR THE GOAL

The XMATCH function is new to Excel 2021 and Microsoft 365. It expands the functionality of the original MATCH function. It contains two extra optional parameters allowing more search options.

XMATCH(lookup_value, table_array, [col_index_num], [range_lookup])

Lookup_value: The value to search for.

Lookup_array: The array or range to search.

Match_mode: An optional parameter to specify how to match the lookup_value against the values in the look_array.

The options are 0 (or omitted) for an exact match, −1 for an exact match or the next smallest value, 1 for an exact match or the next largest value and 2 for a wildcard match (either use “*” to represent any sequence of characters or “?” to represent only one character)

Search_mode: An optional parameter to specify the search mode to use.

The options are 1 (or omitted) to start the search from first to last, −1 searches from last to first, 2 represents a binary search ascendingly and −2 represents a binary search descendingly. For the binary searches to correctly work the lookup_array needs to be sorted in ascending order (for 2) or descending order (for −2). The binary search is quicker for large data sets.

To discover the row number of an exact match, next smallest or next largest:

1. Using the worksheet depicted in Figure 9–4, copy the range A1:D10 in a worksheet.

2. In cell E2, enter 65 as the goal to attain.

3. In cell E4, type the following formula: =XMATCH($E$2,$B$1:$B$10,0).

4. Press <Enter>.

5. In cell E5, type the following formula: =XMATCH($E$2,$B$1:$B$10,-1).

6. Press <Enter>.

7. In cell E6, type the following formula: =XMATCH($E$2,$B$1:$B$10,1).

8. Press <Enter>.

FIGURE 9–4

NOTE

The “#N/A” appears in cell E4 since there is no exact match for 65. Try entering the number 60 in E2 to notice the difference.

USE THE VLOOKUP FUNCTION TO LOOK UP AND EXTRACT DATA FROM A DATABASE

This tip explains how to search for a certain product in a list. First, take a look at the data in Figure 9–5:

FIGURE 9–5

Typing a valid product number in cell B1 fills cells B2 to B4 with the corresponding data from the list. To do this, use the VLOOKUP function, which searches for a value in the left-hand column of a table and returns a value in the same row from a column specified in the table.

VLOOKUP(lookup_value, table_array, col_index_num, range_lookup)

lookup_value: The value to be found in the left-hand column of the array.

table_array: The table in which data is looked up.

col_index_num: The column number in table_array from which the matching value must be returned. 1 returns the value in the first column in table_array, 2 returns the value in the second column in table_array, and so on.

range_lookup: A logical value that indicates whether VLOOKUP is to find an exact match or an approximate match. If TRUE or omitted, an approximate match is returned.

To look up and extract data from a list:

1. In cell B2, type the following formula: =VLOOKUP($B$1,$A$7:$D$16,2,FALSE).

2. In cell B3, type the following formula: =VLOOKUP($B$1,$A$7:$D$16,3,FALSE).

3. In cell B4, type the following formula: =VLOOKUP($B$1,$A$7:$D$16,4,FALSE).

4. Press <Enter>.

FIGURE 9–6

USE THE XLOOKUP FUNCTION TO RETURN A ROW OF INFORMATION

The XLOOKUP function is new to Excel 2021 and Microsoft 365. In this example, we will look at how it compares to the other “LOOKUP” functions. The two main differences are that you do not have to use the first column as the key to looking up a row and second it can return an array or more than one cell.

1. Using the worksheet depicted in Figure 9–7, copy the range A1:A4 and A7:E17 into a worksheet.

2. In cell B1, enter one of the product names listed in column C beneath the “Number” heading (cells C8:C17). In this example, we use T10 but you can use anyone you wish as long as it comes from the range C8:C17.

3. In cell B2, type the following formula: =XLOOKUP($B$1,$C$8:$C$17,$A$8:$A$17,FALSE).

4. Press <Enter>.

5. In cell B3, type the following formula: =XLOOKUP($B$1,$C$8:$C$17,$B$8:$B$17,FALSE)

6. Press <Enter>.

7. In cell B4, type the following formula: =XLOOKUP($B$1,$C$8:$C$17,$D$8:$D$17,FALSE)

8. Press <Enter>.

9. In cell B5, type the following formula: =XLOOKUP($B$1,$C$8:$C$17,$D$8:$E$17,FALSE)

10. Press <Enter>.

FIGURE 9–7

NOTE

The formula in cell B5 returns an array or range of five cells since the return_array parameter contains all five columns of the lookup_array, which is A-E ($A$8:$E$17).

USE THE VLOOKUP FUNCTION TO COMPARE OFFERS FROM DIFFERENT SUPPLIERS

This example contains a table with offers from different suppliers for a product listed vertically. To search for the best offer, use the built-in MIN function in combination with VLOOKUP to display the supplier with the lowest price.

To find the supplier with the lowest price:

1. In cells A2:A10, enter the offers.

2. In cells B2:B10, enter the names of the suppliers.

3. Select cell D2 and type the following formula: =VLOOKUP(MIN(A2:A10),A2:B10,1,FALSE).

4. Press <Enter>.

FIGURE 9–8

NOTE

To determine the lowest offer, use the function VLOOKUP(MIN(A2:A10),A2:B10,1,FALSE), the result of which is shown in cell E2.

USE THE HLOOKUP FUNCTION TO DETERMINE SALES AND COSTS FOR A TEAM

The costs and sales for a team need to be looked up in a table. Each team is listed by column with its costs and sales. To get the desired information, use the HLOOKUP function, which 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 that is specified in the table or array.

HLOOKUP(lookup_value, table_array, row_index_num, range_lookup)

lookup_value: The value to be found in the top row of the table.

table_array: A table in which data is looked up.

row_index_num: The row number in table_array from which the matching value will be returned.

range_lookup: A logical value that indicates whether HLOOKUP is to find an exact match or an approximate match.

To determine sales and costs for a team:

1. In a worksheet, copy the information in cells A1:E6, as shown in Figure 9–9.

2. In cell A7, enter a valid team name.

3. In cell B7, type the following formula: =HLOOKUP($A$7,$B$1:$E$3,2,FALSE).

4. Press <Enter>.

5. Select cell C7 and type the following formula: =HLOOKUP($A$7,$B$1:$E$3,3,FALSE).

6. Press <Enter>.

FIGURE 9–9

USE THE HLOOKUP FUNCTION TO DETERMINE SALES FOR A PARTICULAR DAY

In this example, all sales for a certain day need to be listed in the first column of a table. In addition, all sales need to be summed in cell A7 to show the total amount of sales for this day.

To determine the total amount of sales for one day:

1. In a worksheet, copy the information in cells C1:G5 as shown in Figure 9–8.

2. In cell A1, enter the desired day for which the sales of each team need to be listed.

3. Select cells A2:A5 and type the following formula: =HLOOKUP($A$1,$D$1:$G$5,(ROW())).

4. Press <Ctrl+Enter>.

5. Select cell A7 and type the following formula:="SUM = " & TEXT(SUM(A2:A5),"$#,000.00").

6. Press <Enter>.

FIGURE 9–10

NOTE

The ROW function returns the active row number.

USE THE HLOOKUP FUNCTION TO GENERATE A LIST FOR A SPECIFIC MONTH

The dates on which errors occur in a system are recorded each month in an Excel table as shown in the Figure 9–11. The first column lists the dates of all errors that occurred in a certain month. Enter the month in cell A1 and use a combination of functions based on HLOOKUP to return all recorded dates.

To generate a list for a specific month:

1. In a worksheet, copy cells C2:F5, as shown in Figure 9–11.

2. In cell A1, type the month 11.

3. Select cells A3:A5 and type the following formula: =IF(HLOOKUP($A$1,$C$2:$F$11,ROW()-1,FALSE)=0,"",HLOOKUP($A$1,$C$2:$F$11,ROW()-1,FALSE)).

4. Press <Ctrl+Enter>.

FIGURE 9–11

NOTE

You may need to format cells A3:F5 with a date format.

USE THE LOOKUP FUNCTION TO GET THE DIRECTORY OF A STORE

A store sells different products in a big warehouse. Each floor contains different categories of products. For example, the customer can find software on the first floor and hardware on the second floor. Each category is assigned a combination of two letters, such as software = SO, hardware = HA, food = FO, indoor = IN, and outdoor = OU. The task now is to find which products are sold on which floor by entering the category abbreviation in cell A9. Do this by using the array form of the LOOKUP function to return a value from a one-row or one-column range or from an array.

LOOKUP(lookup_value, array)

lookup_value: A value that will be looked up in an array.

array: A range of cells containing text, numbers, or logical values that are to be compared with lookup_value.

NOTE

The array form of the LOOKUP function is provided for compatibility with other spreadsheet programs. VLOOKUP can also be used in this situation, provided that the values in the first column are sorted in ascending order.

To display the correct floor:

1. In a worksheet, copy cells A1:C6, as shown in Figure 9–12.

2. In cell A9, enter the abbreviation of the product category.

3. Select cell B9 and type the following formula: =LOOKUP($A$9,$A$1:$B$8).

4. Press <Enter>.

5. Select cell C9 and type the following formula: =LOOKUP($A$9,$A$1:$C$8).

6. Press <Enter>.

FIGURE 9–12

USE THE LOOKUP FUNCTION TO GET THE INDICATOR FOR THE CURRENT TEMPERATURE

The following list contains indicators like cold, cool, warm, or hot for different temperature ranges. Enter the current temperature in one cell and let Excel determine the corresponding indicator with the vector form of the LOOKUP function.

LOOKUP(lookup_value, lookup_vector, result_vector)

lookup_value: A value that will be searched for in the first vector.

lookup_vector: A range containing only one row or one column.

result_vector: A range containing only one row or one column. result_vector and lookup_vector must be the same size.

If LOOKUP cannot find the lookup_value, it matches the largest value in lookup_vector that is less than or equal to it, which is quite useful for our task, because we have just four indicators.

They are defined as follows:

•From –50°F to 31°F = icy

•From 32°F to 49°F = cold

•From 50°F to 76°F = warm

•77°F and above = hot

To add an indicator for the temperature:

1. In a worksheet, copy the information in cells A1:B5, as shown in Figure 9–13.

2. In cell D2, enter the current temperature.

3. Select cell E2 and type the following formula: =LOOKUP($D$2,B2:B5,A2:A5).

4. Press <Enter>.

FIGURE 9–13

USE THE INDEX FUNCTION TO SEARCH FOR DATA IN A SORTED LIST

In addition to VLOOKUP, the INDEX function can be used to search for data in a sorted list. Copy the table below to a new worksheet and enter in cell A2 the team number for which you want to search. Let Excel search for the team name and corresponding costs with the INDEX or VLOOKUP functions as described in the next steps.

To search for data in a list:

1. In cells A2 and A3, enter valid numbers between 1 and 7.

2. Select cell B2 and type the following formula: =INDEX($A$6:$C$12,MATCH($A$2,$A$6:$A$12,0),2).

3. In cell B3, type the following formula: =VLOOKUP($A$3,$A$5:$C$12,2,FALSE).

4. Select cell C2 and type the following formula: =INDEX($A$6:$C$12,MATCH($A$2,$A$6:$A$12,0),3).

5. In cell C3, type the following formula: =VLOOKUP($A$3,$A$5:$C$12,3,FALSE).

6. Press <Enter>.

FIGURE 9–14

USE THE INDIRECT FUNCTION TO PLAY “BATTLESHIP”

Why not take a break and play “Battleship”? It is easy to create, and when you are finished reading this tip, you can enjoy playing.

In a new worksheet, define the range C1:E11 as the battlefield and border it as desired. Place some Xs to define the location of the ships and enter in cells B1 and B2 the coordinates of the cell to be fired on. Use the INDIRECT function to get the functionality that returns the reference, specified by a text string (e.g., “HIT”).

INDIRECT(ref_text, a1)

ref_text: A reference to a cell containing an A1-style reference, an R1C1-style reference, a name defined as a reference, or a reference to a cell as a text string.

a1: A logical value specifying the type of reference that is contained in the cell ref_text. If a1 is TRUE or omitted, ref_text will be an A1-style reference. If a1 is FALSE, ref_text will be an R1C1-style reference.

To set up and play “Battleship”:

1. In cell B1, enter a valid row number from 1 to 10.

2. In cell B2, enter a valid column letter from C to E.

3. Select cell B3 and type the following formula: =IF(INDIRECT(B2&B1)="X","Hit","").

4. Press <Enter>.

FIGURE 9–15

USE THE INDIRECT FUNCTION TO COPY CELL VALUES FROM DIFFERENT WORKSHEETS

The INDIRECT function can also be used to address cells in other worksheets and copy their values to the current sheet. Column A lists the names of worksheets, and column B lists cell references. With the INDIRECT function, the value of each cell reference can be copied to the current worksheet.

To copy cell values of different worksheets:

1. In a worksheet, copy cells A1:B10, as shown in Figure 9–16.

2. Select cells C2:C10 and type the following formula: =INDIRECT(A2&"!"&B2).

3. Press <Ctrl+Enter>.

FIGURE 9–16

NOTE

If you rename the worksheets, make sure not to use blanks (see row 6 in the previous example).

USE THE INDEX FUNCTION TO DETERMINE THE LAST NUMBER IN A COLUMN

Sometimes it is extremely useful to let Excel automatically determine the last value in a list. Use the INDEX function in combination with COUNTA and COUNTBLANK to determine the last number in a column. The INDEX function returns the value of an element in a table or an array that is selected by the row and column number indexes.

INDEX(array, row_num, column_num)

array: A range of cells or an array constant.

row_num: Indicates the row in an array from which a value will be returned. If omitted, column_num is required.

column_num: Indicates the column in an array from which a value will be returned. If omitted, row_num is required.

To determine the last number in a column:

1. In cells A2:A11, list any kind of numbers.

2. Select cell C1 and type the following formula: =INDEX(A:A,COUNTA(A:A)+COUNTBLANK(A1:A11),1).

3. Press <Enter>.

FIGURE 9–17

USE THE INDEX AND COUNTA FUNCTIONS TO DETERMINE THE LAST NUMBER IN A ROW

In the previous tip, we learned how to determine the last value for each column. Use the INDEX function in combination with COUNTA to determine the last number in a row. The INDEX function will return the value of an element in a table or an array, selected by the row and column number indexes.

To determine the last number in a row:

1. In cells B2:G10, enter some numbers, leaving some cells empty.

2. Select cells A2:A10 and type the following formula: =INDEX(B2:G2,1,COUNTA(B2:G2)).

3. Press <Ctrl+Enter>.

FIGURE 9–18

USE THE OFFSET FUNCTION TO SUM SALES FOR A SPECIFIED PERIOD

Figure 9–19 gives an overview of the monthly sales figures from the previous year. Let us sum the sales from January to November. To do so, use the OFFSET function in combination with SUM. OFFSET returns a reference to a range that is a specific number of rows and columns from a cell or range of cells.

The syntax is:

OFFSET(reference, rows, cols, height, width)

reference: The reference that is the base for the offset.

rows: The number of rows to which the upper-left cell should refer.

cols: The number of columns to which the upper-left cell should refer.

height: The height, in number of rows, that the returned reference should be. height must be a positive number.

width: The width, in number of columns, that the returned reference should be. width must be a positive number.

To sum sales for a specified period:

1. In a worksheet, copy cells A1:B13, as shown in Figure 9–19.

2. In cell D1, enter a number from 1 to 12 for the desired month.

3. In cell E2, type the following formula: =SUM(OFFSET($B$2,0,0,$D$2,1)).

4. Press <Enter>.

FIGURE 9–19

USE THE OFFSET FUNCTION TO CONSOLIDATE SALES FOR A DAY

This tip shows an effective way of summing all the sales of each team for one specific day. The tricky part of the task is that the dates appear more than once. To calculate all sales for each team on one specific date, use the OFFSET function in combination with SUMIF.

To consolidate sales per day and team:

1. In a worksheet, copy cells A1:E12, as shown in Figure 9–20.

2. In cell H1, enter a desired date.

3. In cells G3:G6, type the team names.

4. Select cells H3:H6 and type the following formula: =SUMIF($A$2:$A$12,$H$1,OFFSET($A$2:$A$12,0,MATCH(G3,$1:$1,)-1)).

5. Press <Ctrl+Enter>.

FIGURE 9–20

USE THE OFFSET FUNCTION TO FILTER EVERY OTHER COLUMN

This example shows a table where every other column has to be filtered. Use the COLUMN function to get the current column and combine it with the OFFSET function to reach the goal.

To extract every other column:

1. In cells A2:G6, type numbers from 1 through 6.

2. Select cells A9:D13 and type the following formula: =OFFSET($A2,0,(COLUMN()-1)*2).

3. Press <Ctrl+Enter>.

FIGURE 9–21

USE THE OFFSET FUNCTION TO FILTER EVERY OTHER ROW

In the previous example, we filtered every other column. To do the same with rows, use the ROW function to get the current row and combine it with the OFFSET function to get the result shown below.

To extract every other row:

1. In cells A2:A16, type any numbers.

2. Select cells B2:D9 and type the following formula: =OFFSET($A$2,(ROW()-2)∗COLUMN(),0).

3. Press <Ctrl+Enter>.

FIGURE 9–22

NOTE

To hide all cells containing 0, select Options from the Tools menu, click the View tab, and deactivate Zero values.

USE THE HYPERLINK FUNCTION TO JUMP DIRECTLY TO A CELL INSIDE THE CURRENT WORKSHEET

Hyperlinks are usually used to navigate through the Internet or link different Office documents. You can also use the HYPERLINK function to jump directly to a specific cell in your worksheet with one mouse click. This function normally creates a shortcut to a document stored on a network server or located in an intranet or the Internet. When a user clicks on a cell that contains the HYPERLINK function, Excel opens the file stored at link_location.

HYPERLINK(link_location, friendly_name)

link_location: The path and file name of the document to be opened.

friendly_name: The text or numeric value that is displayed in the cell and that the user must select.

In this example, we insert a hyperlink that jumps to the already opened file and its cell containing the current month.

To jump with one mouse click to the current month:

1. In cell A1, enter January.

2. Drag the right corner of this cell down to A12.

3. In cell C1, type the following formula: =HYPERLINK("month!A"&MONTH(TODAY()),"Jump to actual month").

4. Press <Enter>.

5. Click with the mouse on the displayed hyperlink in cell C1.

FIGURE 9–23

USE THE HYPERLINK FUNCTION TO LINK TO THE INTERNET

This tip shows how the HYPERLINK function is normally used to create links to the Internet. You can jump directly from your Excel application to predefined Web sites using the HYPERLINK function.

To link to the Internet:

1. In column A, type the URLs of the Web sites to which you want to link.

2. In column B, type the captions of the hyperlinks.

3. Select cells C2:C5 and type the following formula: =HYPERLINK("http://" & A2,"Click to " & B2).

4. Press <Ctrl+Enter>.

FIGURE 9–24

USE THE CHOOSE FUNCTION TO LOOKUP VALUES

There are many instances where one value depends on the value of another value. In order to yield the correct value, we can use VLOOKUP, IF, IFS or a combination of MATCH/INDEX. In the case where a simple reference to a list is all that is required, we can use the CHOOSE function. It is simpler than using nested IF statements.

1. In cell C4, type the formula: =CHOOSE(C2,"Red","Blue","Green","Yellow","Orange")

2. In cell C2, enter a number between 1 and 5.

The number you enter in cell C2 which tell the CHOOSE function to select value represented by the number in the list of colors. What happens if you enter a number below 1 or above 5 in this instance? The function yields an error because there are no values represented by those indices. There are only colors listed for 1 through 5.

FIGURE 9–25

USE THE ROW AND COLUMN FUNCTIONS TO DETERMINE HOW MANY ROWS AND COLUMNS ARE IN A WORKSHEET

The ROW() and COLUMN() functions return what row and column they are in. When you add a parameter, you can get the row or column of another cell or range. This is meaningful when you have worksheets with data spread across hundreds or thousands of rows and columns. In this example, we are going to use these functions with and without parameters. We begin by discovering the last row and column in a worksheet.

1. In a blank worksheet, in cell A1, simultaneously press <Ctrl+→>(Ctrl + right arrow key). This will bring you to the last column in excel. Unless you are using version 2003 or earlier, you will be at cell XFD1. Type the formula: =COLUMN().

2. Press <Enter>. The resulting number 16384 is the column number of XFD1 telling us how many columns an excel worksheet contains.

3. In cell XFD1, simultaneously press the <Ctrl+Home> key OR <Ctrl+←> (Ctrl + left arrow key). Either of these will bring you back to cell A1.

4. In the same worksheet, in cell A1, simultaneously press the <Ctrl+↓> (Ctrl + down arrow key). This will bring you to the last row in excel. Unless you are using version 2003 or earlier, you should be at cell A1048576. Type the formula: =ROW().

5. Press <Enter>. The resulting number will be the row number of cell A1048576 telling us how many columns an excel worksheet contains. The row is obvious in this example since the row numbers are listed on the left of every worksheet. Nevertheless, you can see how the ROW() function works without a parameter passed to it.

6. In cell A1048576, simultaneously press <Ctrl+Home> OR <Ctrl+↑> (up arrow). Either of these will bring you back to cell A1.

7. In the same worksheet, using the worksheet depicted in Figure 9–28, in cell C4, Type the formula: =ROW().

8. Press <Enter>.

9. In cell C5, Type the formula: =ROW(D2).

10. Press <Enter>.

11. In cell C6, Type the formula: =COLUMN().

12. Press <Enter>.

13. In cell C7, Type the formula: =COLUMN(D2:F2).

14. Press <Enter>.

15. In cell C8, Type the formula: =@COLUMN(D2:F2).

16. Press <Enter>.

FIGURE 9–26

FIGURE 9–27

FIGURE 9–28

NOTE

In Microsoft 365, some existing formulas now have the potential to return arrays into multiple cells or a range. ROW() and COLUMN() are two such functions. The formula you typed in cell C7 returns all the columns of the range entered as a parameter. By adding the “@” before the formula as we did in cell C8, the formula only returns the first column value of the range entered.

USE THE FORMULATEXT FUNCTION TO DISPLAY A FORMULA IN A CELL

Using the previous example, we will now display in column A the formulas we used in column C. You can also view this by clicking “Formulas” off the top menu bar and “Show Formulas” in the “Formula Auditing Group.” But by doing this you can only view either the values or the formulas. However, in this example we will use the function FORMULATEXT. The difference is that you can see the values in the cells that contain the functions and you can also display the actual formulas next to the values without having to toggle back and forth. Some use this as a check and balance to ensure formulas and values are consistent.

1. Using the worksheet depicted in Figure 9–29, copy cells C4:C8 into a blank worksheet.

2. Select cells A4:A8 and type the formula: =FORMULATEXT(C4)

3. Press <Ctrl+Enter>.

FIGURE 9–29

USE THE TRANSPOSE FUNCTION TO REARRANGE INFORMATION ON A WORKSHEET

Sometimes we pull data into a worksheet but it is does not display the way we wish it to. The TRANSPOSE function can alter columns and rows by inverting a range. In Figure 9–30, we have data in columns A and B but want our columns to be rows and our rows to be columns.

1. Using the worksheet depicted in Figure 9–30, in a worksheet, copy cells A1:B6

2. In cell D1, type in the formula =TRANSPOSE(A1:B6).

3. Press <Enter>.

FIGURE 9–30

NOTE

You can also execute the inverse. In other words, if the data were in cells D1:I2, you could TRANSPOSE(D1:I2) in another cell and the result will be what appears in cells A1:B6.

USE THE FILTER FUNCTION TO FILTER DATA FROM A RANGE

The FILTER function is new to Excel 2021 and Microsoft 365. To display a filtered range of a larger data set, use the FILTER function.

1. Using the worksheet depicted in Figure 9–31, copy cells A1:C10 into worksheet as well as cells E1:F1

2. In cell F2, type the formula =FILTER(A2:C10,C2:C10=F1)

3. Press <Enter>.

FIGURE 9–31

USE THE SORT FUNCTION TO SORT AN EXISTING RANGE INTO ANOTHER RANGE

The SORT function is new to Excel 2021 and Microsoft 365. We now have a function that will sort a range and place the sorted array into other cells. Using the SORT function has the advantage over the “Sort” option found under the “Data” menu since the SORT function does not change the order of the original data.

1. Using the worksheet depicted in Figure 9–32, copy cells A1:C10 into a worksheet.

2. In cell F1, type the formula =SORT(A1:C10,2,1).

3. Press <Ctrl+Enter>.

FIGURE 9–32

USE THE SORTBY FUNCTION TO SORT AN EXISTING RANGE INTO ANOTHER RANGE

The SORTBY function is new to Excel 2021 and Microsoft 365. Similar to the previous SORT example, you can use SORTBY to sort a range as well using the column range rather than a number within the range.

1. Using the worksheet in Figure 9–33, copy cells A1:C10 into a blank worksheet.

2. In cell F2, type in the formula =SORTBY(A2:C10,C2:C10).

3. Press <Enter>.

FIGURE 9–33

NOTE

Two differences exist between SORT and SORTBY. The first is that you do not include the heading row in the range parameters in SORTBY since SORTBY strictly sorts what you ask it. On the other hand, SORT assumes the first row is a heading row. The second difference is the 2nd parameter. The 2nd parameter in the SORT wants a number referencing the column you want to sort by in the given range. The 2nd parameter in the SORTBY function wants the actual range you wish to sort by.

USE THE UNIQUE FUNCTION TO RETURN UNIQUE ROWS OF DATA INTO ANOTHER RANGE

The UNIQUE function is new to Excel 2021 and Microsoft 365. Similar to the SORT and the SORTBY function, the UNIQUE function returns an array to another range that keeps the original range of values intact. The UNIQUE function will remove any duplicate rows of data. In other words, if all cells of one row match another row, it will not appear in the formula result.

1. Using the worksheet depicted in Figure 9–34, copy the range A1:C12 into a blank worksheet.

2. In cell F2, type the formula =UNIQUE(A2:C12)

3. Press <Enter>.

FIGURE 9–34

NOTE

The UNIQUE function will display unique values of the entire range you enter including a heading row if you add it. In this example we started with row 2 in the formula to exclude the heading row. Also remember that the uniqueness applies to every cell in a row. In the example above the only duplicate row was “Amy 2nd Submariner”

CHAPTER 10

CONDITIONAL FORMATTING WITH FORMULAS

USE THE WEEKDAY FUNCTION TO DETERMINE WEEKENDS AND SHADE THEM

With the help of the WEEKDAY function, we can find out the day of the week for a particular date. This function returns the days as an integer ranging from 1 (Sunday) to 7 (Saturday) by default. You can also use this function in conditional formatting. In this example, some dates are listed in column A and the weekends are then marked as shown.

To detect and shade weekends:

1. Copy cells A1 and B1 into a new worksheet, as shown in Figure 10–1.

2. Enter =TODAY() in cell A2 and =A2+1 in cell A3. For the remaining cells A4:A12, enter =Ax+1, where x is the previous cell number.

3. Select cells B2:B12 and enter the function =WEEKDAY(A2).

4. Press <Ctrl+Enter>.

5. Select cells A2:B12.

6. From the Home tab, go to the Styles bar and click on Conditional Formatting.

7. Choose New Rule.

8. In the Select a Rule Type dialog, select Use a formula to determine which cells to format.

9. In the Edit box, type the following formula to mark Saturday: =WEEKDAY($A2)=7 as depicted in Figure 10–1

10. Click Format to select the desired formatting to apply when the cell value meets the condition.

11. Select a color from the Fill tab and click OK.

12. Click OK.

13. Repeat steps 2 through 6 and choose Manage Rule.

14. Click New Rule and insert the following formula (to mark Sunday): =WEEKDAY($A2)=1.

15. Repeat step 10.

16. Click OK.

FIGURE 10–1

FIGURE 10–2

NOTE

To display the short versions of the days of the week rather than the integers returned by the function, highlight cells B2:B12, select Cells from the Format menu, and enter ddd in the Type box. Click OK.

You can also enter one conditional formatting rule instead of two. Instead of typing in =WEEKDAY($A2)=1 and =WEEKDAY($A2)=7 in separate conditional formatting rules you can use the OR function explained in chapter two to create only one rule. =OR(WEEKDAY($A2)=1,WEEKDAY($A2)=7)

USE THE TODAY FUNCTION TO SHOW COMPLETED SALES

All daily sales are listed in an Excel table. The list contains estimated sales as well, which are assigned this status as shown in column C. We need to mark all completed sales by using conditional formatting, being sure to exclude the estimated sales.

To show completed sales:

1. In a worksheet, copy cells A1:C13, as shown in Figure 10–3.

2. In cell E1, enter the function TODAY().

3. Select cells A2:C13.

4. From the Home tab, go to the Styles bar and click on Conditional Formatting.

5. Choose New Rule.

6. In the Select a Rule Type dialog, select Use a formula to determine which cells to format.

7. In the Edit box, type the following formula to mark the days that either match today’s date or are before today’s date: =$A2<=$E$1.

8. Click Format to select the desired formatting to apply when the cell value meets the condition.

9. Select a color from the Fill tab and click OK.

10. Go to the Font tab and select Bold in the Font Style.

11. Click OK.

FIGURE 10–3

NOTE

The Status column used in this example is meant to be used as a verification. Therefore, as the days go by, the colored formatting you accomplished in this example will be automatic depending on what today’s date is. The Status column is to be used by someone to manually verify that the sales are correct. Once correct, the person types in “ok.” If the cell contains “estimated,” it means that the sales have not been confirmed as final for that day.

Another way to accomplish this is to automate the Status column by comparing today’s date with the date in column A using the IF statement and the formula used above in the conditional formatting rule to yield either “ok” or “estimated”.

USE CONDITIONAL FORMATS TO INDICATE UNAVAILABLE PRODUCTS

When checking the existing inventory of a warehouse, it needs to be determined which products are out of stock so they can be ordered. To get a better overview of the inventory, all products that are unavailable need to be marked by using conditional formatting. The formatting criterion is taken from column D, which indicates whether a product is available.

To mark all products that are out of stock:

1. Copy the table shown in Figure 10–4 into a worksheet and select cells A2:D13.

2. From the Home tab, go to the Styles bar and click on Conditional Formatting.

3. Choose New Rule.

4. In the Select a Rule Type dialog, select Use a formula to determine which cells to format.

5. In the Edit box, type the following formula: =$D2="no".

6. Click Format to select the desired formatting to apply when the cell value meets the condition.

7. Select a color from the Fill tab and click OK.

8. Click OK.

FIGURE 10–4

USE THE TODAY FUNCTION TO SHADE A SPECIFIC COLUMN

A project schedule can be generated quite easily through Excel. To make it easier to read at a glance, the current day can be colored automatically. Use the TODAY function to determine the actual date and define it as the criterion for conditional formatting.

To shade the column for the current day:

1. In cell H1, enter the function TODAY().

2. Select cells A3:H12.

3. From the Home tab, go to the Styles bar and click on Conditional Formatting.

4. Choose New Rule.

5. In the Select a Rule Type dialog, select Use a formula to determine which cells to format.

6. In the Edit box, type the following formula: =A$3=TODAY().

7. Click Format to select the desired formatting to apply when the cell value meets the condition.

8. Select a color from the Fill tab and click OK.

9. Click OK.

FIGURE 10–5

NOTE

To remove all conditional formats as well as all other cell formats for selected cells, do as described in step 3 and choose Clear Rules.

USE THE WEEKNUM AND MOD FUNCTIONS TO SHADE EVERY OTHER TUESDAY

The table shown in Figure 10–6 is part of a schedule for the purchasing department. Purchases are made every other Tuesday. Create a schedule and color every other Tuesday as a reminder. Use the WEEKNUM function (introduced in Chapter 4) from the Analysis ToolPak add-in. This function returns a number that indicates where the week falls numerically within a year. In combination with the MOD function, it can be determined if the week number is even or odd.

To mark every second Tuesday:

1. Select cells A2:C20.

2. From the Home tab, go to the Styles bar and click on Conditional Formatting.

3. Choose New Rule.

4. In the Select a Rule Type dialog, select Use a formula to determine which cells to format.

5. In the Edit box, type the following formula: =AND(WEEKDAY($A3)=3,MOD($C3,2)<>1).

6. Click Format to select the desired formatting to apply when the cell value meets the condition.

7. Select a color from the Fill tab and click OK.

8. Click OK.

FIGURE 10–6

USE THE MOD AND ROW FUNCTIONS TO SHADE EVERY THIRD ROW

In this example, every third row of a table must be marked. To do this automatically, use the ROW function in combination with MOD. The formula uses the ROW function to return the row number of the active cell and then uses the MOD function to divide it by 3. If the remainder is 0, the row can be shaded using conditional formatting.

To shade every third row:

1. Select rows 1 to 20.

2. From the Home tab, go to the Styles bar and click on Conditional Formatting.

3. Choose New Rule.

4. In the Select a Rule Type dialog, select Use a formula to determine which cells to format.

5. In the Edit box, type the following formula: =MOD(ROW(),3)=0.

6. Click Format to select the desired formatting to apply when the cell value meets the condition.

7. Select a color from the Fill tab and click OK.

8. Click OK.

FIGURE 10–7

NOTE

Up to three conditions can be specified as conditional formats. If none of the specified conditions are true, the cells keep their existing formats.

USE THE MOD AND COLUMN FUNCTIONS TO SHADE EVERY THIRD COLUMN

The previous tip showed how to mark every third row. Now let us find out how to automatically mark every third column in a range. Use the COLUMN function in combination with MOD by entering a formula that uses the COLUMN function to return the column number of the active cell and the MOD function to divide that number by 3. If the remainder is zero, the column can be shaded through conditional formatting.

To shade every third column:

1. Select range A1:P14.

2. From the Home tab, go to the Styles bar and click on Conditional Formatting.

3. Choose New Rule.

4. In the Select a Rule Type dialog, select Use a formula to determine which cells to format.

5. In the Edit box, type the following formula: =MOD(COLUMN(),3)=0.

6. Click Format to select the desired formatting to apply when the cell value meets the condition.

7. Select a color from the Fill tab and click OK.

8. Click OK.

FIGURE 10–8

NOTE

Because conditional formatting causes the document file size to grow very quickly, you should format only the ranges where it is really needed.

USE THE MAX FUNCTION TO FIND THE LARGEST VALUE

This example shows how to find and automatically mark the largest value in a range. All occurrences of the largest value will be shaded. Use the MAX function to determine the largest value in a range and then use that value as the formatting criterion for conditional formatting.

To search for and shade the largest value:

1. In a worksheet, enter numbers in cells A1:E10 (or copy the values in Figure 10–9) and select the range.

2. From the Home tab, go to the Styles bar and click on Conditional Formatting.

3. Choose New Rule.

4. In the Select a Rule Type dialog, select Use a formula to determine which cells to format.

5. In the Edit box, type the following formula: =A1=MAX($A$1:$E$10).

6. Click Format to select the desired formatting to apply when the cell value meets the condition.

7. Select a color from the Fill tab and click OK.

8. Click OK.

FIGURE 10–9

USE THE LARGE FUNCTION TO FIND THE THREE LARGEST VALUES

The three largest values in a range need to be found and shaded, regardless of how many times they appear. Use the LARGE function to determine the three largest values in a range and specify those three conditions as criteria for conditional formatting.

To search for and shade the three largest values:

1. In a worksheet, enter numbers in cells A1:E10 or copy the values in Figure 10–10 and select the range.

2. From the Home tab, go to the Styles bar and click on Conditional Formatting.

3. Choose Format only top or bottom ranked values.

4. In the dialog box choose 3 and the required cell format.

5. Click OK.

FIGURE 10–10

USE THE MIN FUNCTION TO FIND THE MONTH WITH THE WORST PERFORMANCE

Salespeople usually do some market analysis to find their current share of the market. Before you can investigate the reasons for a bad fiscal year, you need to find the worst month of sales and then shade it. Use the MIN function to get the lowest value in a range and use it as the formatting criterion for conditional formatting.

To search for the worst month:

1. In a worksheet, enter the months in cells A2:A13 and the sales amounts in cells B2:B13 (or copy the values in Figure 10–11) and select the range.

2. From the Home tab, go to the Styles bar and click on Conditional Formatting.

3. Choose New Rule.

4. In the Select a Rule Type dialog, select Use a formula to determine which cells to format.

5. In the Edit box, type the following formula: =$B2=MIN($B$2:$B$13).

6. Click Format to select the desired formatting to apply when the cell value meets the condition.

7. Select a color from the Fill tab and click OK.

8. Click OK.

FIGURE 10–11

USE THE MIN FUNCTION TO SEARCH FOR THE LOWEST NONZERO NUMBER

In this example, the smallest nonzero number in a range must be found and marked automatically. Use the MIN function to get the lowest value in a range, then use the IF function to check that the number is not zero. Insert this formula as the formatting criterion for conditional formatting, and the lowest numbers will be colored as desired. This function finds the lowest number, whether it is positive or negative.

To search for the lowest nonzero number:

1. In a worksheet, enter numbers in cells A1:D10 (or copy the values in Figure 10–12) and select the range.

2. From the Home tab, go to the Styles bar and click on Conditional Formatting.

3. Choose New Rule.

4. In the Select a Rule Type dialog, select Use a formula to determine which cells to format.

5. In the Edit box, type the following formula: =A1=MIN(IF($A$1:$D$10<>0,$A$1:$D$10)).

6. Click Format to select the desired formatting to apply when the cell value meets the condition.

7. Select a color from the Fill tab and click OK.

8. Click OK.

FIGURE 10–12

USE THE COUNTIF FUNCTION TO MARK DUPLICATE INPUT AUTOMATICALLY

Sometimes a list must be checked for duplicate entries. This example creates a randomized list and then finds all duplicate values and marks them. Use the COUNTIF function to count numbers that are repeated in a range and then use this function with conditional formatting to shade all duplicate values as desired.

To mark duplicate entries automatically:

1. Select the range A1:D10.

2. Type the following formula to generate randomized numbers from 1 to 300: =RANDBETWEEN(1,300) (as a result of the RANDBETWEEN function, the numbers displayed in Figure 10–13 will be different than the numbers displayed in your worksheet).

3. Press <Ctrl+Enter>.

4. In the Format menu, click Conditional Formatting.

5. Select Format only unique or duplicate values or use the following formula in the formula option for defining rules: =COUNTIF($A$1:$D$12,A1)>1.

6. Click Format.

7. From the Patterns tab, choose a color and click OK.

8. Click OK.

FIGURE 10–13

FIGURE 10–14

NOTE

Press <F9> to recalculate and generate new randomized numbers for the range.

USE THE COUNTIF FUNCTION TO CHECK WHETHER A NUMBER EXISTS IN A RANGE

From this example, you can learn how to check whether a specific number is found in a range and have Excel automatically mark each cell of the range that contains the number. Use the COUNTIF function to check whether the range contains the number in cell B1 and combine it with conditional formatting to shade the specific value as desired.

To check whether a number exists in a range:

1. Copy cells A1:D10 as shown in Figure 10–15 or use your own data.

2. Select cell B1.

3. From the Home tab, go to the Styles bar and click on Conditional Formatting.

4. Choose New Rule.

5. In the Select a Rule Type dialog, select Use a formula to determine which cells to format.

6. In the Edit box, type the following formula: =COUNTIF($A$3:$D$10,$B$1)>0.

7. Click Format to select the desired formatting to apply when the cell value meets the condition.

8. Select a color from the Fill tab and click OK.

9. Click OK.

10. Select cells A3:D10.

11. Repeat step 3 and choose Manage Rule.

12. Click New Rule and insert the following formula: =$B$1=A3.

13. Repeat steps 7–8.

14. Click OK.

FIGURE 10–15

USE CONDITIONAL FORMATTING TO CONTROL FONT STYLES IN A SPECIFIC RANGE

Conditional formatting can also be used to control font styles in a specified range. Use cell E1 to enter letters like “i” for italic, “b” for bold, and “s” for strikethrough. Use conditional formatting to format the range as desired based on the input in cell E1.

To control font styles in a specified range:

1. In a worksheet, enter numbers in cells A1:D10 (or copy the values in Figure 10–16) and select the range A1:D10.

2. From the Home tab, go to the Styles bar and click on Conditional Formatting.

3. Choose New Rule.

4. In the Select a Rule Type dialog, select Use a formula to determine which cells to format.

5. In the Edit box, type the following formula: =$E$1="i".

6. Click Format to select the desired formatting to apply when the cell value meets the condition.

7. On the Font tab, select Italic from the Font style box.

8. Click OK.

9. In cell E1, enter the character i to indicate that you want to italicize all the items in the range.

FIGURE 10–16

NOTE

You can add further font styles to the Conditional Formatting dialog using different conditions.

USE A USER-DEFINED FUNCTION TO DETECT CELLS WITH FORMULAS

This example requires you to be familiar with the VBA Editor. Here we want to mark all cells in a specific range that contain a formula. First, you need to write a user-defined function:

1. Press <Alt+F11> to open the VBA window.

2. On the Insert menu, click Module and enter the following function:

Function HF(rng)As Boolean

HF = rng.HasFormula

'returns TRUE if rng contains

'a formula

End Function

(The lines above that begin with an apostrophe indicate the information that follows is a comment.)

3. Press <Alt+Q> to return to the Excel worksheet.

Now you can use this user-defined function in conditional formatting.

To shade all cells that contain formulas:

1. In a worksheet, enter numbers in cells A1:D10, being sure to enter formulas in some of the cells, and select cells A1:D10.

2. From the Home tab, go to the Styles bar and click on Conditional Formatting.

3. Choose New Rule.

4. In the Select a Rule Type dialog, select Use a formula to determine which cells to format.

5. In the Edit box, type the following formula: =HF(A1).

6. Click Format to select the desired formatting to apply when the cell value meets the condition.

7. Select a color from the Fill tab and click OK.

8. Click OK.

FIGURE 10–17

USE A USER-DEFINED FUNCTION TO DETECT CELLS WITH VALID NUMERIC VALUES

Continuing with the previous tip, let us now mark all cells in a range that contain valid numeric values. First, you need to write a user-defined function:

1. Press <Alt+F11> to open up the VBA window.

2. On the Insert menu, click Module and enter the following function:

Function ISNUM(rng) As Boolean

If rng.Value <> "" Then

ISNUM = IsNumeric(rng.Value)

End If

' returns TRUE if rng contains

' numeric values

End Function

3. Press <Alt+Q> to return to the Excel worksheet.

Now you can use this user-defined function in conditional formatting.

To shade cells with valid numeric values:

1. In a worksheet, enter data in cells A1:C10, being sure to use numeric values in some of the cells (or copy the values in Figure 10–18), and select cells A1:C10.

2. From the Home tab, go to the Styles bar and click on Conditional Formatting.

3. Choose New Rule.

4. In the Select a Rule Type dialog, select Use a formula to determine which cells to format.

5. In the Edit box, type the following formula: =isnum(A1).

6. Click Format to select the desired formatting to apply when the cell value meets the condition.

7. Select a color from the Fill tab and click OK.

8. Click OK.

FIGURE 10–18

USE THE EXACT FUNCTION TO PERFORM A CASE-SENSITIVE SEARCH

Usually, Excel does not differentiate between uppercase and lowercase letters. To search for a string that has the same case, use the EXACT function. The search string is entered in cell B1. With the support of conditional formatting, all cells within a specified range will be formatted if they contain the exact search string.

To perform a case-sensitive search on text:

1. In a worksheet, enter a variety of values in cells A3:E13, being sure to use both “Excel” and “excel” in several cells (or copy the values in Figure 10–19).

2. In cell B1, enter Excel.

3. Select cells A3:E13.

4. From the Home tab, go to the Styles bar and click on Conditional Formatting.

5. Choose New Rule.

6. In the Select a Rule Type dialog, select Use a formula to determine which cells to format.

7. In the Edit box, type the following formula: =EXACT(A3,$B$1).

8. Click Format to select the desired formatting to apply when the cell value meets the condition.

9. Select a color from the Fill tab and click OK.

10. Click OK.

FIGURE 10–19

USE THE SUBSTITUTE FUNCTION TO SEARCH FOR TEXT

This tip can help you look for specific text in a list and mark each occurrence. The search text is specified in cell B13. Specify the SUBSTITUTE function as a condition to search for and shade each cell where the text string is found.

To search for text:

1. Copy the data shown in Figure 10–20 to a new worksheet and select cells B2:B11.

2. From the Home tab, go to the Styles bar and click on Conditional Formatting.

3. Choose New Rule.

4. In the Select a Rule Type dialog, select Use a formula to determine which cells to format.

5. In the Edit box, type the following formula: =LEN(B2)<>LEN(SUBSTITUTE(B2,$B$13,"")).

6. Click Format to select the desired formatting to apply when the cell value meets the condition.

7. Select a color from the Fill tab and click OK.

8. Click OK.

FIGURE 10–20

USE CONDITIONAL FORMATTING TO SHADE PROJECT STEPS WITH MISSED DEADLINES

The project schedule shown in Figure 10–21 contains different steps and their starting and projected ending dates. The actual end dates are listed in column E. Use conditional formatting to search for all steps that ended late by comparing the dates in columns D and E. As usual, select the desired formatting to apply when the cell value meets the condition.

To shade project steps with missed deadlines:

1. In a worksheet, copy the values shown in Figure 10–21 and select cells A2:E11.

2. From the Home tab, go to the Styles bar and click on Conditional Formatting.

3. Choose New Rule.

4. In the Select a Rule Type dialog, select Use a formula to determine which cells to format.

5. In the Edit box, type the following formula: =$E2>$D2.

6. Click Format to select the desired formatting to apply when the cell value meets the condition.

7. Select a color from the Fill tab and click OK.

8. Click OK.

FIGURE 10–21

USE CONDITIONAL FORMATTING TO CREATE A GANTT CHART IN EXCEL

With the help of this tip, you can easily create a project plan that includes a Gantt chart in Excel. Begin by inserting a new worksheet and then copy the header row as shown in Figure 10–22.

To create a project plan and Gantt chart step by step:

1. Copy the data in cells A2:C11, as shown in Figure 10–22.

2. Select cells D2:D11 and type the formula =C2-D2.

3. Press <Ctrl+Enter>.

4. Select cell E1 and type the formula =B2.

5. Select cells F1:AB1 and type the formula =E1+1.

6. Press <Ctrl+Enter>.

7. Select cells E2:AB11.

8. From the Home tab, go to the Styles bar and click on Conditional Formatting.

9. Choose New Rule.

10. In the Select a Rule Type dialog, select Use a formula to determine which cells to format.

11. In the Edit box type the following formula: =AND(E$1>=$B2,E$1<$C2).

12. Click Format to select the desired formatting to apply when the cell value meets the condition.

13. Select a color from the Fill tab and click OK.

14. Click OK.

FIGURE 10–22

USE THE OR FUNCTION TO INDICATE DIFFERENCES HIGHER THAN 5% AND LOWER THAN −5%

At the end of a fiscal year, a company compares the monthly sales of the last two years. Look at the following sales report for 2008 and 2009. Monthly sales of fiscal year 2008 are listed in column B, and column C contains the sales for 2009. Check the difference in column D by inserting the formula =(C2/B2)-1 and format it to percentages with one decimal place. The following steps show how to use conditional formatting to shade each cell that meets the desired condition.

To shade differences higher than 5% and lower than −5%:

1. Select cells C2:C13.

2. From the Home tab, go to the Styles bar and click on Conditional Formatting.

3. Choose New Rule.

4. In the Select a Rule Type dialog, select Use a formula to determine which cells to format.

5. In the Edit box type the following formula: =OR((C2/B2)-1>5%,(C2/B2)-1<-5%).

6. Click Format to select the desired formatting to apply when the cell value meets the condition.

7. Select a color from the Fill tab and click OK.

8. Click OK.

FIGURE 10–23

USE THE CELL FUNCTION TO DETECT UNLOCKED CELLS

If a worksheet has been protected, all cells are locked by default. The protection for each cell must be unlocked before activating sheet protection. If a sheet is protected, usually it is not possible to see at one glance which cells are locked and which are unlocked. Use conditional formatting to shade all unlocked cells in a range.

To shade unlocked cells:

1. Create the worksheet shown in Figure 10–24 and unlock cells B2, B4, B6, and B8.

2. Select cells A1:D10.

3. From the Home tab, go to the Styles bar and click on Conditional Formatting.

4. Choose New Rule.

5. In the Select a Rule Type dialog, select Use a formula to determine which cells to format.

6. In the Edit box, type the following formula: =CELL("protect",A1)=0.

7. Click Format to select the desired formatting to apply when the cell value meets the condition.

8. Select a color from the Fill tab and click OK.

9. Click OK.

FIGURE 10–24

USE THE COUNTIF FUNCTION TO SHADE MATCHING NUMBERS IN COLUMN B

Cells A2:A4 in Figure 10–25 contain numbers that need to be found in column B. If values in column B match values in column A, the cells should be marked. Use the COUNTIF function in combination with conditional formatting to shade each cell that meets the desired condition.

To shade values in column B that correspond to values in column A:

1. Create the worksheet shown in Figure 10–25 and select cells B1:B10.

2. From the Home tab, go to the Styles bar and click on Conditional Formatting.

3. Choose New Rule.

4. In the Select a Rule Type dialog, select Use a formula to determine which cells to format.

5. In the Edit box, type the following formula: =COUNTIF($A$2:$A$4,B2)>=1.

6. Click Format to select the desired formatting to apply when the cell value meets the condition.

7. Select a color from the Fill tab and click OK.

8. Click OK.

FIGURE 10–25

USE THE ISERROR FUNCTION TO MARK ERRORS

In this example, the value in column B is divided by the value in column A and the result is displayed in column C. If the result of this operation is invalid, an error appears in column C. Use the ISERROR function in combination with conditional formatting to shade each cell that contains an error.

To detect and shade errors:

1. In a worksheet, enter numbers in cells A2:B11, as shown in Figure 10–26.

2. Select cells C2:C11 and type the formula =B2/A2.

3. Press <Ctrl+Enter>.

4. Select cells C2:C11.

5. From the Home tab, go to the Styles bar and click on Conditional Formatting.

6. Choose New Rule.

7. In the Select a Rule Type dialog, select Use a formula to determine which cells to format.

8. In the Edit box, type the following formula: =ISERROR(B2/A2).

9. Click Format to select the desired formatting to apply when the cell value meets the condition.

10. Select a color from the Fill tab and click OK.

11. Click OK.

FIGURE 10–26

USE THE DATEDIF FUNCTION TO DETERMINE ALL FRIENDS YOUNGER THAN 30

You have the birth dates of your friends listed in a worksheet and want to shade those who are currently younger than 30 years old. Use the TODAY function to determine the current date and the DATEDIF function to calculate each friend’s exact age, then combine those functions with conditional formatting.

To determine all friends younger than 30:

1. In a worksheet, enter data in cells A2:B10, as shown in Figure 10–27.

2. Select cells A2:B10.

3. From the Home tab, go to the Styles bar and click on Conditional Formatting.

4. Choose New Rule.

5. In the Select a Rule Type dialog, select Use a formula to determine which cells to format.

6. In the Edit box, type the following formula: =DATEDIF($B2,TODAY(),"Y")<30.

7. Click Format to select the desired formatting to apply when the cell value meets the condition.

8. Select a color from the Fill tab and click OK.

9. Click OK.

FIGURE 10–27

USE THE MONTH AND TODAY FUNCTIONS TO FIND BIRTHDAYS IN THE CURRENT MONTH

Use the same list from the previous tip to determine whose birthday falls in the current month. Use the TODAY function to determine the current date and the MONTH function to compare the month of everyone’s birthday with the current month, then combine those functions with conditional formatting.

To determine all friends whose birthday is in the current month:

1. In cell D1 enter the formula TODAY().

2. Select cells A2:B10.

3. From the Home tab, go to the Styles bar and click on Conditional Formatting.

4. Choose New Rule.

5. In the Select a Rule Type dialog, select Use a formula to determine which cells to format.

6. In the Edit box, type the following formula: =(MONTH(TODAY())=MONTH($B2)).

7. Click Format to select the desired formatting to apply when the cell value meets the condition.

8. Select a color from the Fill tab and click OK.

9. Click OK.

FIGURE 10–28

USE CONDITIONAL FORMATTING TO BORDER SUMMED ROWS

Enhance worksheets with this tip for placing a border on special cells. The worksheet contains daily sales for different teams. After a certain period, team sales are summed. To enhance the visibility of each sum, we want to border it automatically through conditional formatting. Use a simple instruction as the condition for conditional formatting and border the row of each cell that meets the desired condition.

To border all rows containing a sum:

1. In a worksheet, enter data in cells A1:C11, as shown in Figure 10–29, and select the range A2:C11.

2. From the Home tab, go to the Styles bar and click on Conditional Formatting.

3. Choose New Rule.

4. In the Select a Rule Type dialog, select Use a formula to determine which cells to format.

5. In the Edit box, type the following formula: =$B2="sum".

6. Click Format.

7. On the Border tab, click the bottom line in the Border field.

8. Select Red from the Color drop-down box.

9. Click OK.

FIGURE 10–29

USE THE LEFT FUNCTION IN A PRODUCT SEARCH

In this example, you need to find all the product numbers that contain the same first three characters. Enter the product number as the search criterion in cell A2 and let Excel find each product that corresponds to the same first three characters. The first three characters of the numbers can be extracted by the LEFT function. The name of the first product appears automatically in cell B2 with the use of the following formula: =VLOOKUP($A$2,$A$5:$B$15,2,FALSE). Use a combination of the LEFT function and conditional formatting to shade each cell that meets the desired condition.

To shade product numbers that meet the criteria:

1. In a worksheet, copy the data in cells A4:B15, as shown in Figure 10–30, and select cells A5:B15.

2. From the Home tab, go to the Styles bar and click on Conditional Formatting.

3. Choose New Rule.

4. In the Select a Rule Type dialog, select Use a formula to determine which cells to format.

5. In the Edit box, type the following formula: =LEFT($A5,3)=LEFT($A$2,3).

6. Click Format to select the desired formatting to apply when the cell value meets the condition.

7. Select a color from the Fill tab and click OK.

8. Click OK.

FIGURE 10–30

USE THE AND FUNCTION TO DETECT EMPTY ROWS IN A RANGE

The tip in this chapter marks all empty cells in a range. Use a combination of the AND function and conditional formatting to shade each cell that meets the desired condition.

To detect empty rows in a range:

1. In a worksheet, copy the data in cells A1:B12, as shown in Figure 10–31, and select the range A2:B12.

2. From the Home tab, go to the Styles bar and click on Conditional Formatting.

3. Choose New Rule.

4. In the Select a Rule Type dialog, select Use a formula to determine which cells to format.

5. In the Edit box, type the following formula: =AND($A3>($A2+1),$B3>($B2+1)).

6. Click Format to select the desired formatting to apply when the cell value meets the condition.

7. Select a color from the Fill tab and click OK.

8. Click OK.

FIGURE 10–31

USE THE COUNTIFS FUNCTION TO DETERMINE VALUE BASED ON MULTIPLE FILTERS

The COUNTIFS function is an extension of the COUNTIF function. The COUNTIF function only filters against one value while the COUNTIFS function can use multiple filters to evaluate against. For example, if you wish to determine the number of cats of a certain color instead of just the number of cats, you can use the COUNTIFS function.

1. In a worksheet, copy the data in cells B3:C12, as shown in Figure 10–32.

2. In cell F3, type the formula: =COUNTIFS(B4:B10,"Cat",C4:C10,"Black")

The function brings back a count of only the black cats.

FIGURE 10–32

CHAPTER 11

WORKING WITH DYNAMIC ARRAY FORMULAS

Microsoft made probably its biggest changes to formulas with the new version by introducing Dynamic Array Formulas. This differs from the legacy array formulas in which you needed to use the “Ctrl+Shift+Enter” (CSE) keys to enter an array formula. In addition to not needing to press CSE, other main upshots to this upgrade are the following:

• You only need to enter the array formula in one cell rather than entering the formula in many different cells as required by the individual formulas.

• The size of the array is automatically resized based upon data added or removed as well as the parameter changes within the formula.

• Any dynamic array formulas that return values into more than one cell will automatically “spill,” meaning results of the array will automatically populate based upon the parameters of the formula and the data entered.

• If you need to change a formula in the old CSE array formula, you will need to edit the entire range simultaneously. With the new dynamic array formulas, all you need to do is modify the original cell in which the formula resides.

The examples in this chapter will make the above features clearer as we traverse through them.

Essentially the main difference is that you no longer need to use the “Ctrl+Shift+Enter” when entering a formula; rather, simply enter the formula. For older versions of Excel you will still need to press CSE when entering array formulas.

Also note, that for any Dynamic Array Formula, when you click outside the original cell that creates the array, you will not be able to adjust it. If you enter another value anywhere in the output range it will clear out the resulting array. This will make more sense later as you enter the formula examples for yourself.

USE THE ADDRESS, MAX, AND ROW FUNCTIONS TO DETERMINE THE LAST CELL USED

With this tip, we learn the definition of an array formula. Here, we want to determine the last cell used in a range and shade it. Combine the ADDRESS, MAX, and ROW functions as described below to get the desired result.

To determine the last cell used in a range and shade it:

1. In column A, list any kind of numbers.

2. Select cell B2 and type the following array formula: =ADDRESS (MAX((A2:A100<>"")∗ROW(A2:A100)),1).

3. Press <Enter>.

4. Select cells A2:A11.

5. From the Home tab, go to the Styles bar and click on Conditional Formatting.

6. Choose New Rule.

7. In the Select a Rule Type dialog, select Use a formula to determine which cells to format.

8. In the Edit box, type the following formula: =ADDRESS(ROW(),1)=$B$2.

9. Click Format, select a color from the Fill tab, and click OK.

10. Click OK.

NOTE

Use a dynamic array formula to perform several calculations to generate a single result or multiple results.

FIGURE 11–1

USE THE INDEX, MAX, ISNUMBER, AND ROW FUNCTIONS TO FIND THE LAST NUMBER IN A COLUMN

Use the table from the previous tip and continue with array formulas. Now we want to determine the last value in column A. Use a combination of the INDEX, MAX, ISNUMBER, and ROW functions inside an array formula to have the desired result displayed in cell B2.

To determine the last number in a column:

1. In column A, list values or use the table from the previous tip.

2. Select cell B2 and type the following array formula: =INDEX(A:A, MAX(ISNUMBER(A1:A1000)∗ROW(A1:A1000))).

3. Press <Enter>.

FIGURE 11–2

USE THE INDEX, MAX, ISNUMBER, AND COLUMN FUNCTIONS TO FIND THE LAST NUMBER IN A ROW

In this example, the last value in each row must be determined and copied to another cell. To do this, combine the INDEX, MAX, ISNUMBER, and COLUMN functions in an array formula.

To determine the last number in a row:

1. Generate a table the one shown in Figure 11–3 using the range A1:F6.

2. In cells A9:A13, enter numbers from 2 to 6.

3. Select cell B9 and type the following array formula: =INDEX(2:2, MAX(ISNUMBER(2:2)∗COLUMN(2:2))).

4. Press <Enter>.

5. Select cells B9:B13.

6. In the Home tab, go to the Editing bar and choose the Fill button.

7. Select down to retrieve the last value in each of the remaining rows.

FIGURE 11–3

USE THE MAX, IF, AND COLUMN FUNCTIONS TO DETERMINE THE LAST COLUMN USED IN A RANGE

Now let’s determine the last column used in a defined range by using an array formula. All columns in the range A1:X10 need to be checked, and the last column used is then shaded automatically. Here we use the MAX, IF, and COLUMN functions in an array formula and combine them with conditional formatting.

To determine the last used column in a range:

1. Select cells A1:D10 and enter any numbers.

2. Select cell B12 and type the following array formula: =MAX(IF(A1:X10<>"",COLUMN(A1:X10))).

3. Press <Enter>.

4. Select cells A1:X10.

5. From the Home tab, go to the Styles bar and click on Conditional Formatting.

6. Choose New Rule.

7. In the Select a Rule Type dialog, select Use a formula to determine which cells to format.

8. In the Edit box, type the following formula: =$B$12=COLUMN(A1).

9. Click Format, select a color from the Fill tab, and click OK.

10. Click OK.

FIGURE 11–4

USE THE MIN AND IF FUNCTIONS TO FIND THE LOWEST NONZERO VALUE IN A RANGE

The sales for a fiscal year are recorded by month. At some point during the year, the month with the lowest sales must be determined. If the list contains all sales from the year, we simply use the MIN function to get the lowest value. However, if we want to find the lowest sales before the year is over and we don’t have sales figures available for some of the months, we need to use the IF function to exclude the zero values, so they aren’t read as the minimum. Combine the MIN and IF functions in an array formula and use conditional formatting to shade the lowest value.

To detect the lowest nonzero value in a range:

1. In cells A2:A13, list the months January through December.

2. In column B, list some sales values down to row 7.

3. Select cell F2 and type the following array formula: =MIN(IF(B1:B13>0,B1:B13)).

4. Press <Enter>.

5. Select cells B2:B13.

6. From the Home tab, go to the Styles bar and click on Conditional Formatting.

7. Choose New Rule.

8. In the Select a Rule Type dialog, select Use a formula to determine which cells to format.

9. In the Edit box, type the following formula: =$F$2=B2.

10. Click Format, select a color from the Fill tab, and click OK.

11. Click OK.

FIGURE 11–5

USE THE AVERAGE AND IF FUNCTIONS TO CALCULATE THE AVERAGE OF A RANGE, TAKING ZERO VALUES INTO CONSIDERATION

Normally, Excel calculates the average of a range without considering empty cells. Use this tip to calculate the correct average when some values in a range are missing. As in the previous example, we use the IF function to exclude the zero values, in this case so they don’t reduce the average. Combine the AVERAGE and IF functions in an array formula to obtain the correct average of all listed costs.

To calculate the average of a range, taking zero values into consideration:

1. In cells A2:A13, list the months January through December.

2. In column B, list monthly costs down to row 7.

3. Select cell E1 and type the following array formula: =AVERAGE(IF($B$2:$B$13<>0,$B$2:$B$13)).

4. Press <Enter>.

FIGURE 11–6

NOTE

The result can be checked by selecting cells B2:B7. Right-click in the Excel status bar and select the built-in Average function instead of the usually displayed Sum.

USE THE SUM AND IF FUNCTIONS TO SUM VALUES WITH SEVERAL CRITERIA

To sum values in a list, the SUMIFS function can be used. But you can also use a dynamic array formula. Using a combination of different functions in a dynamic array formula is an alternative solution. Use the SUM and IF functions together to take several criteria into consideration. In this example, we want to sum all values in a list that match both the word “wood” in column A and a value larger than 500 in column B. The result is displayed in cell E2.

To sum special values with several criteria:

1. In cells A2:A11, enter materials like wood, earth, and metal.

2. In cells B2:B11, list sizes from 100 to 1,000.

3. In cells C2:C11, enter the corresponding costs.

4. Select cell E2 and type the following array formula: =(SUM(IF(A2: A11="wood",IF(B2:B11>500,C2:C11)))).

5. Press <Enter>.

FIGURE 11–7

USE THE INDEX AND MATCH FUNCTIONS TO SEARCH FOR A VALUE THAT MATCHES TWO CRITERIA

To search for a value that takes one or more criteria into consideration, use the INDEX and MATCH functions together. In this example, the search criteria can be entered in cells E1 and F1. Generate a search function using those two search criteria for the range A2:C11 and return the result in cell E2.

To search for a special value considering two criteria:

1. In a worksheet, copy the data in cells A1:C11, as shown in Figure 11–8.

2. Enter W46 as the first criterion in cell E1 and 1235 as the second criterion in cell F1.

3. Select cell E2 and type the following array formula: =INDEX(C1: C11,MATCH(E1&F1,A1:A11&B1:B11,0)).

4. Press <Enter>.

FIGURE 11–8

NOTE

Using the INDEX/MATCH combination is one of the great alternatives to using the VLOOKUP function. The combination also works quicker when analyzing large amounts of data. The new XLOOKUP, however, is more powerful and flexible than both.

USE THE SUM FUNCTION TO COUNT VALUES THAT MATCH TWO CRITERIA

To count values in a list, normally the COUNTIF function is used. Unfortunately, COUNTIF cannot be used to count when more than one criterion must be taken into consideration. However, it is possible to get the desired result using an array formula. Use the SUM function to consider two criteria. In this example, we count the rows that contain the word “wood” in column A and have a size larger than 500 in column B.

To count special values that match two criteria:

1. In cells A2:A11, list materials like wood, earth, and metal.

2. In cells B2:B11, enter sizes from 100 to 1000.

3. In cells C2:C11, list the sales for each product.

4. Select cell E2 and type the following array formula: =SUM((A2:A11="wood")∗(B2:B11>500)).

5. Press <Enter>.

FIGURE 11–9

USE THE SUM FUNCTION TO COUNT VALUES THAT MATCH SEVERAL CRITERIA

In the previous example, we took two criteria into consideration. Now let’s adapt that example for three criteria. Count all rows that meet these criteria: The material is “wood” (column A), the size is larger than 500 (column B), and the sales price is higher than $5,000 (column C). To get the desired result, use an array formula that takes care of all three criteria.

To count special values that match several criteria:

1. In cells A2:A11, enter materials like wood, earth, and metal.

2. In cells B2:B11, list sizes from 100 to 1000.

3. In cells C2:C11, enter the sales price for each product.

4. Select cell E5 and type the following array formula: =SUM((A2:A11="wood")∗(B2:B11>500)∗(C2:C11>5000)).

5. Press <Enter>.

FIGURE 11–10

USE THE SUM FUNCTION TO COUNT NUMBERS FROM X TO Y

For this tip, we want to count all sales from $2,500 to less than $5,000. As previously described, COUNTIF handles only one condition. Use an array formula with the SUM function to get the correct result here.

To count sales from $2,500 to less than $5,000:

1. In cells A2:B11, list the daily sales and dates.

2. Select cell D2 and type the following array formula: =SUM((A2:A11>=2500)∗(A2:A11<5000)).

3. Press <Enter>.

4. Select cells A2:B11.

5. From the Home tab, go to the Styles bar and click on Conditional Formatting.

6. Choose New Rule.

7. In the Select a Rule Type dialog, select Use a formula to determine which cells to format.

8. In the Edit box, type the following formula: =AND($A2>=2500,$A2<5000).

9. Click Format, select a color from the Fill tab, and click OK.

10. Click OK.

FIGURE 11–11

NOTE

To sum all shaded sales, use the following array formula: =(SUM(IF(A2:A11>=2500,IF(A2:A11<5000,A2:A11))))

USE THE SUM AND DATEVALUE FUNCTIONS TO COUNT TODAY’S SALES OF A SPECIFIC PRODUCT

The table in Figure 11–12 contains several products sold on different days. We want to count all sales of one specific product for just one day. To handle dates this way, use the DATEVALUE function, which converts a date represented by text to a serial number. Use an array formula to count all the sales of one product for the desired day.

To count today’s sales of a specific product:

1. In cells A2:A15, list dates.

2. In cells B2:B15, enter product numbers.

3. In cell E1, enter =TODAY().

4. In cell D2, enter the product number you want to find (sold on today’s date).

5. Select cell E2 and type the following array formula: =SUM((DATEVALUE("3/7/2014")=$A$2:$A$15)∗($D$2=$B$2:$B$15)).

6. Press <Enter>.

FIGURE 11–12

USE THE SUM FUNCTION TO COUNT TODAY’S SALES OF A SPECIFIC PRODUCT

This example is similar to the previous one, except the search criteria are variable. The array formula refers now to cells E1 and E2 and sums up all counted sales for one product on a specified date in cell E4.

To count sales of a specific product for one day:

1. In cells A2:A15, list dates.

2. In cells B2:B15, enter product numbers.

3. Select cell E1 and enter the desired date to be considered for counting.

4. Select cell E2 and select one product number.

5. Select cell E4 and type the following array formula: =SUM((E1=$A$2:$A$15)∗(E2=$B$2:$B$15)).

6. Press <Enter>.

FIGURE 11–13

USE THE SUM, OFFSET, MAX, IF, AND ROW FUNCTIONS TO SUM THE LAST ROW IN A DYNAMIC LIST

Figure 11–14 shows a list that is updated constantly. The task here is to determine the last row and sum its entries. Use the MAX and ROW functions to detect the last row used, then sum that row with help from the SUM and OFFSET functions. Combine all these functions in one array formula and assign the calculated result to cell H2.

To sum the last row in a dynamic list:

1. In cells A2:A11, enter dates.

2. In cells B2:F11, list numbers for each team.

3. Select cell H2 and type the following array formula: =SUM(OFFSET(B1:F1,MAX(IF(B1:F100<>"",ROW(1:100)))-1,)).

4. Press <Enter>.

FIGURE 11–14

NOTE

Check the result by selecting cells B11:F11. With the right mouse button, click on the status bar at the bottom of the Excel window and select the Sum function.

USE THE SUM, MID, AND COLUMN FUNCTIONS TO COUNT SPECIFIC CHARACTERS IN A RANGE

In this example, we want to count specific characters that appear in a range. Use the MID function to extract each character from the cells, then define the range to be searched using the COLUMN function. The SUM function counts the result. Combine all these functions into one array formula.

To count certain characters in a range:

1. In cells A2:A11, list IP addresses.

2. Insert in any of these cells one or more characters, like x or xxx.

3. Select cell D2 and type the following array formula: =SUM((MID(A1:A11,COLUMN(1:1),3)="xxx")∗1).

4. Press <Enter>.

5. Select cell D3 and type the following array formula: =SUM((MID(A1:A11,COLUMN(1:1),1)="x")∗1).

6. Press <Enter>.

FIGURE 11–15

USE THE SUM, LEN, AND SUBSTITUTE FUNCTIONS TO COUNT THE OCCURRENCES OF A SPECIFIC WORD IN A RANGE

In this example, we want to count how many times a specific word appears in a range. Use the SUM, SUBSTITUTE, and LEN functions in one array formula to do this. Enter the criterion in cell C1 and let Excel display the result of the count in cell C2.

To count the occurrences of a specific word in a range:

1. In cells A2:A11, type any text but enter the word test at least once.

2. In cell C1, enter the word test.

3. Select cell C2 and type the following array formula: =SUM((LEN(A1:A10)-LEN(SUBSTITUTE(A1:A10,C1,"")))/LEN(C1)).

4. Press <Enter>.

5. Select cells A2:A10.

6. From the Home tab, go to the Styles bar and click on Conditional Formatting.

7. Choose New Rule.

8. In the Select a Rule Type dialog, select Use a formula to determine which cells to format.

9. In the Edit box, type the following formula: =$C$1=A1.

10. Click Format, select a color from the Fill tab, and click OK.

11. Click OK.

FIGURE 11–16

USE THE SUM AND LEN FUNCTIONS TO COUNT ALL DIGITS IN A RANGE

With what you have learned so far about array formulas, this task should be easy. Here we will count all digits in the range A1:A10 and display the result in cell C2. As you have probably already guessed, both the SUM and LEN functions can be combined in an array formula.

To count all digits in a range:

1. In cells A2:A10, type any text.

2. Select cell C2 and type the following array formula: =SUM(LEN(A1:A10)).

3. Press <Enter>.

FIGURE 11–17

USE THE MAX, INDIRECT, AND COUNT FUNCTIONS TO DETERMINE THE LARGEST GAIN/LOSS OF SHARES

Let’s say you record the daily share prices of a stock in an Excel worksheet. In this example, you want to monitor your stock to determine the largest gain and loss in dollars.

To determine the largest gain and loss:

1. In cells A2:A11, enter the daily value of a stock.

2. In cells B2:B11, list dates.

3. Select cell D2 and type the array formula =MAX(A3:INDIRECT("A"&COUNT(A:A))-A2:INDIRECT("A"& COUNT(A:A)-1)) to find the largest gain.

4. Press <Enter>.

5. Select cell E2 and type the array formula =MIN(A3:INDIRECT("A"&COUNT(A:A))-A2:INDIRECT("A"&COUNT(A:A)-1)) to find the greatest loss.

6. Press <Enter>.

FIGURE 11–18

NOTE

To determine the dates of the largest gain and loss, use =INDEX(B:B,MATCH(D2,A$3:A$1002-A$2:A$1001,0)+1) in cell D3 and =INDEX(B:B,MATCH(E2,A$3:A$1002-A$2:A$1001,0)+1) in cell E3.

USE THE SUM AND COUNTIF FUNCTIONS TO COUNT UNIQUE RECORDS IN A LIST

Excel offers a feature to extract unique values from a list. This feature usually is used by filtering the list through the Data menu option Filter | Advanced Filter. But how do you count unique records in a list without filtering them? Use the SUM and COUNTIF functions together in an array formula.

To count unique records in a list:

1. In cells A2:A11, list numbers, repeating some of them.

2. Select cell C2 and type the following array formula: =SUM(1/COUNTIF($A$2:$A11,$A$2:$A11)).

3. Press <Enter>.

FIGURE 11–19

USE THE UNIQUE FUNCTION TO LIST UNIQUE RECORDS IN A LIST

Microsoft 365/Excel 2021 offers a more sophisticated method in managing unique records than by using the SUM and COUNTIF functions together. In this example, we will duplicate what was done in the previous section that used the SUM and COUNTIF function but take it to the next level by being more detailed. Using only the SUM and COUNTIF function we get the number of unique records. By using the UNIQUE function, we get what the actual unique values are.

To list unique records in a list:

1. In cells A2:A11, list numbers, repeating some of them.

2. Select cell C2 and type the following array formula: =UNIQUE(A2:A11,0,0)

3. Press <Enter>.

FIGURE 11–20

USE THE AVERAGE AND LARGE FUNCTIONS TO CALCULATE THE AVERAGE OF THE X LARGEST NUMBERS

In this example, we will calculate the average of the largest five numbers in a list. Combine the AVERAGE and LARGE functions in one array formula.

To calculate the average of the five largest numbers:

1. In cells A2:A11, list some numbers.

2. Select cell C2 and type the following array formula: =AVERAGE(LARGE(A:A,{1,2,3,4,5})).

3. Press <Enter>.

FIGURE 11–21

NOTE

To calculate the average of the three largest numbers, enter the following formula in cell D2: =AVERAGE(LARGE(A:A,{1,2,3})).

USE THE TRANSPOSE AND OR FUNCTIONS TO DETERMINE DUPLICATE NUMBERS IN A LIST

Imagine you have a long list of numbers and your task is to identify all numbers that occur more than once. All of the values need to be checked to see if they appear more than once by using the TRANSPOSE and OR functions. Then all duplicated numbers need to be shaded with the help of the COUNTIF function, which is connected to conditional formatting.

To determine duplicate numbers in a list:

1. In columns A and B, list numbers, some of which are repeated at least once.

2. Select cell D2 and type the following array formula: =OR(TRANSPOSE(A2:A11)=B2:B11).

3. Press <Enter>.

4. Select cells A2:B11.

5. From the Home tab, go to the Styles bar and click on Conditional Formatting.

6. Choose New Rule.

7. In the Select a Rule Type dialog, select Use a formula to determine which cells to format.

8. In the Edit box, type the following formula: =COUNTIF($A$2:$B$11,A2)>1.

9. Click Format, select a color from the Fill tab, and click OK.

10. Click OK.

FIGURE 11–22

USE THE MID, MATCH, AND ROW FUNCTIONS TO EXTRACT NUMERIC VALUES FROM TEXT

This tip can help you extract numeric digits from text. Use the MID, MATCH, and ROW functions and combine them in an array formula.

To extract numeric values from text:

1. In cells A2:A11, enter numbers with leading characters, like YE2004 or FGS456.

2. Select cells B2:B11 and type the following array formula: =1∗MID(A2,MATCH(FALSE,ISERROR(1∗MID(A2,ROW($1:$10),1)),0),255).

3. Press <Enter>.

FIGURE 11–23

USE THE MAX AND COUNTIF FUNCTIONS TO DETERMINE WHETHER ALL NUMBERS ARE UNIQUE

This tip lets you check whether listed numbers are unique. In this example, you use the MAX and COUNTIF functions in combination with an array formula.

To determine whether all listed numbers are unique:

1. In column A, list some numbers.

2. Select cell C2 and type the following array formula: =MAX(COUNTIF(A2:A11,A2:A11))=1.

3. Press <Enter>.

4. Select cells A2:A11.

5. From the Home tab, go to the Styles bar and click on Conditional Formatting.

6. Choose New Rule.

7. In the Select a Rule Type dialog, select Use a formula to determine which cells to format.

8. In the Edit box, type the following formula: =COUNTIF($A$2:$A$11,A2)>1.

9. Click Format, select a color from the Fill tab, and click OK.

10. Click OK.

FIGURE 11–24

NOTE

If any numbers are listed more than once, they will be shaded and cell C2 will display FALSE.

USE THE TRANSPOSE FUNCTION TO COPY A RANGE FROM VERTICAL TO HORIZONTAL OR VICE VERSA

Sometimes it is very useful to copy a vertical range of cells to a horizontal range or vice versa. Just copy a range, select a cell outside the range, and click Paste Special on the Edit menu. Check the Transpose option and click OK. The copied range will be shifted by its vertical or horizontal orientation. To use the same functionality but keep the original references to the copied range, use the TRANSPOSE function in an array formula. Follow this tip to transpose the following table below the range A1:G3.

To transpose a range and keep original cell references:

1. In a worksheet, copy the data in cells A1:G3, as shown in Figure 11–25.

2. Select cells B7:B12 and type the following array formula: =TRANSPOSE(B1:G1).

3. Press <Enter>.

4. Select cells C6:C12 and type the following array formula: =TRANSPOSE(A2:G2).

5. Press <Enter>.

6. Select cells D6:D12 and type the following array formula: =TRANSPOSE(A3:G3).

7. Press <Enter>.

FIGURE 11–25

NOTE

The order of an array will always be the same; only the vertical or horizontal orientation is shifted.

USE THE FREQUENCY FUNCTION TO CALCULATE THE NUMBER OF PRODUCTS SOLD FOR EACH GROUP

The table in Figure 11–26 lists the number of a product sold daily. To do some market analysis and check consumer behavior, group the list and count the different consumption patterns. Use the FREQUENCY function entered as an array formula to count the frequency by different groups.

To calculate frequency and check purchasing habits:

1. In column A, enter dates in ascending order.

2. In column B, list the number of products sold each day.

3. Define the different groups in cells D2:D5.

4. Select cells E2:E6 and type the following array formula: =FREQUENCY(B2:B11,$D$2:$D$11).

5. Press <Enter>.

FIGURE 11–26

NOTE

FREQUENCY ignores blank cells and text.

USE THE FILTER FUNCTION TO DETERMINE WINS FOR A SPECIFIC DIVISION

The result in this example can be accomplished by pivot tables and table filters. However, in this example, we are going to use a Dynamic Array Formula that provides us the results direct into the spreadsheet without upsetting the original data.

To filter by division:

1. In column A, enter divisions in any pattern you wish. You can mimic the spreadsheet displayed in Figure 11–27.

2. In column B, list different teams.

3. In column C, list the number of wins that each team has.

4. In cell F3, type the following array formula: =FILTER(A2:C11,A1:A11=F1, "No Wins")

5. Press <Enter>

6. In cell F1, type in a value representing one of the divisions you entered in column A. In Figure 11–27, we used A, B and C.

7. Press <Enter>.

FIGURE 11–27

NOTE

If you enter a value in cell F1 that is not present in column A, you will receive the response “No Wins.”

USE THE SORT FUNCTION TO LIST AN EXISTING TABLE OF DATA BY A CERTAIN COLUMN

You can certainly highlight a group of data and sort the data by using the option in the menu bar DATA→SORT. If you do so, the data will be re-arranged to your liking. However by using the SORT function, you can keep the existing data in its original order and view a completely different data view by the sort you request.

To sort by division:

1. You can use the data from the previous example or in column A, enter divisions in any pattern you wish. You can also mimic the spreadsheet displayed in Figure 11–28.

2. In column B, list different teams.

3. In column C, list the number of wins that each team has.

4. In cell F3, type the following array formula: =SORT(A2:C11,1,1). This sorts the entire data table in column 1 in ascending order.

5. Press <Enter>.

FIGURE 11–28

USE THE SORTBY FUNCTION TO LIST AN EXISTING TABLE OF DATA BY A CERTAIN COLUMN

We are going to take the SORT function and expand it a bit. In this example, we are going to create an entirely separate table, but sorted by wins.

To sort by wins:

1. You can use the data from the previous example or in column A, enter divisions in any pattern you wish. You can also mimic the spreadsheet displayed in Figure 11–29.

2. In column B, list different teams.

3. In column C, list the number of wins that each team has.

4. In cell F3, type the following array formula: =SORTBY(A2:C11,C2:C11,1). This sorts the entire data table in column 3, the “win” column, in ascending order.

5. Press <Enter>.

FIGURE 11–29

USE THE RANDARRAY FUNCTION TO RETURN A LIST OF RANDOM NUMBERS ACROSS ANY NUMBER OF ROWS AND COLUMNS

Random numbers are a welcome use to either test a Monte Cristo concept or create random data to test reports. Now, because Microsoft 365 has dynamic array formulas, you can simply enter the formula in one cell and create data in any number of rows and columns. Here is how it works.

1. Open up a blank worksheet and in cell A1, type the following array formula: =RANDARRAY(12,5). This will place random numbers between 0 and 1 in a range 5 columns wide by 12 rows down.

2. Press <Enter>.

3. In cell I1, type the following array formula =RANDARRAY(12,5)∗10000.

4. Press <Enter>.

FIGURE 11–30

NOTE

You can vary the random numbers being displayed by multiplying the entire formula by a number. For example, in cell I1 we typed, =RANDARRAY(12,5)∗10000 which will provide you random numbers between 1,000 and 10,000. The multiplication factor of 10,000 will be the max and the min will be that number (10,000) divided by 10 or 1,000.

USE THE SEQUENCE FUNCTION TO RETURN A LIST OF A SEQUENCE OF NUMBERS ACROSS ANY NUMBER OF ROWS AND COLUMNS

A sequence of numbers can be used as a basis for testing other formulas or to view an end result of where a sequence ends. Here is how it works.

1. Open up a blank worksheet and in cell A1, type the following array formula: =SEQUENCE(12,5,1000,-16). This will a sequence of numbers beginning with 1000 in cell A1 and decrement each value by 16 across each row and column until the 12 rows and 5 columns are used up.

2. Press <Enter>.

FIGURE 11–31

NOTE

You can also put in a reference to a range or another formula in each parameter. For instance, in the third parameter type in the function pi() which is equivalent to approximately 3.14 and view the results.

CHAPTER 12

SPECIAL SOLUTIONS WITH FORMULAS

USE THE COUNTIF FUNCTION TO PREVENT DUPLICATE INPUT THROUGH VALIDATION

This tip shows an easy way to prevent duplicate input in the range A1:A100. Use the Validation option and enter a custom formula to get the desired functionality for the specified range in a worksheet.

To prevent duplicate input:

1. Select cells A1:A100.

2. On the Data tab, in the Data Tools group, click Data Validation.

3. In the Data Validation dialog box, click the Settings tab and select Custom in the Allow drop-down box.

4. In the Formula box, type the formula =COUNTIF($A:$A,A1)=1.

5. Select the Error Alert tab.

6. Enter a custom error message.

7. Click OK.

When a user attempts to enter duplicate data, an error message will appear.

FIGURE 12–1

NOTE

To remove data validation, select the desired range, click Validation on the Data menu, select the Settings tab, and then click Clear All.

USE THE EXACT FUNCTION TO ALLOW ONLY UPPERCASE CHARACTERS

This example shows how to allow only uppercase characters in a specified range. Use the data validation option in combination with a custom formula.

To allow only uppercase characters:

1. Select cells A1:A100.

2. On the Data tab, in the Data Tools group, click Data Validation.

3. In the Data Validation dialog box, click the Settings tab and select Custom in the Allow drop-down box.

4. In the Formula box, type the formula =EXACT(A1,UPPER(A1)).

5. Select the Error Alert tab.

6. Enter a custom error message.

7. Click OK.

FIGURE 12–2

NOTE

If you want to allow only lowercase characters, use the formula =EXACT(A1,LOWER(A1)).

USE DATA VALIDATION TO ALLOW DATA INPUT BY A SPECIFIC CRITERION

A range is defined to allow data input as long as it is not locked through a criterion specified in a certain cell. In this example, we allow data input only if the value “Yes” is entered in cell D1. Again, we use data validation in combination with a custom-defined formula to get the solution for this exercise.

To allow data input according to one specified criterion:

1. Enter data in cells A1:A10 as shown in Figure 12–3 and select cells A1:A10.

2. On the Data tab, in the Data Tools group, click Data Validation.

3. In the Data Validation dialog box, click the Settings tab and select Custom in the Allow drop-down box.

4. Type the formula =$D$1="Yes".

5. Select the Error Alert tab.

6. Enter a custom error message.

7. Click OK.

FIGURE 12–3

NOTE

This formula allows data to be changed only if cell D1 contains the value 1.

USE DATA VALIDATION TO LIMIT DATA TO A SPECIFIC LIST

You can limit the input of a cell to a list of choices either by listing them out or referring to another range or list. In this example, you will execute both.

To allow data input limited to a list:

1. Enter any data you wish into cells A1:A5 or copy the information as in Figure 12–4.

2. In cell C1, enter the phrase “Select Answer”.

3. In cell C4, enter the phrase “Select Name”.

4. Select cells D1, and then on the Data tab, in the Data Tools group, click Data Validation.

5. In the Data Validation dialog box, click the Settings tab and select List in the Allow drop-down box.

6. In the Source: box type “Yes,No,Maybe”. These are the three choices that will be allowed in cell D1. See Figure 12–5 below.

7. Click OK.

8. Select cell D4 and then on the Data tab, in the Data Tools group, click Data Validation.

9. In the Data Validation dialog box, click the Settings tab and select List in the Allow drop-down box.

10. In the Source: box type =$A$1:$A$5. These are the choices that will be allowed in cell D4. See Figure 12–6 below.

11. Click OK.

FIGURE 12–4

FIGURE 12–5

FIGURE 12–6

USE CONTROLS WITH FORMULAS

The table shown in Figure 12–7 contains an address list with company names and a contact person for each company. Imagine that we can use a drop-down box to select a company, and all corresponding data about the company is automatically displayed in specified cells. Just open a new worksheet and copy the table below to learn more about using drop-down boxes in combination with functions.

FIGURE 12–7

To assign a name to a range of data:

1. Select cells A2:D5 as shown in Figure 12–7 above.

2. Click the name box to the left of the formula bar which shows “A2” and enter Data. This name represents all the data inside the range A2:D5.

3. Press <Enter>.

4. Select cells A2:A5.

5. Assign a name to this header row by entering Company in the Name box.

6. Press <Enter>.

To display addresses by selecting them from a drop-down box:

1. Insert a new worksheet in the same Excel file and display the Developer toolbar by selecting the File tab. Click Options and choose Customize ribbon.

2. In the Main tabs, tick Developer. A new tab will appear in the tab ribbon.

3. In this new tab, go to the Controls box and click Insert.

4. From Form Controls, choose Combo Box.

5. Move the mouse cursor to the desired location inside the worksheet. Click and drag the combo box to the desired size.

6. Click with the right mouse button on the combo box and select Format Control.

7. Select the Control tab and type Company in the Input range field.

8. In the Cell link field, enter E2.

9. Check the 3D shading box.

10. Press OK.

11. Select cell B6 and type the formula =INDEX(data,$E$2,2) to display the first name.

12. Select cell C6 and type the formula =INDEX(data,$E$2,3) to display the last name.

13. Select cell B7 and type the formula =INDEX(data,$E$2,4) to display the country.

FIGURE 12–8

NOTE

If the index in cell E2 is not visible, move the combo box so it doesn’t cover this cell or change the displayed font style color from Automatic (black) to white.

USE GOAL SEEK AS A POWERFUL ANALYSIS TOOL

Goal Seek is a standard function found on the Tools menu that takes several criteria into consideration and helps find the correct value of a calculation. This example shows the quality control of a production run. The monitoring process sorts out products that don’t meet the expected quality standards. The first time we check the quality, we find that 5% of the production does not meet quality standards, and the second time, we find that 2% of the production fails to meet standards. How many more products need to be produced to reach the required number of 1,030 products that meet the quality standards?

Use Goal Seek to determine the total amount of production needed:

1. In cell C2, enter 1030 as the production goal.

2. In cell C3, type the formula =C2∗0.05.

3. In cell C4, enter the formula =C2-C3 to calculate how many products are needed to reach the production goal.

4. In cell C5, type the formula =C4∗0.02.

5. Calculate the final sum in cell C6 with the formula =C4-C5.

FIGURE 12–9

6. On the Data tab, in the Data Tools group, click What-If Analysis, and then click Goal Seek.

7. In the Set cell box, enter C6; in the To value box, enter 1030; and in the By changing cell box, enter C2.

8. Press OK.

FIGURE 12–10

USE A CUSTOM FUNCTION TO SHADE ALL CELLS CONTAINING FORMULAS

The remaining tips in this chapter describe the usage of Visual Basic for Applications (VBA) macros to enhance and optimize Excel worksheets. For the first example, we’ll write a macro that shades all cells containing formulas.

To shade all cells with formulas:

1. Press <Alt+F11> to open the Visual Basic Editor.

2. In the Insert menu, click Module.

3. Type the following macro:

Sub ColorThem()

Selection.SpecialCells (xlCellTypeFormulas).Select

With Selection.Interior

.ColorIndex = 44

.Pattern = xlSolid

End With

End Sub

FIGURE 12–11

4. In the Excel Tools menu, select Macro | Macros.

5. Select the ColorThem macro and click Run.

FIGURE 12–12

USE A CUSTOM FUNCTION TO CHANGE ALL FORMULAS IN CELLS TO VALUES

This macro changes all cells with formulas to cells containing values. Note that this means all formulas will be deleted. This is a common need when copying tables when we need just the results of a calculation and no formulas or individual formatting.

To change all formulas into values:

1. Press <Alt+F11>.

2. In the Insert menu, click Module.

3. Type the following macro:

Sub ChangeToValue()

Dim rng As Range

With ActiveSheet

For Each rng In .UsedRange

rng.Value = rng.Value

Next rng

End With

End Sub

FIGURE 12–13

NOTE

To start the macro from the Visual Basic Editor, click anywhere within the macro code and press <F5>.

USE A CUSTOM FUNCTION TO DOCUMENT AND DISPLAY ALL CELLS CONTAINING FORMULAS

This powerful macro will document in an Immediate window all cells containing formulas. When it is executed, each cell that contains a formula is listed by its cell address, along with the formula and the current value.

To determine and document all formulas in the current worksheet:

1. Press <Alt+F11>.

2. In the Insert menu, click Module.

3. Type the following macro:

Sub DocFormulasWks()

Dim rng As Range

With ActiveSheet

For Each rng In .UsedRange

If rng.HasFormula = True Then

Debug.Print "Addr.:" & rng.Address

Debug.Print "Form.:" & rng.Formula

Debug.Print "Value:" & rng.Value

End If

Next rng

End With

End Sub

4. With the cursor in the macro, start it by pressing F5.

5. Click View and choose Immediate window.

FIGURE 12–14

NOTE

If you want to document all formulas in the entire workbook, use the following macro:

FIGURE 12–15

USE A CUSTOM FUNCTION TO DELETE EXTERNAL LINKS IN A WORKSHEET

To distinguish between cells containing formulas and cells containing external links, all cells need to be checked. If a cell contains “[“ or “]”, it is a cell with a hyperlink to another workbook.

To delete all external links in a worksheet:

1. Press <Alt+F11>.

2. In the Insert menu, click Module.

3. Type the following macro:

Sub DeleteExLinks()

Dim rng As Range

With ActiveSheet

For Each rng In .UsedRange

If InStr(rng.Formula, "[") > 0 Then

rng.Value = rng.Value

End If

Next rng

End With

End Sub

NOTE

Starting this macro will delete all external links, and only values will be displayed.

USE A CUSTOM FUNCTION TO DELETE EXTERNAL LINKS IN A WORKBOOK

Like the previous macro, this macro will delete all external links; however, they will be deleted in the entire workbook, not just the current worksheet. This macro will look up all existing worksheets of a workbook and delete the external links, replacing them with values.

To delete all external links in a workbook:

1. Press <Alt+F11>.

2. In the Insert menu, click Module.

3. Type the following macro:

Sub DeleteExLinksWkb()

Dim rng As Range

Dim wks As Worksheet

For Each wks In ActiveWorkbook.Worksheets

For Each rng In wks.UsedRange

If InStr(rng.Formula, "[") > 0 Then

rng.Value = rng.Value

End If

Next rng

Next wks

End Sub

USE A CUSTOM FUNCTION TO ENTER ALL FORMULAS INTO AN ADDITIONAL WORKSHEET

This example utilizes a new worksheet with the name documentation. Once started, all formulas inside the active workbook will be documented.

To find all formulas and enter them into a worksheet:

1. Press <Alt+F11>.

2. In the Insert menu, click Module.

3. Type the following macro:

Sub NewSheetWithFormulas()

Dim rng As Range

Dim wks As Worksheet

Dim i As Integer

With Sheets("documentation")

i = 1

For Each wks In _

ActiveWorkbook.Worksheets

For Each rng In wks.UsedRange

If rng.HasFormula = True Then

.Cells(i, 1).Value = wks.Name

.Cells(i, 2).Value = rng.Address

.Cells(i, 3).Value = " " & rng.Formula

.Cells(i, 4).Value = rng.Value

i = i+1

End If

Next rng

Next wks

End With

End Sub

FIGURE 12–16

CHAPTER 13

USER-DEFINED FUNCTIONS

USE A USER-DEFINED FUNCTION TO COPY THE NAME OF A WORKSHEET INTO A CELL

To copy the name of a worksheet into a cell, you must create a user-defined function.

To copy the name of a worksheet into a cell:

1. Press <Alt+F11> to open the Visual Basic Editor.

2. In the Insert menu, click Module.

3. Type the following function:

Function TabName()

TabName = ActiveSheet.Name

End Function

FIGURE 13–1

4. Close the VBA Editor by pressing <Alt+Q>, and type the following function in cell A1: =TabName().

5. Press <Enter>.

FIGURE 13–2

USE A USER-DEFINED FUNCTION TO COPY THE NAME OF A WORKBOOK INTO A CELL

To determine the name of a workbook, including the path and current worksheet name, you can type the function =CELL("Filename") in cell A2.

FIGURE 13–3

Another way to determine the name is to write a user-defined function, as shown here.

To display the workbook name in a cell:

1. Press <Alt+F11> to open the Visual Basic Editor.

2. In the Insert menu, click Module.

3. Type the following function:

Function WkbName()

WkbName = ActiveWorkbook.Name

End Function

4. Close the VBA Editor by pressing <Alt+Q> and type the following function in cell A1: =WkbName().

5. Press <Enter>.

USE A USER-DEFINED FUNCTION TO GET THE PATH OF A WORKBOOK

Continue with the same worksheet for this task. Here we want to determine the path of the active workbook.

To find the path of a workbook:

1. Press <Alt+F11> to open the Visual Basic Editor.

2. In the Insert menu, click Module.

3. Type the following function:

Function WkbPath()

WkbPath = ActiveWorkbook.Path

End Function

4. Close the VBA Editor by pressing <Alt+Q> and type the following function in cell A1: =WkbPath().

5. Press <Enter>.

USE A USER-DEFINED FUNCTION TO GET THE FULL NAME OF A WORKBOOK

We have learned how to determine the filename and the path for a workbook. To get both at the same time, we could combine the two text strings. Another, more convenient, way, however, is to use a user-defined function that delivers both the name and path of the active workbook.

To determine the full filename and path of the workbook:

1. Press <Alt+F11> to open the Visual Basic Editor.

2. In the Insert menu, click Module.

3. Type the following function:

Function WkbFull()

WkbFull = ActiveWorkbook.FullName

End Function

4. Close the VBA Editor by pressing <Alt+Q> and type the following function in cell A1: =WkbFull().

5. Press <Enter>.

USE A USER-DEFINED FUNCTION TO DETERMINE THE CURRENT USER OF WINDOWS OR EXCEL

This tip explains how to determine the current user of Windows and/or Excel. Once again, you will write a user-defined function. In this case, the function will return the name of the current user.

To get the current Windows user:

1. Press <Alt+F11> to open the Visual Basic Editor.

2. In the Insert menu, click Module.

3. Type the following function:

Function User()

User = Environ("Username")

End Function

4. Close the VBA Editor and type the following formula in any cell: =User().

5. Press <Enter>.

To get the current Excel user:

1. Press <Alt+F11> to open the Visual Basic Editor.

2. In the Insert menu, click Module.

3. Type the following function:

Function ExcelUser()

ExcelUser = Application.UserName

End Function

4. Return to the worksheet and type the following formula in any cell: =ExcelUser().

5. Press <Enter>.

USE A USER-DEFINED FUNCTION TO DISPLAY FORMULAS OF A SPECIFIC CELL

Using this tip, you can look up the formula text of any cell. It is similar to the keyboard shortcut <Ctrl+#>. Generate a worksheet containing data and formulas and then enter the user-defined function shown below.

To make formulas visible:

1. Press <Alt+F11> to open the Visual Basic Editor.

2. In the Insert menu, click Module.

3. Type the following function:

Function FormT(rng As Range)

FormT = " " & rng.Formula

End Function

4. Return to the worksheet and type the following formula in any cell: =FormT(A7).

5. Press <Enter>.

FIGURE 13–4

USE A USER-DEFINED FUNCTION TO CHECK WHETHER A CELL CONTAINS A FORMULA

The function described here checks whether a cell contains a formula. Open a new worksheet, list some values in the range A1:A6, and sum them in cell A7. Generate a new user-defined function and use it for the range B1:B7.

To check whether a cell contains a formula:

1. Press <Alt+F11> to open the Visual Basic Editor.

2. In the Insert menu, click Module.

3. Type the following function:

Function FormYes(rng As Range)

FormYes = rng.HasFormula

End Function

4. Close the VBA Editor by pressing <Alt+Q> and type the following function in cell A1: =FormYes(A1).

5. Copy it down to cell B7 by dragging the cell handle in the bottom-right corner of cell B1.

FIGURE 13–5

USE A USER-DEFINED FUNCTION TO CHECK WHETHER A CELL CONTAINS DATA VALIDATION

When a worksheet contains data validation, sometimes it can be useful to find all cells with data validation. One way to check for this is to create a user-defined function to perform the task. First create a new worksheet and define a date validation for cell A1 that starts with 1/1/2013 and ends with 12/31/2013. Then perform the following steps.

To check whether a cell contains data validation:

1. Press <Alt+F11> to open the Visual Basic Editor.

2. In the Insert menu, click Module.

3. Type the following function:

Function Valid(rng As Range)

Dim intV As Integer

On Error GoTo errorM

intV = rng.Validation.Type

Valid = True

Exit Function

errorM:

Valid = False

End Function

4. Return to the worksheet and type the formula =Valid(A1) in cell C1.

5. Press <Enter>.

FIGURE 13–6

USE A USER-DEFINED FUNCTION TO FIND ALL COMMENTS

Cells with comments have red indicator triangles in the upper-right corners. Usually the comments are hidden and appear only if the mouse pointer is rested over that particular cell. It is also possible to hide the red indicator. One way to review all comments is to click Comments in the View menu. It is also possible to create a user-defined function that returns True if a comment is found.

To check whether a cell contains a comment:

1. Press <Alt+F11> to open the Visual Basic Editor.

2. In the Insert menu, click Module.

3. Type the following function:

Function ComT(rng As Range)

On Error GoTo errorM

If Len(rng.Comment.Text) > 0 Then _

ComT = True

Exit Function

errorM:

ComT = False

End Function

4. Close the VBA Editor by pressing <Alt+Q>, select cells C1:C5, and type the formula =ComT(A1).

5. Press <Ctrl+Enter>.

FIGURE 13–7

USE A USER-DEFINED FUNCTION TO SUM ALL SHADED CELLS

This tip shows how to sum all shaded cells. Copy the values in range A1:A6 as shown in Figure 13–8 to your worksheet. Format two of the cells with the color red and define a special user-defined function to sum them.

To sum all shaded cells:

1. Press <Alt+F11> to open the Visual Basic Editor.

2. In the Insert menu, click Module.

3. Type the following function:

Function SumColor(Area As Range, Ci As Integer)

Dim sng As Single, rng As Range

For Each rng In Area

If rng.Interior.ColorIndex = Ci Then sng = sng+rng.Value

Next rng

SumColor = sng

End Function

4. Return to cell A7 of the worksheet and type the formula =SumColor(A1:A6,3).

5. Press <Enter>.

FIGURE 13–8

NOTE

The integer value Ci is the search criterion for the background color (e.g., 1=black, 2=white, 3=red, 4=green, 5=blue, etc.).

USE A USER-DEFINED FUNCTION TO SUM ALL CELLS WITH A COLORED FONT

As learned from the previous tip, it is quite easy to sum cells that are shaded. Here we will sum all cells formatted with the font color red. Use the worksheet from the previous tip, changing the font style of two values to the color red. Create a new user-defined function as described below.

To sum all cells with a particular font color:

1. Press <Alt+F11> to open the Visual Basic Editor.

2. In the Insert menu, click Module.

3. Type the following function:

Function SumColorF(Area As Range, Ci As Integer)

Dim sng As Single, rng As Range

For Each rng In Area

If rng.Font.ColorIndex = Ci Then sng = sng+rng.Value

Next rng

SumColorF = sng

End Function

4. Return to the worksheet and in cell A7 type the following formula: =SumColorF(A1:A6,3).

5. Press <Enter>.

FIGURE 13–9

NOTE

The integer value Ci is the search criterion for font color (e.g., 1=black, 2=white, 3=red, 4=green, 5=blue).

USE A USER-DEFINED FUNCTION TO DELETE LEADING ZEROS FOR SPECIFIED CELLS

In this example, we delete all leading zeros with a user-defined function. Insert a new worksheet and type some numbers with leading zeros. You will enter an apostrophe before the first digit and continue with zeros. Create a user-defined function as shown below to delete those zeros.

To delete all leading zeros:

1. Press <Alt+F11> to open the Visual Basic Editor.

2. In the Insert menu, click Module.

3. Type the following function:

Function KillZeros(rng As Range)

Dim intS As Integer

intS = rng

While intS-Int(intS) > 0

intS = intS * 10

Wend

KillZeros = intS

End Function

4. Close the VBA Editor by pressing <Alt+Q>.

5. Select cells B1:B5 and type the formula =KillZeros(A1).

6. Press <Ctrl+Enter>.

FIGURE 13–10

USE A USER-DEFINED FUNCTION TO DELETE ALL LETTERS IN SPECIFIED CELLS

With this tip you can easily delete all letters in specified cells. Doing so manually would take a long time with a large list, but you can automate this process with a user-defined function. Copy the table shown in Figure 13–11 to a new worksheet, create the user-defined function, and test it.

To delete all letters in specified cells:

1. Press <Alt+F11> to open the Visual Basic Editor.

2. In the Insert menu, click Module.

3. Type the following function:

Function LetterOut(rng As Range)

Dim i As Integer

For i = 1 To Len(rng)

Select Case Asc (Mid(rng.Value, i, 1))

Case 0 To 64, 123 To 197

LetterOut = LetterOut & Mid(rng.Value, i, 1)

End Select

Next i

End Function

4. Return to the worksheet, select cells B1:B5, and type the formula =LetterOut(A1).

5. Press <Ctrl+Enter>.

FIGURE 13–11

USE A USER-DEFINED FUNCTION TO DELETE ALL NUMBERS IN SPECIFIED CELLS

Like the previous tip, this task deletes all numbers in specified cells. Again, without the help of a user-defined function or a special macro, this would be a difficult job and take a lot of time. A more convenient way to perform this task is with a user-defined function.

To delete all numbers in specified cells:

1. Press <Alt+F11> to open the Visual Basic Editor.

2. In the Insert menu, click Module.

3. Type the following function:

Function NumberOut(rng As Range)

Dim i As Integer

For i = 1 To Len(rng)

Select Case Asc (Mid(rng.Value, i, 1))

Case 0 To 64, 123 To 197

Case Else

NumberOut = NumberOut & _

Mid(rng.Value, i, 1)

End Select

Next i

End Function

4. Return to the worksheet, select cells B1:B5, and type the formula =NumberOut(A1).

5. Press <Ctrl+Enter>.

FIGURE 13–12

USE A USER-DEFINED FUNCTION TO DETERMINE THE POSITION OF THE FIRST NUMBER

The user-defined function described here determines the position of the first number in a text string in a cell.

To determine the position of the first number:

1. Type any data with letters and numbers in cells A1:A5.

2. Press <Alt+F11> to open the Visual Basic Editor.

3. In the Insert menu, click Module.

4. Type the following function:

Function FirstNum(rng As Range)

Dim i As Integer

For i = 1 To Len(rng.Value)

Select Case Mid(rng.Value, i, 1)

Case 0 To 9

FirstNum = i

Exit Function

End Select

Next i

End Function

5. Close the VBA Editor by pressing <Alt+Q>.

6. Select cells B1:B5 and type the formula =FirstNum(A1).

7. Press <Ctrl+Enter>.

FIGURE 13–13

USE A USER-DEFINED FUNCTION TO CALCULATE THE CROSS SUM OF A CELL

With this tip, you can calculate the cross sum of a cell. Create a table like the one in Figure 13–14 and type any numeric data in cells A1:A5.

To calculate the cross sum of a cell:

1. Press <Alt+F11> to open the Visual Basic Editor.

2. In the Insert menu, click Module.

3. Type the following function:

Function Qs(rng As Range)

Dim i As Integer

For i = 1 To Len(rng.Value)

Qs = Qs+Cint (Mid(rng.Value, i, 1))

Next i

End Function

4. Close the VBA Editor by pressing <Alt+Q>.

5. Select cells B1:B5 and type the formula =Qs(A1).

6. Press <Ctrl+Enter>.

FIGURE 13–14

USE A USER-DEFINED FUNCTION TO SUM EACH CELL’S CROSS SUM IN A RANGE

Continuing from the previous example, now we want to sum each cell’s cross sum in a range. Create a table like the one in Figure 13–15 and calculate cross sums in a specified range with a new user-defined function.

To sum each cell’s cross sum in a range:

1. Press <Alt+F11> to open the Visual Basic Editor.

2. In the Insert menu, click Module.

3. Type the following function:

Function QsE(Area As Range)

Dim i As Integer

Dim rng As Range

For Each rng In Area

For i = 1 To Len(rng.Value)

QsE = QsE+CInt (Mid(rng.Value, i, 1))

Next i

Next rng

End Function

4. Close the VBA Editor by pressing <Alt+Q>.

5. In cell B1, type the following formula: =QsE(A1:A5).

6. Press <Enter>.

FIGURE 13–15

USE A USER-DEFINED FUNCTION TO CHECK WHETHER A WORKSHEET IS EMPTY

Sometimes it is necessary to check whether a worksheet is empty or still contains hidden formulas. To do this, choose Worksheet in the Insert menu to add a new worksheet to the current workbook and write a user-defined function in the Visual Basic Editor as described below.

To check whether a worksheet is empty:

1. Press <Alt+F11> to open the Visual Basic Editor.

2. In the Insert menu, click Module.

3. Type the following function:

Function ShEmpty(s As String) As Boolean

If Application.CountA (Sheets(s).UsedRange) = 0 Then

ShEmpty = True

Else

ShEmpty = False

End If

End Function

4. Close the VBA Editor by pressing <Alt+Q>.

5. Select any cell in the worksheet and type the formula =ShEmpty("Sheet15"). Be sure to replace “Sheet15” with the name of the sheet you want to check.

6. Press <Enter>.

USE A USER-DEFINED FUNCTION TO CHECK WHETHER A WORKSHEET IS PROTECTED

The function described here checks whether a worksheet is protected. First you must create a worksheet and protect it, then you can write a user-defined function to test it.

To check whether a worksheet is protected:

1. Press <Alt+F11> to open the Visual Basic Editor.

2. In the Insert menu, click Module.

3. Type the following function:

Function ShProt(s As String) As Boolean

On Error GoTo errorM

If Sheets(s).ProtectContents = True Then

ShProt = True

End If

Exit Function

errorM:

ShProt = False

End Function

4. Close the VBA Editor by pressing <Alt+Q>.

5. Select any cell in the worksheet and type the formula =shProt("Sheet15"). Be sure to replace “Sheet15” with the name of the sheet whose protection you want to check.

6. Press <Enter>.

USE A USER-DEFINED FUNCTION TO CREATE YOUR OWN AUTOTEXT

The last tip in this chapter provides a way to use AutoText inside your worksheet. This functionality can be useful for many different Excel-based tasks.

To create your own AutoText:

1. Press <Alt+F11> to open the Visual Basic Editor.

2. In the Insert menu, click Module.

3. Type the following function:

Function AuTxt(rng As Range) As String

Select Case rng.Value

Case 1

AuTxt = "fire"

Case 2

AuTxt = "water"

Case 3

AuTxt = "heaven"

Case Else

AuTxt = "invalid text"

End Select

End Function

4. Return to the worksheet. Select cells B1:B4 or a much larger range and type the formula =AuTxt(A1).

5. Press <Ctrl+Enter>.

FIGURE 13–16

CHAPTER 14

EXAMPLES

This chapter is about how to use the Excel formulas and functions that have been discussed and to gain some more experience with them as well. With these exercises, you need to determine which functions are best to solve the task. Try to solve the tasks and consult the previous chapters if necessary.

CALCULATE AVERAGE FUEL CONSUMPTION

Figure 14–1 lists miles driven and number of gallons used. What is the average consumption for 100 miles?

FIGURE 14–1

To determine average fuel consumption:

1. In a worksheet, copy the data shown in cells A4:D12 in Figure 14–2.

2. Select cells D5:D12.

3. Type the formula =C5/B5*100.

4. Press <Ctrl+Enter>.

5. Calculate the average consumption by selecting cell D15 and typing the formula =AVERAGE(D5:D12).

6. Press <Enter>.

FIGURE 14–2

Extend the task to indicate the lowest and highest daily gas consumption. Both values should be formatted individually. The highest value needs to be shaded in red and the lowest shaded in green. In addition, the whole row rather than just the individual cell should be shaded. These requirements can be solved with conditional formatting.

1. Select cells A5:D12.

2. From the Home tab, go to the Styles bar and click on Conditional Formatting.

3. Choose New Rule.

4. In the Select a Rule Type dialog, select Use a formula to determine which cells to format.

5. In the Edit box, type the following formula: =$D5=MAX($D$5:$D$12).

6. Click Format, select Red from the Fill tab when the cell value meets the condition, and click OK.

7. Repeat step 2 and choose Manage Rule.

8. Click New Rule and insert the following formula: =$D5=MIN($D$5:$D$12).

9. Repeat step 6 but select Green.

10. Click OK.

FIGURE 14–3

CALCULATE NET AND CORRESPONDING GROSS PRICES

Figure 14–4 shows a gross price and a net price. Calculate the corresponding values using a tax rate of 7%.

FIGURE 14–4

The net price needs to be calculated in cell C5.

To calculate the net price:

1. Select cell C5.

2. Type the formula =B5+(B5*A5) and press <Enter>.

The gross price needs to be calculated in cell B7.

To calculate the gross price:

1. Select cell B7.

2. Type the formula =C7/(1+A7).

3. Press <Enter>.

FIGURE 14–5

DETERMINE THE ECONOMIC VALUE OF A PRODUCT

The table in Figure 14–6 lists the costs, prices, and profit margins of various products. Determine which product is most profitable and use conditional formatting to format it.

FIGURE 14–6

To determine the economic value:

1. Using the information in Figure 14–6, select cells E5:E12.

2. Type the formula =D5/C5.

3. Press <Ctrl+Enter>.

4. Select cells B5:E12.

5. From the Home tab, go to the Styles bar and click on Conditional Formatting.

6. Choose New Rule.

7. In the Select a Rule Type dialog, select Use a formula to determine which cells to format.

8.In the Edit box, type the following formula: =$E5=MAX($E$5:$E$12).

9. Click Format, select a color from the Fill tab, and click OK.

10. Click OK.

FIGURE 14–7

CALCULATE THE FINAL PRICE OF A PRODUCT, TAKING INTO ACCOUNT REBATES AND PRICE REDUCTIONS

Look at the price table in Figure 14–8. The net price of a tractor is listed along with an agreed-upon rebate and a price reduction because of minor defects. To calculate the total price, the reductions need to be considered and then the taxes must be added. Your task is to calculate the final price of the tractor.

FIGURE 14–8

To calculate the final price:

1. Select cell B9.

2. Enter the following formula: = B4*(1-B5)*(1-B6)*(1+B7).

3. Press <Enter>.

The order of the parameters is not important when multiplying.

FIGURE 14–9

SEARCH FOR DATA THAT MEETS SPECIFIC CRITERIA

Figure 14–10 lists dates and corresponding sales. Your task is to sum all sales that are more than $500.

FIGURE 14–10

There are various ways to solve this task. One solution is to mark the values that fit the given criteria.

1. Select cells C9:C23.

2. Type the formula =AND(A9>$B$5,B9>$B$6).

3. Press <Ctrl+Enter>.

4. Select cell C25.

5. Type the formula =SUMIF(C9:C23,TRUE,B9:B23).

6. Press <Enter>.

If you’d like to use the built-in data filter, filter column C for the entry TRUE:

1. Select cell C8.

2. Select Filter | AutoFilter from the Data menu.

3. In cell C8, select TRUE from the drop-down box to filter the list.

FIGURE 14–11

NOTE

When you calculate the sum of a filtered list, usually the hidden cells are added as well. Therefore, use the SUBTOTAL function rather than the SUM function. The easiest way to do this is to place the mouse cursor in the target cell and click on the AutoSum symbol in the Standard menu. Excel automatically recognizes the filtered list and uses the correct function, which in this case is SUBTOTAL.

SEPARATE CITIES FROM ZIP CODES

The table in Figure 14–12 lists zip codes and their corresponding cities. This information should be separated and shown in two separate columns.

FIGURE 14–12

To separate data:

1. Select cells B5:B12.

2. Type the formula =LEFT(A5,SEARCH(" ",A5)-1).

3. Press <Ctrl+Enter>.

4. Select cells C5:C12.

5. Type the formula =RIGHT(A5,LEN(A5)-(SEARCH(" ",A5))).

6. Press <Ctrl+Enter>.

FIGURE 14–13

ELIMINATE SPECIFIC CHARACTERS

Various telephone numbers are listed in the following table and formatted in a variety of ways. Some contain hyphens or slashes, while others contain spaces.

FIGURE 14–14

To eliminate specific characters:

1. Select cells B5:B11.

2. Type the formula =SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A5,"-",""),".",""),"/","").

3. Press <Ctrl+Enter>.

FIGURE 14–15

COMBINE TEXT, DATES, AND TIMESTAMPS

In this example, there is text that should be combined with dates and times and presented in a single cell. Excel needs to be “tricked” to produce the correct result.

FIGURE 14–16

To combine dates, times, and text:

1. Select cell A8.

2. Type the formula ="Attention " & B4 & " starts " & TEXT(B5,"DD.MM.YYYY") & " at exactly " & TEXT(B6,"hh:mm") & " !".

3. Press <Enter>.

FIGURE 14–17

DETERMINE THE LAST DAY OF A MONTH

The table in Figure 14–18 contains a number of dates. Your task is to determine the day of the week that falls on the last day of the month for each date, considering the length of each month.

FIGURE 14–18

To solve this task, you will need to install the Analysis ToolPak add-in for Excel, if it has not already been installed. From the Tools menu, select Add-Ins. In the dialog that appears, select Analysis ToolPak and confirm with OK. Now you can proceed as described below:

1. Using the data shown in cells A5:D12 of Figure 14–19, select cells C6:C12.

2. Type the formula =EOMONTH(A6,B6).

3. Press <Ctrl+Enter>.

4. Select cells D6:D12.

5. Type the formula =C6.

6. Press <Ctrl+Enter>.

7. In the Home tab, go to the Cells bar and click on Format.

8. Select Format Cells and then the Custom option in the Number tab.

9. Type DDDD.

10. Press OK.

FIGURE 14–19

DETERMINE THE NUMBER OF AVAILABLE WORKDAYS

This task shows the time frame of a project. There are weekends between the start date and the end date, which are usually not workdays. Only the actual workdays need to be determined. Excel supports this task with a specific table function called NETWORKDAYS, which can be found in the Analysis ToolPak add-in.

FIGURE 14–20

In addition to finding the weekends, the NETWORKDAYS function can be used to find holidays. To solve this extended task, some holidays have been entered in cells E2:E8. Of course, it is possible to extend this list for additional non-workdays, such as company parties and various promotions.

Determine the available workdays for the given time frame, taking into account additional non-workdays:

1. Select cell C5.

2. Type the formula =NETWORKDAYS(A5,B5,E2:E8).

3. Press <Enter>.

FIGURE 14–21

NOTE

The WORKDAY function is like the NETWORKDAYS function. WORKDAY needs a start date and the number of workdays and will calculate the end date, considering weekends and holidays.

DETERMINE A PERSON’S EXACT AGE

Figure 14–22 shows a list of various people and their birth dates. Your task is to determine the exact age of each person in years, months, and days.

FIGURE 14–22

To determine the age of a person:

1. Select cells C6:C11.

2. Type the formula =DATEDIF(B6,$B$3,"Y") & " years and " & DATEDIF(B6,$B$3,"YM") & " months and " & DATEDIF(B6,$B$3,"MD") & " days".

3. Press <Ctrl+Enter>.

FIGURE 14–23

NOTE

The #NUM! will appear in a cell when the Birthday is after the Date to which it is being compared. The DATEDIF function requires that the first argument passed is less than or equal to the second parameter. Therefore, if you enter a Birthday of 9/26/2013 you will see the Age as being “0 years and 0 months and 0 days.”

DETERMINE THE NUMBER OF VALUES IN A SPECIFIC RANGE

Figure 14–24 shows a table containing different values. Your task is to count the number of values that are between 50 and 100. This task can be solved easily with an array formula.

FIGURE 14–24

To determine the number of values in a specific range:

1. Select cell D6.

2. Type the array formula =SUM((A5:A16>=50)*(A5:A16<=100)).

3. With the cursor at the end of the statement while in the formula bar, press <Ctrl+Shift+Enter>.

FIGURE 14–25

NOTE

The braces in the formula are generated automatically with the keyboard combination <Ctrl+Shift+Enter>. If you manually enter the braces, the formula will not work.

If you need to sum the values in a certain range need to be instead of counted, use this solution:

1. Select cell D7.

2. Type the array formula =SUM(IF(A5:A16>=50,IF(A5:A16<100,A5:A16))).

3. With the cursor at the end of the statement while in the formula bar, press <Ctrl+Shift+Enter>.

FIGURE 14–26

DETERMINE THE WEEKLY SALES FOR EACH DEPARTMENT

This example involves an unsorted list of sales by individual employees from different departments. Your task is to calculate the weekly sales for each department.

FIGURE 14–27

To determine weekly sales:

1. Using the data shown in Figure 14–28, select cells F6:F9.

2. Type the formula =SUMIF($A$6:$A$16,E6,$C$6:$C$16).

3. With the cursor at the end of the statement while in the formula bar, press <Ctrl+Shift+Enter>.

FIGURE 14–28

Because of the different sizes of each department, the weekly sales figures do not really indicate anything about the performance of each salesperson. As an example, the Food department has more salespeople than the Perfume department. To break down the average sales in each department, you need to consider the number of employees for each department. Now let’s determine the average weekly sales per employee for each department and shade the department with the best performance.

1. Select cells G6:G9.

2. Type the formula =F6/COUNTIF($A$6:$A$16,E6).

3. Press <Ctrl+Enter>.

4. Select cells E6:G9.

5. From the Home tab, go to the Styles bar and click on Conditional Formatting.

6. Choose New Rule.

7. In the Select a Rule Type dialog, select Use a formula to determine which cells to format.

8. In the Edit box, type the following formula: =$G6=MAX($G$6:$G$9).

9. Click Format, select a color from the Fill tab, and click OK.

10. Click OK.

FIGURE 14–29

ROUND A VALUE TO THE NEAREST 5 CENTS

In this example, the dollar values need to be rounded to the nearest number divisible by 5; i.e., the rounded number must end with 0 or 5. There are various functions inside Excel for rounding values, but the best function for this task is the MROUND function. It can be used only if the Analysis ToolPak add-in has been installed.

FIGURE 14–30

To round to a value that ends with 0 or 5:

1. Select cells B5:B11.

2. Type the formula =MROUND(A5, 0.05).

3. Press <Ctrl+Enter>.

FIGURE 14–31

DETERMINING INVENTORY VALUE

Figure 14–32 shows a list of items that are in stock, along with their cost and current quantity. Your task is to calculate the total value of the items in inventory.

FIGURE 14–32

It is certainly possible to solve this task by adding an additional column to calculate a total for each item and sum those values. But there is a much easier way!

To determine the value of the inventory:

1. Using the data in Figure 14–33, select cell C13.

2. Type the formula =SUMPRODUCT(B6:B11,C6:C11).

3. Press <Enter>.

FIGURE 14–33

DETERMINE THE TOP SALESPERSON FOR A MONTH

Figure 14–34 presents a list of salespeople and their monthly sales volume. Your task is to determine the highest sales total each month and mark it in the list.

FIGURE 14–34

To determine the top salesperson:

1. Using the data shown in Figure 14–35, select cells B4:E4.

2. Type the formula =MAX(B6:B14).

3. Press <Ctrl+Enter>.

4. Select cells B6:E14.

5. From the Home tab, go to the Styles bar and click on Conditional Formatting.

6. Choose New Rule.

7. In the Select a Rule Type dialog, select Use a formula to determine which cells to format.

8. In the Edit box, type the following formula: =B6=B$4.

9. Click Format, select a color from the Fill tab, and click OK.

10. Click OK.

FIGURE 14–35

DETERMINE THE THREE HIGHEST VALUES IN A LIST

A particular area has a speed limit of 20 miles per hour. All drivers who have exceeded that speed limit are listed in the following Excel table. Your task is to determine and mark the three fastest drivers who will receive a ticket for speeding.

FIGURE 14–36

To determine the fastest driver:

1. Using the data shown in Figure 14–36, select cells F11:F13.

2. Type the formula =LARGE($C$5:$C$14, E11).

3. Press <Ctrl+Enter>.

4. Select cells A5:D14.

5. From the Home tab, go to the Styles bar and click on Conditional Formatting.

6. Choose New Rule.

7. In the Select a Rule Type dialog, select Use a formula to determine which cells to format.

8. In the Edit box, type the following formula: =$C5=$F$11.

9. Click Format, select a color from the Fill tab, and click OK.

10. Insert Condition 2 and Condition 3 as shown in Figure 14–37 by clicking New Rule.

FIGURE 14–37

11. Click OK.

FIGURE 14–38

DETERMINE AMOUNT TO INVEST

To determine how much to invest, there are various factors that need to be considered. First, you need to know if the cost of the investment will be covered by its yearly return. You also need to know the length of the investment and the annual interest rate. All this information can be compared by using the PV formula.

FIGURE 14–39

To determine the cost of an investment:

1. Using the data shown in Figure 14–39, select cell C11.

2. Type the formula =-PV(C9,C8,C7).

3. Press <Enter>.

FIGURE 14–40

DETERMINE HOW MANY ITEMS ARE IN VARIOUS CATEGORIES

It is possible to use different solutions to address this task, including Pivot tables and the SUBTOTAL, COUNTIF, and DCOUNTA functions. Here we use the DCOUNTA function.

FIGURE 14–41

To count all items in the Components category:

1. Using the data shown in Figure 14–42, select cell C4.

2. Type Components.

3. Select cell C5.

4. Type the formula =DCOUNTA($A$7:$E$52,C7,$A$3:$E$4).

5. Press <Enter>.

FIGURE 14–42

FIND A SPECIFIC VALUE IN A COMPLEX LIST

Different flights are listed in the table in Figure 14–43. When a passenger enters a flight number, the corresponding flight information should be shown.

FIGURE 14–43

As seen in Figure 14–43, a list of flights starts in row 7. The search field to enter the required flight number is cell B1. Cells B2:B4 display the corresponding flight information if available.

To display specific values from a list:

1. Select cell B2.

2. Type the formula =VLOOKUP($B$1,$A$6:$E$15,2,FALSE).

3. Select cell B3.

4. Type the formula =VLOOKUP($B$1,$A$6:$E$15,3, FALSE).

5. Select cell B4.

6. Type the formula =VLOOKUP($B$1,$A$6:$E$15,4,FALSE) & " / " & VLOOKUP($B$1,$A$6:$E$15,5,FALSE).

FIGURE 14–44

If you need to shade the corresponding row in the range A7:E15, use Excel’s conditional formatting feature as described here:

1. Select cells A7:E15.

2. From the Home tab, go to the Styles bar and click on Conditional Formatting.

3. Choose New Rule.

4. In the Select a Rule Type dialog, select Use a formula to determine which cells to format.

5. In the Edit box, type the following formula: =$A7=$B$1.

6. Click Format, select a color from the Fill tab, and click OK.

7. Click OK.

FIGURE 14–45

DYNAMICALLY SHOW COSTS AND SALES PER DAY

The table in Figure 14–46 contains cost and sales values per day. After the desired date is entered, the corresponding cost and sales values should be found and displayed.

FIGURE 14–46

To dynamically show costs and sales per day:

1. Using the data shown in Figure 14–47, select cell C5.

2. Type the formula =HLOOKUP($B$5,$B$8:$G$10,2,FALSE).

3. Press <Enter>.

4. Select cell D5.

5. Type the formula =HLOOKUP($B$5,$B$8:$G$10,3,FALSE).

6. Press <Enter>.

FIGURE 14–47

For this example, it is also good to use conditional formatting to mark the results in the table, as shown in Figure 14–48:

1. Select cells B8:G10.

2. From the Home tab, go to the Styles bar and click on Conditional Formatting.

3. Choose New Rule.

4. In the Select a Rule Type dialog, select Use a formula to determine which cells to format.

5. In the Edit box, type the following formula: =B$8=$B$5.

6. Click Format, select a color from the Fill tab and click OK.

7. Click OK.

FIGURE 14–48

EXTRACT EVERY FOURTH VALUE FROM A LIST

A list of measurements taken every two minutes is shown in Figure 14–49. Your task is to extract every fourth value after the first from the list and transfer that value to another list.

FIGURE 14–49

To extract every fourth value:

1. Using the data shown in Figure 14–50, select cells D2:D5.

2. Type the formula =OFFSET($B$2,(ROW()-2)*4,0).

3. Press <Ctrl+Enter>.

FIGURE 14–50

DISPLAY NAMES IN A LIST OR IN AN ARRAY

You have a list of names on a spreadsheet but wish to view them another way or you wish to use an array output to be used in another formula.

To display the names in a list that is easy to read or format into an array that you can use in another formula:

1. Type in a list of names in cells A1:A10 or copy the data shown in Figure 14–51.

2. Copy cells C1:C2 to be used as labels.

3. In cell D1, type the formula =ARRAYTOTEXT($A$1:$A$12,0)

4. Press <Enter>.

5. In cell D2, type the formula =ARRAYTOTEXT($A$1:$A$12,1)

6. Press <Enter>.

FIGURE 14–51

NOTE

The 2nd parameter “Format” tells the function how to display the data: “0” or “False” will display the data in a simple list while “1” or “True” will display the data in an array. You will notice that the array automatically contains brackets and quotes around each piece of data. This is valuable and can be used in other formulas that use arrays rather than simple text.

FILTER FOR CERTAIN JOB POSITIONS

You have a list of names along with their job positions on a spreadsheet and wish to create a list of names based on their job positions without upsetting the original list. Using the array function “FILTER” we can do this.

To display a list of names whose job position matches what you are requesting:

1. Type in a list of names in cells A1:A10 or copy the data shown in Figure 14–52.

2. Type in a list of positions in cells B1:B10 or copy the data shown in Figure 14–52.

3. In cell E1, type in one of the positions you listed in cells B1:B10.

4. In cell E3, type the formula =FILTER(A1:B10,B1:B10=E1,"None Found")

5. Press <Enter>.

FIGURE 14–52

NOTE

If you type in a job position that is not listed in cells B1:B10 you will receive the “None Found” message which is the third parameter of the “FILTER” function.

DISPLAY THE MILE TIME FOR A RUNNER

You have a list of runners with their mile times and their number tags. How do we pull their names and their mile times by entering their respective number tags? Using the functions “LET” and “XLOOKUP” we can do this.

To display the name and mile time of a runner with a certain number tag:

1. Type in a list of runners in cells A2:A11 or copy the data shown in Figure 14–53.

2. Type in number tags for each runner in cells B2:B11 or copy the data shown in Figure 14–53.

3. Highlight cells C2:C11.

4. Press <Ctrl+1> to bring up the “Format Cells” dialog box. See Figure 14–54.

5. Within the “Number” tab, select “Custom.”

6. Under the “Type” description, type in “mm:ss” (this will display the times in minutes and seconds).

7. Press OK to save and exit.

8. In cells C2:C11, enter times in the format “12:MM:SS AM”. This is a bit awkward in Excel and there are various methods to enter time but for this example we will use this method. For example, to enter a time of five minutes and 10 seconds you would enter “12:05:10 AM”.

9. In cell F2, enter one of the number tags you entered in cells B2:B11.

10. In cell F4, type the formula =LET(name,XLOOKUP(F2,$B$2:$B$11,A2:A11),time,XLOOKUP(F2,$B$2:$B$11,C2:C11), name & " ran the mile in " & TEXT(time,"mm:ss"))

11. Press <Enter>.

FIGURE 14–53

FIGURE 14–54

NOTE

The LET function sets the variables “name” and “time.” The XLOOKUP uses the number tag you entered in cell F2 to give values to “name” and “time.” The last parameter of the LET function uses the values for “name” and “time” to create a sentence of the runner and his/her time. It is also important to note that you can also display this message using the MATCH/INDEX combination. But in large databases with many columns the XLOOKUP is more efficient and easier to read.

CREATE A LIST OF RANDOM TELEPHONE NUMBERS

The RANDARRAY function can create a list of telephone numbers or any other type of number you wish. This is helpful when creating a large database you wish to test against without using real phone numbers tied to individuals.

To display a list of 48 random phone numbers over 12 rows and 4 columns:

1. On a blank worksheet in cell A1, type the formula =RANDARRAY(12,4,1111111111,9999999999,TRUE) (see Figure 14–55).

2. Press <Enter>.

3. Highlight cells A1:D12.

4. Press <Ctrl+1> to bring up the “Format Cells” dialog box.

5. Within the “Number” tab click the “Special” category and click the “Phone Number” type. (see Figure 14–56).

6. Press OK.

7. Highlight columns A:D by clicking on the “A” on column A and then highlighting over to column D.

8. As shown in Figure 14–57, click on the “Home” menu option at the top.

9. Within the “cells” menu group, click “Format” then “AutoFit Column Width.” This will adjust the column widths so that you can see the phone numbers.

FIGURE 14–55

FIGURE 14–56

FIGURE 14–57

CREATE A LIST OF SEQUENTIAL FRIDAY DATES

To create a sequence of any group of numbers you can use the SEQUENCE function. In this example, we are going to create a sequence of Fridays. We can do this since dates are stored as numbers within Excel.

To display a list of 12 sequential Fridays:

1. On a blank worksheet in cell A1, type the formula =SEQUENCE(12,1,DATE(2022,1,7),7) (see Figure 14–58).

2. Press <Enter>.

3. Highlight cells A1:A12.

4. Press <Ctrl+1> to bring up the “Format Cells” dialog box.

5. Within the “Number” tab click the “Date” category and select any date format you wish. In this example, we selected “03/14/12” to display the date as a two-digit month, two-digit day and two-digit year. (see Figure 14–59).

6. Press OK.

7. Highlight cells B1:B12.

8. Type in the formula =TEXT(A1,"Ddd").

9. Press <Ctrl+Enter>. This will display the days of the week corresponding to the dates listed in column A.

FIGURE 14–58

FIGURE 14–59

SORT A LIST OF NAMES

To create a separate list that sorts name of another list without upsetting the original data use the “SORT” function.

To sort a list of 12 names in another column separate from the original list:

1. On a blank worksheet type the names of 12 individuals into cells A2:A13 or copy the list as seen in Figure 14–60.

2. In cell D2, type the formula =SORT(A2:A13,1,-1).

3. Press <Enter>.

FIGURE 14–60

NOTE

The 3rd parameter of the SORT function dictates whether or not the sort is ascending or descending. In this example, we sorted in descending order. To sort in an ascending order, enter a 1 or leave it blank which automatically defaults to ascending order.

SORT A LIST OF NAMES TO INCLUDE ALL THEIR DATA

To create a separate list that sorts names and other attributes tied to the name, use the SORTBY function. In this example, we list the person’s age along with the country in which they reside.

To sort a table of names, age and city into another column separate from the original list:

1. On a blank worksheet type the names of 12 individuals into cells A2:A13 or copy the list as seen in Figure 14–61.

2. Highlight cells B2:B13.

3. Type the formula =RANDBETWEEN(18,99)

4. Press <Ctrl+Enter> (this gives you a random list of ages rather than to type them in directly).

5. In cells C2:C13, type in a list of cities or copy them from the spreadsheet depicted in Figure 14–61.

6. In cell E2, type the formula =SORTBY(A2:C13,B2:B13)

7. Press <Enter>.

FIGURE 14–61

NOTE

The 3rd parameter of the SORTBY function dictates whether or not the sort is ascending or descending. In this example, we sorted in descending order. To sort in an ascending order, enter a 1 or leave it blank which automatically defaults to ascending order.

LIST UNIQUE DATA BASED ON NAMES AND CITY

In order to clean up databases, there is a need to remove duplicate information. In this example, we are searching for a person with the same address so that we can review and potentially remove it from our database. To create a separate list of unique names and addresses use UNIQUE function.

To display a separate list of names and addresses and display them into another column separate from the original list:

1. On a blank worksheet type the names of 12 individuals into cells A2:A13 or copy the list as seen in Figure 14–62.

2. Type in addresses for each in cells B2:B13 or copy the list as seen in Figure 14–62.

3. In cell E2, type the formula =UNIQUE(A2:B13,0,0).

4. Press <Enter>.

FIGURE 14–62

NOTE

The way we wrote this function aids us in looking for duplicate rows where the NAME and the ADDRESS are the same. If we wanted to only look for duplicate names without regard to a duplicate address, the 1st parameter would be A2:A13.

RETRIEVE STUDENT’S MATH AND HISTORY SCORES

With a database of hundreds or thousands of records (rows), it is easier to enter a value to retrieve certain pieces of information rather than search for it. In this example, we have a list of students along with their math and history test scores. In addition, the name is in the third column precluding us from using the VLOOKUP function. Although we can use the MATCH/INDEX combination, we are going to use the XLOOKUP function since with large databases, XLOOKUP is more efficient and easier to read. Additionally, we are going to use “Data Validation” so that the name we select is in the list. In other words, this limits the choices of students to the actual list of students thereby reducing errors.

To list math and history scores for a student:

1. On a blank worksheet either copy the math scores, history scores and the names in Figure 14–63 or type your own in.

2. In cell E2, type the phrase “Enter Name:”.

3. Click cell F2, and on the top menu bar click the “Data” menu option.

4. Within the “Data Tools” menu group, click “Data Validation” then “Data Validation” again – yes, this is a duplicate menu option. (see Figure 14–63).

5. In the “Data Validation” dialog box that appears (see Figure 14–64), in the “Settings” tab, select “List” under the “Allow” option.

6. In the same dialog box, under source type in =$C$2:$C$13.

7. Press OK.

8. In cell G2, type the formula =XLOOKUP(F2,C2:C13,A2:B13,"not found").

9. Press <Enter>.

FIGURE 14–63

FIGURE 14–64

NOTE

Since this is an array formula, it automatically displays the requested data into two columns. If the third parameter was A2:A13, then it would have only displayed the math score. The other item to note is that we searched from the third column rather than the first column which is a requirement when using VLOOKUP.

RETRIEVE STUDENT’S TOTAL SCORE

Similar to the previous example we are going to display the total score of a student’s math and history score in one formula.

To list math and history scores for a student:

1. On a blank worksheet either copy the math scores, history scores and the names in Figure 14–65 or type your own in.

2. Highlight cells D2:D13.

3. Type the formula =A2+B2.

4. Press <Ctrl+Enter>.

5. In cell F2, type the phrase “Enter Name:”.

6. Click cell G2, and on the top menu bar click the “Data” menu option.

7. Within the “Data Tools” menu group, click “Data Validation” then “Data Validation” again – yes this is a duplicate menu option. (see —Figure 14–65).

8. In the “Data Validation” dialog box that appears (see Figure 14–66), in the “Settings” tab, select “List” under the “Allow” option.

9. In the same dialog box, under source type in =$C$2:$C$13.

10. Press OK.

11. In cell G3, type the formula =INDEX(D2:D13,XMATCH(G2,C2:C13,0),1).

12. Press <Enter>.

FIGURE 14–65

FIGURE 14–66

CHAPTER 15

OTHER FEATURES

This chapter explains features within Excel that are beyond formulas. These features enhance the Excel experience and provide extended presentation views, access to internet data, and quicker methods to move around Excel.

INSERT ICONS

Table 15–1 displays a list of four food items with corresponding sales. We will create icons for each food item and show you how to link them to a website.

FIGURE 15–1

To add icons

1. In a worksheet, copy the data shown in cells C4:D7 in Figure 15–1.

2. Click in cell B4.

3. On the menu bar, click Insert, then Illustrations, then Icons. When the Icons dialog box appears, click on Food and Drinks then double-click the pizza icon. At this point the pizza image appears in cell B4. To shrink, click on the image so that the box appears around the pizza image. Place the cursor over the circle in the lower left corner of the image. The cursor should change to a diagonal arrow. Click and hold on the diagonal arrow, then drag the circle up and left until the image is small enough to fit in cell B4.

4. Right-Click on the image and select Link then Insert Link. Type in (or paste in) a website address or reference to another place in the workbook in the Address box.

5. Repeat steps 3 and 4 for Popcorn, Apples and Candy in cells B5, B6 and B7 respectively.

Below is the worksheet with all icons inserted in the corresponding B column.

FIGURE 15–2

DRAW FREESTYLE

In this example, we are going to use the Draw features. Open a worksheet and on the top menu bar, click on Draw. You will see a box of pens and highlighters in different colors. You can change these by clicking the Add Pen icon to the right of the box. But for now, we will use the defaults.

1. Click on the Red Pen and manually draw the word “Hi” with your mouse over cell B4. You can make it as large or as small as you wish. Once done with your word, press the Esc button on your keyboard to release the pen. The drawing is now an image on the worksheet, and you can move or modify it anyway you wish.

2. Next click on Draw and select the yellow highlighter. Then go to cell B9 and drag the highlighter across a few cells to the right. Then press ESC on your keyboard to release the highlighter.

3. Now click on Draw again. Find Ink to Math and click on it. A dialog box will appear in which you can write any math equation you wish. In this example, write as close as you can get it. It does not have to be perfect. Once you click on Insert, the formula will be cleanly inserted as an image into the cell you originally clicked. The formula will appear in the middle of the worksheet. You can now click on it and move it around to wherever you wish and re-size it to your liking.

FIGURE 15–3

One final example exhibiting the ability to erase.

1. Click on Draw again, then the red highlighter and trace it across cells B15 to D17 and then again in cells B17 to D17. This will produce two stripes.

2. Then go back to Draw and click on Eraser, then click on the second red highlight. This will erase the second red highlight appear in cells B17 to D17.

The final display will look like Figure 15–4.

As a final example you can replay the steps you created in this example by going into the Draw menu again and clicking on Ink Replay. This will replay the steps you just did on this worksheet.

FIGURE 15–4

SMART LOOKUP

Smart Lookup gathers information from a Bing search about a word or phrase that you highlight.

1. Copy the food items and sales you created in the first example in this chapter on the icons worksheet.

2. Paste them in cells C4 to D7. Right-click on cell C4 – Pizza – and select Smart Lookup.

A box will appear to the right as though you searched for “Pizza” on the web. You can scroll down the right and discover pages and images for what you looked up. There is also a “Define” option to the right that will display definitions of what you used the Smart Lookup for.

The Lookup and Definitions are based on Microsoft’s Bing Search. There are ways to change this through your computers Registry and code, but this is beyond the scope of this book. An Internet search will yield solutions on this matter for you.

FIGURE 15–5

SHARE FILES

You also can share the current Excel file you have open with others via a web location or a network folder.

1. To share the Excel file, you are using with others over the web or a network so they can edit and view, click on the Share icon in the upper right-hand corner of the screen.

2. Then click on the location whether it be a shared folder on a network on a folder in the cloud. You will then see a screen on the right side of Excel in which you can enter emails of those you wish to view and edit your current workbook.

3. Enter email addresses then click Share. You can also click the address box to the right and select names from current email lists you have stored in your outlook.

FIGURE 15–6

FIGURE 15–7

FLASH FILL

Flash Fill is a feature that will allow you to fill in cells based upon logic you have entered information into another cell. In this instance, Excel is can fill in patterns that you are attempting to enter.

1. Open a new worksheet and enter in the names listed in cells C4 to D7.

2. Then go to cell E4 and type in BR for the initials of the first and last name of the existing name in cells C4 and D4.

3. Then highlight cells E4 to E7, click on Home, then on the far right within the Editing group, click on Fill then Flash Fill. This will fill in the cells E5 to E7 based on the logic you displayed in cell E4. In this case, it took the first letter of the cells in column C and D and created initials for the names listed in cells C5 to D7.

FIGURE 15–8

FIGURE 15–9

QUICK ANALYSIS TOOL

There is a quick way to highlight data and create charts from data without having to go through the conditional formatting and charts menu.

1. Copy the data in cells C3 to D8 into a blank worksheet.

2. Highlight cells C3 to D8 and a box will appear below the lower right corner. This is the Quick Analysis tool.

3. On this you can hover over each icon to see how the data will appear. In this case, we select the Formatting option and Color to yield the following result in Figure 15–10

FIGURE 15–10

FIGURE 15–11

FIGURE 15–12

We can also insert a chart by selecting the Charts menu and the Cluster yielding the following Chart in Figure 15–12

FIGURE 15–13

MAP CHART

In this feature, you can create a map based upon regions such as states, countries, and zip codes.

1. In this example, copy the list of states with the corresponding random gas prices entered in cells B4 to C55.

2. Highlight the cells containing information including the heading. Click on the Insert menu, then within the group Charts, click on Maps, then Filled Map. A map chart will appear to the right with states highlighted based upon the relative weight of the gas price.

You can then change the colors and style of the chart to what you wish. Additionally, you can use this chart or the entire worksheet in a PowerPoint slide as part of a presentation.

FIGURE 15–14

FIGURE 15–15

FUNNEL CHART

In this example, we will use the same data used in the Map Chart to display a Funnel Chart that can also be used in presentations.

1. Copy the gas price information into the cells B4 to C55 in an empty worksheet.

2. Then highlight the same cells, go to the Insert menu item, and within the Charts group select the Funnel Chart icon. This will display a funnel chart by state and gas price.

From this you can perform a couple of different actions.

3. Label each bar line with the state to which it applies. Click on the Chart so that it is outlined.

4. Click on the Design menu item.

5. Then within the Chart Styles group select the second Chart from the left on the ribbon.

FIGURE 15–16

This will yield the following chart with the State labels.

FIGURE 15–17

You can then sort the data by gas price to show the chart as a funnel. Highlight cells B4 to C55 then select the Data menu item, and within the Sort & Filter group select Filter by gas price. This will yield:

FIGURE 15–18

DATA TYPES – STOCKS

In this next example, Excel can retrieve stock information based upon a stock name or symbol.

1. Either through an internet search or copying the stocks listed in the example Excel spreadsheet, paste the 30 stocks that are part of the Dow Jones Industrial composite list.

2. Highlight the cells containing the heading and the stocks – in this case cells B4 to C34.

3. Then on the menu ribbon, click the Data menu item then under Data Types click the Stocks icon. This will place an icon next to each stock or company that can be linked to internet information.

4. Then click on the icon of the first one – 3M Co – this will pop up a Card displaying real-time information about 3M stock and the company. You can scroll down to view all the information.

FIGURE 15–19

FIGURE 15–20

DATA TYPES – GEOGRAPHY

The next example is similar to the previous but instead of displaying information about a company, Excel can display information about a country, region, or state.

1. Select a list of countries from the internet or simply type countries into a list as in the following example.

2. Then highlight the entire list including the heading.

3. Then click on the Data menu item, then Geography in the Data Types group.

FIGURE 15–21

FIGURE 15–22

This will insert an icon next to each country as such.

FIGURE 15–23

4. Click on any icon to display information about the country. Figure 15–24 is the example of clicking on Albania. Scroll through the box to view various characteristics of the country.

FIGURE 15–24

NOTE

There are quite a few other data types that you can use and tie to words used in your Excel sheet. By creating data types as in the example above, you can display information related to words based on a data type category. See Figure 15–25.

FIGURE 15–25

VIEW WORKBOOK OBJECTS USING THE NAVIGATION PANE

The navigation pane makes it easy to view the different types of objects that exist in your workbook and allows you to jump directly to them. This is a new feature in Microsoft 365. Some of the objects that are listed in the navigation pane are icons, charts, tables, freestyle work, smart lookup, and data types.

1. Using the spreadsheet related to this chapter, off the top menu item “View,” click on Navigation Pane located in the Show group. See Figure 15–26. The navigation pane now appears on the right and lists the various objects contained within the workbook.

2. Click on the right arrows next to each object and you will see a list of those types of objects. For example, clicking on the arrow next to the “icons” will show you which icons are in the workbook.

3. Click on one of the Graphic objects and Excel will jump to the worksheet that contains that graphic. See Figure 15–27.

FIGURE 15–26

FIGURE 15–27

NOTE

In the search box at the top of the navigation pane, you can also type in a word describing the object type (such as icon, data type, etc.) or the actual name of the object (such as Graphic 7 or Ink 24).

REVIEW WORKBOOK STATISTICS

Reviewing the statistics of a workbook comes in handy when working with large workbooks. This is a new feature in Microsoft 365.

1. In any workbook, under the Review menu option on the top menu bar, click “Workbook Statistics.” See Figure 15–28.

2. Figure 15–29 shows the statistics tied to the current workbook.

FIGURE 15–28

FIGURE 15–29

NOTE

The “End of sheet” statistic tells you where the last used cell is on a worksheet. This is valuable since sometimes there are rows and columns that are not used, but are taking up space. You can then delete the unnecessary rows and columns, save the file, and the file size will be reduced.

SMOOTH SCROLLING WHEN CELLS CROSS OVER VIEWABLE PAGES

If you have worked with many cells that contain several lines, and you have wrapped the text, you may have noticed it was difficult when scrolling to stop on a particular cell. The new Excel version has fixed this. This is also a new feature in Microsoft 365.

1. Use the “smooth scrolling” worksheet in the current chapters spreadsheet version. See Figure 15–30.

2. Scroll up and down and you will notice it does not jump as new rows are displayed. You can now stop the scrolling at any point you wish.

FIGURE 15–30

UNHIDING MULTIPLE WORKSHEETS AT ONCE

Previous versions of Excel only allowed you to unhide one worksheet at a time. Now you can unhide multiple worksheets using the <Ctrl+Shift> key combination. This is valuable when you have a large workbook with many worksheets. This is a new feature in Microsoft 365.

1. In any workbook, hide multiple sheets by holding down the <Ctrl> key and left clicking (while keeping the <Ctrl> key pressed) the sheets you wish to hide.

2. Once you have selected which sheets you wish to hide, right-click on any one of them and select Hide. See Figure 15–31.

3. Now to unhide multiple worksheets, simply right-click on any unhidden sheet and select Unhide. You will then see the popup displaying a list of hidden worksheets.

4. Hold down the <shift> key and simultaneously click on those sheets you want to unhide. See Figure 15–32.

FIGURE 15–31

FIGURE 15–32

RESIZING THE CONDITIONAL FORMATTING WINDOW

Previous versions of Excel only had one window size for the conditional formatting window. If there was a long formula in one of the rules, you had to open the rule up to see it. Now you can expand the window to any size you wish, making it easier to view many of the rules at once AND view the full formulas contained within each one without having to open up the individual rules. This is another new feature in Microsoft 365.

1. In the workbook used for this chapter, go to the “conditional formatting” worksheet.

2. On the Home menu tab, click “Conditional Formatting” in the “Styles” menu group. See Figure 15–33.

3. Click and hold the bottom right corner.

4. You can then resize the window to the right to make it wider and/or drag the corner towards the bottom to make it larger. See Figure 15–34.

FIGURE 15–33

FIGURE 15–34

NOTE

The resizable feature has also been added to the “New Rule” and “Edit Rule” dialog boxes that appear when you click on them. These buttons appear near the top of the “conditional formatting” dialog box.

DUPLICATING A CONDITIONAL FORMATTING RULE

Another feature only available to Microsoft 365 subscribers is the ability to duplicate a rule. If you have ever had to create many rules with several of them being similar, you will appreciate this feature. Duplicating a rule and only having to change parts of it makes creating similar rules easier and quicker than if you would have to start a rule from scratch.

1. In the workbook used for this chapter, go to the “conditional formatting” worksheet.

2. On the Home menu tab, click “Conditional Formatting” in the “Styles” menu group. See Figure 15–35.

3. In the dialog box that pops up, highlight any rule. See Figure 15–36.

4. Click the button “Duplicate Rule.”

FIGURE 15–35

FIGURE 15–36

CHAPTER 16

DATA ANALYTICS USING EXCEL

Excel has many tools to analyze small or large amounts of data. We will provide simple examples using data analytics. Once you understand the use of the analytic tools, we will show you how to merge large amounts of data.

Let us explore a few examples. Keep in mind we are only touching the surface of how Excel can analyze small or large data sets. Hopefully, with the examples we exhibit, you will understand the (near) limitless methods in which Excel can store and report on large data sets.

Of course, there are other “power” tools online that can manage large databases, but Excel is a ubiquitous tool that most people use, and it offers a simple environment in which to manage large amounts of data. In this chapter, we will first setup the Analysis TookPak and then provide examples of how to analyze data sets.

ACTIVATE “ANALYSIS TOOLPAK”

The “Analysis ToolPak” comes with Excel. To activate, click on “File” on the top menu bar, then on the left navigation bar click “Options” yielding the popup in Figure 16–1.

FIGURE 16–1

Then on the left navigation bar, click “Add-ins” as in Figure 16–2. Locate “Analysis TookPak” (not the ‘Analysis ToolPak – VBA). If it is in the list of “Active…” add-ins, then there is no need to do anything.

FIGURE 16–2

If it is beneath the “Inactive” add-ins, then double click on the “Go” button down near the middle of the popup. This will yield the popup in Figure 16–3.

FIGURE 16–3

DISPLAY A HISTOGRAM TO VIEW THE FREQUENCY OF SALES

Let us determine where the concentration of Sales which can be tied back to salespeople, regions, or wherever else your data takes you. Use the data in Figure 16–4, to develop a histogram.

FIGURE 16–4

1. Copy the cells (or range) A1:C20 into a blank worksheet. Including a column C will add the groupings which you can modify at any point.

2. On the top menu, click “Data,” then at the far right, click “Data Analysis” within the “Analysis” group. This will bring up the window “Data Analysis” and then select the “Histogram” tool depicted in Figure 16–5.

FIGURE 16–5

3. In the above popup depicted in Figure 16–5, enter, or select the following:

Input Range: $A$1:$A$20

Bin Range: $C$2:$C$5 (representing the buckets)

Output Range: $F$1

4. Click <OK>.

NOTE

This will display the frequency of which Sales Amounts appear in the groupings listed in column C. You can modify the values in column C to discover the frequency of where the Sales Amounts fall. This can assist in determining which Sales Amounts are more popular or are less frequent. This helps a businessperson to focus on where help is needed.

DISPLAY MANY STATISTICS DESCRIBING A DATA SET

With one tool, let us view the mean, median, deviation, variance, range, minimum, maximum, sum and other statistics of a group of data. Using the “Descriptive Analysis” tool within the Analysis TookPak, we now have one tool that provides numerous statistics.

1. Using the same Sales Amounts in the previous example, copy the cells (or range) A1:A20 into a blank worksheet.

2. On the top menu, click “Data” then at the far right, click “Data Analysis” within the “Analysis” group. This will bring up the window “Data Analysis” and select the “Descriptive Analysis” tool depicted in Figure 16–6.

FIGURE 16–6

3. After clicking “OK” you will see the following statistics:

FIGURE 16–7

NOTE

You can view the 14 different statistics from the simple data we inputted. Using this tool for thousands or hundreds of thousands of rows can provide a simple summary of a large amount of date.

REVEAL HOW NUMBERS CORRELATE TO EACH OTHER

Using the “Correlation” option within the Analysis ToolPak can give you confidence or lack of confidence in a data set. In other words, how accurate is it to relate one set of data to another set of data?

1. Using the Sales Amounts in Figure 16–7 in the previous example, copy the cells (or range) A1:A20 into a blank worksheet.

2. On the top menu, click “Data” then at the far right, click “Data Analysis” within the “Analysis” group. This will bring up the window “Data Analysis” and select the “Descriptive Analysis” tool depicted in Figure 16–8.

FIGURE 16–8

3. After clicking “OK” you will see the following statistics:

FIGURE 16–9

NOTE

The result tells us that Sales 1 is perfectly correlated to the months – in other words the first month yields $1,000 etc. Column C shows us that it is perfectly inversely correlated – in other words it is the exact opposite. Column D shows values that are less than correlated. Perfect correlation is 1 or −1. As a correlation number approaches zero from either 1 or −1, it becomes less correlated. A correlation value of zero means that the data is not correlated at all.

SMOOTH A NATURAL PROGRESSION OF NUMBERS

Many data sets have highs and lows – meaning high and low values that skew the real trends. In this example we are going to use the “Exponential Smoothing” tool with the Analysis ToolPak to smooth out the trend. This is a more realistic progression of values.

1. Using Figure 16–10, copy cells A1:B27 into a blank worksheet.

FIGURE 16–10

2. On the top menu, click “Data” then at the far right, click “Data Analysis” within the “Analysis” group. This will bring up the window “Data Analysis” and select the “Exponential Smoothing” tool depicted in Figure 16–11.

FIGURE 16–11

3. After clicking “OK” you will see the following statistics:

FIGURE 16–12

NOTE

The result “smooths” out the trend over time – the function essentially removes the highs and lows and provides an even result as time goes on. The larger the “damping factor” the more highs and lows the formula will remove for its calculation of the future trend.

DETERMINE A MOVING AVERAGE FOR A DATA SET

Many times, we like to see if a current data value is breaking a trend. In this example we can compare live data sets with what a long-term average value is.

1. Using Figure 16–10, copy cells A1:B27 into a blank worksheet.

FIGURE 16–13

2. On the top menu, click “Data” then at the far right, click “Data Analysis” within the “Analysis” group. This will bring up the window “Data Analysis” and select the “Moving Average” tool depicted in Figure 16–14.

FIGURE 16–14

3. After clicking “OK” you will see the following statistics and chart:

FIGURE 16–15

NOTE

You will notice the “#N/A” – this depicts there is no answer to an average less than 12 periods which is what we selected. You can change it, of course. But in this example the moving average does not start until 11/1/2020. In the chart you can see that some values dip below the moving average, but the moving average continues to progress because it brings up the previous 12 periods. If the moving average began to decline, this may be a prediction of the overall amounts declining.

CREATE A LIST OF RANDOM NUMBERS

Many times, we like to evaluate values or create random values to test against any theories we may have or to be used in any formulas we wish to use. In this example, we will use the “Random Number Generation” to create any type of random number sequence we wish.

In this example, we will create 20 random numbers somewhere between 0 and 500.

1. In a blank worksheet, click in cell A1.

2. On the top menu, click “Data” then at the far right, click “Data Analysis” within the “Analysis” group. This will bring up the window “Data Analysis” and select the “Random Number Generator” tool depicted in Figure 16–16.

FIGURE 16–16

3. After clicking “OK” you will see the following statistics and chart:

FIGURE 16–17

RANK A LIST OF CLIENTS OBTAINED IN A MONTH

Let us see what the greatest number of clients is which we obtained during one month in our business. In this example, we have a sample of 19 periods. What were the highest amounts, and how did all the rest rank amongst the entire data set?

1. Copy the data in Figure 16–18, cells A1:A20.

FIGURE 16–18

2. On the top menu, click “Data” then at the far right, click “Data Analysis” within the “Analysis” group. This will bring up the window “Data Analysis” and select the “Rank and Percentile” tool depicted in Figure 16–19.

FIGURE 16–19

3. After clicking “OK” you will see the following statistics and chart:

FIGURE 16–20

DETERMINE AN ACCURATE HOUSE PRICE

In this example, we will look at values of 10 homes and determine how the attributes of each house determine a price. This can be used to determine an equitable price for a house that is not on the list, but one you may wish to compare with.

1. Copy the data in Figure 16–21, cells A1:D11.

FIGURE 16–21

2. On the top menu, click “Data” then at the far right, click “Data Analysis” within the “Analysis” group. This will bring up the window “Data Analysis” and select the “Regression” tool depicted in Figure 16–22.

FIGURE 16–22

3. After clicking “OK” you will see the following statistics and chart:

FIGURE 16–23

SELECT FOUR RANDOM CUSTOMERS TO RECEIVE A PRIZE

In this example, you can use any list of numbers, dollar amounts, temperature degrees, etc. in order to retrieve a sampling of the entire list. In the following example, we want to give prizes to four of our customers. We will select them randomly.

1. Copy the data in Figure 16–24, cells A1:A24.

FIGURE 16–24

2. On the top menu, click “Data” then at the far right, click “Data Analysis” within the “Analysis” group. This will bring up the window “Data Analysis” and select the “Sampling” tool depicted in Figure 16–25.

FIGURE 16–25

3. In this case, we simply selected four. You can choose any number you wish by modifying the field “Number of Samples.” After clicking “OK” you will see the following statistics and chart:

FIGURE 16–26

CHAPTER 17

SHORTCUT KEYS

Instead of clicking on menu options or right clicking on some item, a combination of keys can accomplish the same result more quickly. Some of these you may not remember, and some you may not use a lot. The shortcut keys depicted in this chapter are probably the most common. There are hundreds of shortcut keys, most of which are rarely used. In this chapter, we hope to show the most common shortcut keys.

In this chapter, we will use the same worksheet as in Figure 17–1. For all examples, start with clicking into cell A1.

FIGURE 17–1

GO TO CELLS OR HIGHLIGHT CELL RANGES

1. To get to the next cell, simply click “tab” – this will move you to the cell to the right. There is a setting within Excel options that will direct the <enter> button to move you “down” instead of “right.”

2. To get to the far-right cell with data, click “ctrl+>.” This will bring you to the last column that possesses data.

3. To get to the cell farthest down with data, click “ctrl+ DownArrow.” This will bring you to the last row with data.

4. To highlight all cells in one row, click in cell A1. The click “ctrl+shift+>.” This will highlight all cells in the same row from the cell in which you started to the last cell highlighted.

5. To get to the cell farthest down with data, click “ctrl+shift+DownArrow.” This will highlight all cells in the same column to the last cell containing data.

6. Next, let’s find the end. To get to the cell that contains the last row and column of data, when in cell A1, click “ctrl+end.”

7. To highlight all cells with all rows and columns, click “ctrl+shift+end.”

OTHER COMMON SHORTCUTS

Below is a list of shortcuts and what they accommodate. These are some of the more common shortcuts that will save you time in moving around and modifying items within Excel. We recommend you open up one of your Excel workbooks with at least a few sheets and run through each shortcut key to familiarize yourself with them. Then in future, concentrate on one or a few at a time while working in workbook. With practice, they will become second nature and you will be able to get around Excel much quicker than you have before.

There are two videos that come with this book that provide examples of how some of the following shortcut keys work.

Manage Excel and Workbooks

Key Combination

Close Excel

Ctrl+F4

Close a workbook

Ctrl+W

Switch between open workbooks

Ctrl+Tab

Move Around Within a Workbook and Its Worksheets

Move to the next sheet

Ctrl+PageDown

Move to the previous sheet

Ctrl+PageUp

Go the most bottom right used cell

Ctrl+End

Go the leftmost cell in the current row

Home

Move the beginning of a worksheet

Ctrl+Home

Move to the next cell

Tab

Move to the previous cell

Shift+Tab

Format Cell Contents

Insert a hard return within a cell (while editing a cell)

Alt+Enter

Bold and remove bold text

Ctrl+B

Italicize and remove italicized text

Ctrl+I

Apply and remove strikethrough text

Ctrl+5

Highlight Groups of Cells

Select all cells from the current cell to the bottom right (that contain data)

Ctrl+Shift+End

Select all cells from current cell to the right (that contain data)

Ctrl+Shift+Right arrow

Select all cells from current cell to the left (that contain data)

Ctrl+Shift+Left Arrow

Select all cells above the selected cell (that contain data)

Ctrl+Shift+Up Arrow

Select all cells below the selected cell (that contain data)

Ctrl+Shift+Down Arrow

Clipboard Actions

Cut content of a cell or range of cells

Ctrl+X

Copy content of a cell or range of cells

Ctrl+C

Paste content of a cell or range of cells

Ctrl+V

Other Shortcut Keys

Undo an action

Ctrl+Z

Redo an action

Ctrl+Y

Display find and replace

Ctrl+H

Search in a spreadsheet, or use find and replace

Ctrl+F

APPENDIX

EXCEL INTERFACE GUIDE

Spreadsheet software is used to manage and process large amounts of data. A spreadsheet is organized into a grid of rows (indicated by number) and columns (indicated by letter). The intersection of these rows and columns is called a cell; a cell is identified by letter and number, so A1 would be the first cell of the spreadsheet. A spreadsheet document is not delimited by printed pages or slides, as you have previously seen in other software packages. Instead, it is organized as individual spreadsheets or worksheets (identified by the tabs at the bottom of the interface in the common spreadsheet applications); the entire file is called a workbook. A worksheet (also called a “tab” or simply a “sheet”) can contain many printed pages’ worth of material. In fact, a worksheet can contain thousands of rows or columns that would be infeasible to print; the maximum size of a worksheet in Excel contains rows up to row 1,048,576 and columns up to column XFD (or 16,384 columns). The total number of cells on a worksheet is 17,179,869,184.

A row in spreadsheet software is the horizontal grouping of data that is divided by columns; rows are signified by numbers.

A column in spreadsheet software is the vertical grouping of data that is divided by rows; columns are signified by letters.

A cell in spreadsheet software is the intersection of a row and a column, containing a single piece of data, which can be text, a number, a formula, or an object; cells are signified by the letter of the column and the number of the row.

A range in spreadsheet software is the combination of one or more contiguous cells. For example, a range can represent an entire column, an entire row, three adjacent cells in a row or a small grid of 9 rows by 11 columns anywhere in a spreadsheet. A range can even be one cell. Ranges are another way to reference information in a spreadsheet when using formulas instead of by cell and/or row (i.e. C5:C22, E10, A:A)

A formula in spreadsheet software is a mathematical calculation that results in a data value; the value is displayed in the cell in which the formula is typed.

A function within a cell or range is a predefined formula that produces a value based upon variables, or arguments, that you can pass it. For example, I can pass a few cells to the SUM function and it will result in the addition of the values within the cells that I pass it.

Cells are not intended for large amounts of text; you should ideally include one piece of data or information per cell. Spreadsheets are best for organizing data and calculating results. If you want the results to accompany text, you should produce your results in a spreadsheet and export the relevant data to a word-processing document. There are an enormous number of applications for spreadsheets across disciplines such as accounting and mathematics. The practical applications of this technology go far beyond the scope of this text. Some general uses that you may find for spreadsheet software are formatting information in large tables, creating charts that help visualize data, and performing complex mathematical calculations.

The spreadsheet software application in Microsoft Office is called Excel. First, open the software and use the File menu to save your new open document as Appendix A. The native file type in Excel is Excel Workbook (.xlsx).

ANATOMY OF EXCEL

Excel uses the ribbon interface for organizing various tools. Beneath the ribbon interface is the Formula Bar, which is used for naming cells and defining calculations. The main pane of the document window looks very different from those of other Office applications; it displays the rows, columns, and cells of the document. The bottom of the interface contains tabs for you to select the worksheet that is active in the document pane. Depending on the version of Excel you are using, the ribbons and shortcuts available will be slightly different. Below are sections on different versions; you can jump to the section that is relevant to you.

MICROSOFT 365 VS 2021

Microsoft changed the name of Office 365 to Microsoft 365. Microsoft 365 is a subscription-based service while Excel 2021 is a one-time purchase to be used on a PC or a Mac. Excel 2021 is also referred to as a “Perpetual” version of Office and can also be considered a subset of Microsoft 365. Microsoft 365 includes most of the Office products such as Excel, Word, PowerPoint, and Outlook. With Microsoft 365, you receive the latest features, security updates and bug fixes as they are released. You can always get the latest version by going into File then Account and clicking “Update Options.” With Excel 2021, you need to wait until the next release to receive these updates and upgrades. For example, there are a few functions that Microsoft 365 offers that are not part of Excel 2021. There are other functions and features demonstrated throughout this book that may only be available in Microsoft 365 – we make note of these in the various chapters.

When opening a Microsoft 365 version, you will see “Microsoft 365” and not a number or a year in the version in the “About” box that pops up with first starting an Office application.

MICROSOFT EXCEL 2021

The interface for Excel 2021 has the same ribbon structure and general layout as the other Office applications. You can see an example of the interface for Excel 2021 in Figure A-1. The Formula Bar, located beneath the ribbon interface, identifies the current cell that you have selected and displays the contents of the cell or the formula used to determine the cell contents. When you begin using functions, the Formula Bar will become much more relevant. It allows you to perform a formula lookup and will help identify any possible errors in your formula construction.

Excel 2021 and Microsoft 365 contain the “Tell me what you want to do” box near the top middle. In this box, you can type in a phrase or sentence you are trying to accomplish, and it will return possible answers it believes can assist you. It also taps into the existing “Smart Lookup” feature that can search the web for other possible answers and solutions.

FIGURE A-1

The document is divided into cells. You can use the arrow keys to navigate from one cell to the next, or you can click on a cell to activate it. The current cell is called the active cell, and the row and column in which it resides will also be highlighted for you to identify them quickly. Hold the Shift key to select multiple cells. Each cell acts like a text box in which you can type information.

The bottom of the interface has a set of tabs, each of which identifies an individual spreadsheet within the overall workbook (the file itself). You can navigate to these spreadsheets by clicking on the tabs or by using the directional arrows to the left of the tabs. The bottom of the interface also contains the view options, which allow you to see the page breaks in your document in a Page Layout view, a Page Break Preview, or the Normal view; the last of these tends to be the most helpful for document creation. When you have numeric values selected, the bottom of the interface will also display an automatic calculation of the average of the values, the sum of the values, and the number of values you have selected (omitting white space). This is a nice feature for quickly assessing statistics on a list.

The available ribbons and functions are quite different from the interface for Word. The Home ribbon contains the Number panel for formatting numeric values (either as direct text input or as the result of formula calculations), as well as commands for style formatting and for adding, deleting, or formatting cells. Of particular note are the Fill icon, which is used to replicate values or predict entries in a series, and the Sort & Filter icon, both in the Editing panel. The Insert ribbon, shown in Figure A-2, contains several entries of note, particularly the chart creation functionality, single-cell charts called Sparklines, and the icon to create a PivotTable, which is one of the more advanced features of Excel.

FIGURE A-2

The Page Layout ribbon, shown in Figure A-3, is used to manage the spreadsheet by dividing it into printable areas. You can add a background, insert manual page breaks, and set the printable region size for your spreadsheet. If printing is a concern, it may be helpful to preview the print regions to keep your document confined within the desired page delineations.

FIGURE A-3

The Formulas ribbon contains categories of formulas from which you can select to insert into your document. This ribbon also contains the functionality to trace dependencies among cells in your spreadsheet and provides manual links to set calculation options for your spreadsheet; by default, all calculations are updated immediately when a value on which they depend is changed. The Formulas ribbon is shown in Figure A-4.

FIGURE A-4

The Data ribbon, shown in Figure A-5, contains several useful commands, including the Remove Duplicates command to make sure no identical values are repeated in your list and the Text to Columns command to convert continuous text into multiple columns based on a delimiter character. This ribbon also contains commands to manage external sources, perform a What-If Analysis (for goal seeking), validate data, and perform advanced filtering for lists.

FIGURE A-5

The Review ribbon gives you the ability to add comments to your spreadsheet. Unlike Word, Excel places comments in a triangle icon in the upper-right corner of the cell to which they are attached. The Review ribbon also gives you options for protecting your document from changes or sharing your document on a network location for others to edit. You can also select the Start Inking icon to use your mouse as a pen to mark up your document. The Review ribbon is shown in Figure A-6.

FIGURE A-6

The View ribbon, shown in Figure A-7, allows you to change the view of the document as usual, but it also allows you to manage your workspace. The views in Excel are primarily the Normal view and views to preview page layouts for printing, such as Page Break Preview. The Page Layout view is not recommended for constructing or working with your document. You can show or hide various document elements from this ribbon as well, such as the gridlines and the Formula Bar. The Freeze Panes functionality allows you to preserve your headings as you scroll through your document. The Split function lets you set up multiple viewing panes of your document, so you can view disjoined elements side by side. You can also use the Save Workspace icon to store the configuration of multiple document windows. The View Side by Side icon allows you to look at two workbooks at the same time. You can set synchronous scrolling for these, so they move in the same direction at the same time.

FIGURE A-7

MICROSOFT EXCEL 2021 FOR MACINTOSH

The Macintosh interface for Excel 2021, shown in Figure A-8, is very similar to the other Office applications for Macintosh computers and is similar to the Personal Computer (PC) version. The interface contains the standard menu and ribbons where most of your functionality is located. In addition, you have a Formula Bar that is used to construct calculations in the spreadsheet and edit information in the cells of the document. The main document is divided into cells, which can be navigated with the arrow keys on the keyboard. The columns are labeled with letters across the top, and the rows are labeled with numbers down the left side. The tabs at the bottom are the individual spreadsheets within the workbook (the overall document).

FIGURE A-8

Clicking with the mouse on a cell in the document makes that cell the active cell; this action outlines the cell in a thick border and highlights the row and column labels for quick reference. The cell reference will also appear in the Name box on the left side of the Formula Bar. Options in the Quick Access toolbar include a toggle that allows you to show or hide the Formula Bar and links to common functions like SUM. The bottom of the interface contains the view selection, where you can alternate between the Normal view and a preview of the page breaks in your document for printing.

The Home ribbon contains the standard text formatting options, along with a panel for formatting numeric values. This is necessary for effectively managing and displaying data in the spreadsheets. The Home ribbon also contains icons for inserting and deleting rows and columns and for using special preset formatting options.

The Page Layout ribbon, shown in Figure A-9, contains view settings and print options and is primarily used for establishing print regions and previewing the print area. This ribbon can also be used to set up a workspace where you can open multiple workbook documents on the screen for use at the same time.

FIGURE A-9

The Draw ribbon is similar to what is found in Word; you can use this ribbon to “write” in free-form anywhere you wish using varying colors This ribbon is shown in Figure A-10.

FIGURE A-10

The Formulas ribbon is where you can access the available formula library in Excel. This ribbon contains an icon for quick access to formulas for summations and averaging, as well as the Formula Builder icon for creating more advanced calculations. You can also control the recalculation options for your formulas from this ribbon (by default, the recalculation is immediate whenever a value is changed) and trace the cells used in your calculations. The Formulas ribbon is shown in Figure A-11.

FIGURE A-11

The Data ribbon, shown in Figure A-12, contains the functionality for managing information in your spreadsheet. You can sort and filter data from this ribbon, manage external data sources, remove duplicate values in a list, and convert the existing text into separate columns. Data validation and grouping is also performed from this ribbon.

FIGURE A-12

The Review ribbon, shown in Figure A-13, is primarily used for document collaboration and markup. You can add or address comments from this ribbon and share your document or set document protection so it cannot be altered.

FIGURE A-13

MICROSOFT EXCEL WEB APP

From a OneDrive account or Microsoft 365, you can also create a new Excel workbook or edit an existing workbook in your online storage using the Microsoft Excel Web App. You can see the interface of the Excel Web App in Figure A-14. The Excel Web App has a limited subset of the functionality of the Excel program, along with the ability to open the document in the full version installed on the computer and the ability to share the document via the Share option found in line with the other ribbons. The basic organization of the interface is very similar to that in the 2013 version of Excel. Note the inclusion of the Share button at the top of the interface, allowing you to easily collaborate on the same document. There is no Save icon in the Quick Access toolbar, because changes are saved as soon as any action in the document is completed.

FIGURE A-14

The Home ribbon, also shown in Figure A-14, contains formatting commands for text and numerical values. The number formatting options are collapsed in this version into a dropdown list under Number Format; this version also can add or reduce significant digits. Most of the commands on this ribbon should be familiar to you from the use of other Office software.

The Insert ribbon, shown in Figure A-15, provides options for adding charts and formulas (also called functions) to your document. You can also add hyperlinks and tables from this ribbon. The Data ribbon in Figure A-16 contains the Calculate Workbook command to refresh the calculations in the workbook, as well as the options for sorting by column. The View ribbon, shown in Figure A-17, contains only the option to hide the interface in Reading View or show the interface in the standard Editing View. Most of the functions you will need in Excel are limited to the standalone versions installed on the computer, though the Web version can be used for quick edits and computations when you are away from your home or work computer.

FIGURE A-15

FIGURE A-16

FIGURE A-17

INDEX

A

Accounting system, 119

Add Pen icon, 467

ADDRESS functions

determine last cell used, 336–337

largest number position, 255–256

smallest number position, 257

sum sales up to today, 257–258

Analysis ToolPak, 118, 122, 123, 125, 128, 186, 491–493

AND function

combine with IF function, 44–45

compare to two columns, 37–38

to detect empty rows in range, 332–333

for sales in time period, 38–39

& operator, 74, see also Combine text (use & operator)

ARABIC function, convert Roman to Arabic numerals, 209

Arabic to Roman numerals, ROMAN function convert, 208

Array, 141

ASCII character, 73, 88, 89

Asterisk matches, 65

A1-style reference, 272

Attendance list calculation, use COUNTIF function, 176–177

Average daily production calculation, 16

Average fuel consumption calculation, 411–413

AVERAGE functions

average of x largest numbers, 356–357

calculate average output, 145

taking zero values, 342

Average speed calculation, 34

B

Barrels, liters convertion to, 22

BASE function, convert decimal to binary numbers, 210

“Battleship” INDIRECT function to play, 272–273

BMI, see Body mass index

Body mass index (BMI), 7

Broca, P. P., 7

Broca’s index, 7

C

Calculation, using excel formula age of person in days, 2–3

average daily production, 16

average speed, 34

divide and double every three hours, 33

examples

account rebates and price reductions, 417–418

average fuel consumption, 411–413

combine text, dates, and timestamps, 422–423

components category, 442–443

cost and sales values per day, 445–448

cost of investment, 440–441

determine last day of month, 424–425

economic value of product, 415–416

eliminate specific characters, 421–422

extract every fourth value, 448–449

final price of products, 417–418

highest values in list, 438–440

inventory value, 435–436

net and gross prices, 414–415

number of available workdays, 425–427

number of values in specific range, 429–431

person’s age, 427–429

round value to nearest 5 cents, 434–435

search for data, 418–419

separate cities from zip codes, 420–421

specific value in complex list, 443–445

top salesperson for month, 436–438

weekly sales for each department, 431–433

ideal and recommended weights, 7–8

net income, 31

number

of employees for project, 29–30

of hours between two dates, 26–27

of pieces in box, 28–29

price per pound, 27–28

price reduction, 3–4

production per hour, 1–2

sales taxes, 12–13

total with percentage, 24

Calendar, use Fill command, 8–9

Case-sensitive search, use EXACT function, 316–317

CEILING function, round up prices to nearest $100, 187–188

CELL function to detect unlocked cells, 323–324

Cell reference, 135, 136, 145, 169

search for, 256

Celsius to Fahrenheit convertion, 23–24

Characters

ASCII, 73

beginning with same, use DCOUNTA function, 246–247

non-printable, 84

numeric code of, 88

numeric Unicode value of, 90–91

CHAR functions, 73

to check fonts, 86–87

to determine special characters, 87–88

CHOOSE function, to lookup values, 283

CLEAN function, remove all non-printable characters, 84

CODE function, numeric code of character, 88–89

COLUMN functions

count certain characters in range, 350–351

last column used in range, 339–340

last number in row, 338–339

MOD functions and, 302–303

Combine

columns with date parts use DATE function, 109–110

text, dates, and timestamps calculation, 422–423

Combine text (use & operator), 13

and date, 14

use FIND function, 77–78

and format text use TEXT function, 93–94

and numbers, 13

and time, 14

use CONCATENATE function, 94–96, 97

use CONCAT function, 96–97

use TEXTJOIN function, 97–99

Compare

AND function to two columns, 37–38

IF function

to columns and return, 42–43

dates with the actual date, 58

INT, TRUNC, and ROUND functions, 219–220

SWITCH function to two cells, 52

Completion percentage, 19

CONCATENATE function, to combine text, 94–96, 97

CONCAT function, to combine text, 96–97

Conditional formatting with formulas, 17–18

array formula and combine with, 339

to border summed rows, 330–331

CELL function to detect unlocked cells, 323–324

to control font styles in specific range, 312–313

COUNTIF function

check whether number exists in range, 310–311

to mark duplicate entries automatically, 308–310

to shade matching numbers, 324–325

COUNTIFS function, value based on multiple filters, 334

to create Gantt chart, 320–321

DATEDIF function, 327–328

EXACT function, to perform case-sensitive search, 316–317

features, 444

AND function, detect empty rows in range, 332–333

to indicate unavailable products, 297–298

ISERROR function, to mark errors, 326–327

LARGE function, to find three largest values, 304–305

LEFT function in product search, 331–332

MAX function, to find largest value, 303–304

MIN function

and IF function, 340–341

search for lowest nonzero number, 307–308

for worst month, 306–307

MOD functions

and COLUMN functions, 302–303

and ROW functions, 300–301

WEEKNUM function and, 299–300

MONTH functions, birthdays in current month, 328–329

OR function, 322–323

shade project steps with missed deadlines, 319–320

SUBSTITUTE function, to search for text, 317–318

TODAY functions

birthdays in current month, 328–329

to shade specific column, 298–299

to show completed sales, 295–297

user-defined function in, 313–314

with valid numeric values, 315–316

WEEKDAY function, detect and shade weekends, 293–295

Control font styles, conditional formatting to, 312–313

Convertion

Arabic to Roman numerals, use ROMAN function, 208

binary to decimal numbers, use DECIMAL function, 211

Celsius to Fahrenheit, 23–24

currency, 4–5

decimal to binary numbers, use BASE function, 210

dollars to euros, 4–5

Fahrenheit to Celsius, 22–23

feet per minute to meters per second, 21

hours to minutes, 5–6

initial characters lowercase to uppercase, use PROPER function, 80–81

liters to barrels, gallons, quarts, and pints, 22

miles to kilometers per hour, 20

negative values to positive, 11–12

numbers to currency in text format, 91–92

DOLLAR function, 91–92

numbers to text, use FIXED function, 81–82

Roman to Arabic numerals, use ARABIC function, 209

text lowercase to uppercase, use UPPER function, 78–79

“text-numbers” to real numbers, TRIM function, 83–84

text uppercase to lowercase, use LOWER function, 79–80

CORREL function, data correlation determination, 165–166

Correlation option, 496–497

COUNTA functions, 152, 274–276

count cells data, 148

count cells text, 149

determine last number in row, 276

last filled row, 151

in non-filtered list, 199

COUNTBLANK function, 274–275

count empty cells, 150

COUNT functions, 152

count cells contain numeric data, 147

largest gain/loss of shares, 353–354

in non-filtered list, 199

COUNTIF functions, 334, 345, 357

calculate an attendance list, 176–177

check whether number exists in range, 310–311

count unique records in list, 355

to mark duplicate entries automatically, 308–310

phases cost more than $1,000, 217–218

count, 175–176

prevent duplicate input through validation, 369–370

to shade matching numbers, 324–325

whether all numbers are unique, 359–360

COUNTIFS function, value based on multiple filters, 334

Count unique records, 355

Currency convertion, 4–5

Current time, NOW function to, 107–108

Custom-defined formula, 371

Custom function

delete all external links in worksheet, 384

formulas

into additional worksheet, 385–386

document and display, 382–383

to shade all cells with, 379–380

into values change, 381

Customized formatting

to create time format, 131–132

display weekdays using, 103–104

D

Daily production plan, 25

Database functions

DAVERAGE function, 254

DCOUNTA function, 246–247

DCOUNT function

to count cells range between x and y, 245–246

to count special cells, 243–245

DGET function, search for product by number, 247–248

DMAX function, most expensive product, 248–249

DMIN function

least expensive product, 250

oldest person on team, 251

DSUM function

sum all prices in category, 253

to sum sales for period, 252

Data correlation determination, use CORREL function, 165–166

Data analytics using Excel

accurate price for a house, 502–503

moving average for data set, 498–499

natural progression of numbers, 497–498

numbers correlate to each other, 494–497

list of random numbers generation, 500

prizes to our customers randomly, 504–505

statistics describing a data set, 494–495

Data types

Geography in, 480–482

Stocks icon, 478–479

Data validation, 60, 369, 370

user-defined functions cell contains, 393

Date and time functions

calculation

ages of employees, DATEDIF function use, 128

with 360-day year, DAYS360 function, 119–120

employees ages, YEARFRAC function use, 126–127

with 100-minute hours, HOUR function use, 132–133

months, EDATE function to, 123

weeks of Advent, WEEKDAY function to, 129

workdays, WORKDAY function use, 124

DATEVALUE function to recalculate, 112–113

display weekdays using customized formatting, 103

EOMONTH function, last day of month, 118–119

extract

DAY function, 115–116

LEFT and MID functions, 110–111

MONTH function, 114–115

RIGHT functions, 110–111

TEXT function, 111–112

YEAR function, 113–114

NOW function

calculate with time, 108–109

to show current time, 107–108

sort birthdays by month, 116–117

TIMEVALUE function

convert text to time, 130–131

TODAY function

check for future dates, 105

TEXT function calculate with, 106

WEEKDAY function

calculate with different hourly pay rates, 121

to determine weekend, 104–105

WEEKNUM function determine week number, 122

YEARFRAC function, employees ages, 126–127

DATEDIF function, 327–328

to ages of employees, 128–129

DATE function

to add months to date, 117–118

combine columns with date parts, 109–110

DATEVALUE function

count today’s sales of a specific product, 348

recalculate dates formatted as text, 112–113

DAVERAGE function, average price in category, 254

DAY function

to extract date parts, 115–116

sort birthdays by, 116–117

DAYS360 function, calculate with 360-day year, 119–120

DCOUNTA function, 442

beginning with same character, 246–247

DCOUNT function

to count cells range between x and y, 245–246

to count special cells, 243–245

DDB function, using double-declining balance method, 234–235

DECIMAL function, convert binary to decimal numbers, 211

Delete spaces, use TRIM function, 82–83

Descriptive Analysis tool, 494–495

DGET function, search for product by number, 247–248

Distribute sales, 30–31

DMAX function, most expensive product, 248–249

DMIN function

least expensive product, 250

oldest person on team, 251

DOLLAR function, convert numbers to currency in text format, 91–92

Dollars to euros convertion, 4–5

DSUM function

sum all prices in category, 253

sum sales for period, 252

Duplicate numbers in list, TRANSPOSE and OR functions, 357–358

E

Economic value of product calculation, 415–416

EDATE function, to calculate months, 123

Eliminate specific characters calculation, 421–422

EOMONTH function, last day of month, 118–119

European method, 120

Euros convertion, dollars to, 4–5

EVEN function, nearest even value, 204

EXACT function

to allow only uppercase characters, 370–371

to compare two columns, 69–70

to perform a case-sensitive search, 316–317

Excel

data analytics

accurate price for a house, 502–503

moving average for data set, 498–499

natural progression of numbers, 497–498

numbers correlate to each other, 494–497

list of random numbers generation, 500

prizes to our customers randomly, 504–505

statistics describing a data set, 494–495

histogram to view the frequency of sales, 493–494

shortcuts, see Shortcut keys

Excel formulas

calculation using

age of person in days, 2–3

average speed, 34

divide and double every three hours, 33

ideal and recommended weights, 7–8

monitor daily production, 25

net income, 31

number of characters in string, 34–36

number of employees for project, 29–30

number of hours between two dates, 26–27

number of pieces in box, 28–29

percentage of completion, 19

price per pound, 27–28

price reduction, 3–4

production per hour, 1–2

sales taxes, 12

total with percentage, 24

combine (use & operator)

text and date, 14

text and numbers, 13

text and time, 14–15

conversion using

Celsius to Fahrenheit, 23–24

currency, 4–5

dollars to euros, 4–5

Fahrenheit to Celsius, 22–23

feet per minute to meters per second, 21

hours to minutes, 5–6

liters to barrels, gallons, quarts, and pints, 22

miles to kilometers per hour, 20

negative values to positive, 11–12

distribute sales, 30–31

evaluate profitability, 17–18

fuel consumption data, 6–7

gain/loss of stock, 17

generation using

own to-do list, 9–10

special ranking list, 15–16

percentage of price reduction, 32

quick calendar creation with, 8–9

standard row numbering in, 10

Exponential forecasting tool, 161

Exponential method, 161

Exponential Smoothing tool, 497–498

F

Fahrenheit to Celsius convertion, 22–23

Features

Add Pen icon, 467

data types, see Data types draw freestyle, 467–468

Flash Fill, 471–472

Funnel Chart, 477–478

insert icons, 465–466

Map Chart, 475–476

Quick Analysis Tool, 473–475

Share Files, 470–471

Smart Lookup, 469

Feet per minute to meters per second convertion, 21

Fill command, 8

Filtered list, use SUBTOTAL function

count rows in, 152

sum, 146

Financial functions

DDB function, 234–235

FV function, calculate total savings account balance, 236–237

PMT function, determine payment of loan, 235–236

PV function

to compare investments, 233

to decide an amount to invest, 231–232

RATE function, calculate interest rate, 238–239

SLN function, 230–231

SYD function, 229–230

FIND function, 60

combine, text and date, 77–78

FIXED function, round and convert numbers to text, 81–82

Flash Fill, 471–472

FLOOR function, to round down prices to nearest $100, 189

Fonts, use CHAR function, 86–87

FORECAST.ETS.CONFINT function, confidence in future values use, 162–163

FORECAST.ETS.SEASONALITY function, future values patterns use, 164–165

Forecasting model, 165

FORECAST.LINEAR function, future values use, 159–160

Formulas, in excel, see Excel formulas

FREQUENCY function, number of products sold, 362

Fuel consumption data, 6–7

Function(s)

AND, see AND function

database, see Database functions

financial, see Financial functions

FIND, 60

IF, see IF functions

IFERROR, 60–61

IFS, see IFS function

INT, see INT functions

LEN, 35

logical, see Logical functions

lookup and reference, see Lookup and reference functions

mathematical, see Mathematical functions

OR, see OR functions

statistical, see Statistical functions

SUBSTITUTE, 34–35

SWITCH, see SWITCH function

TEXT, see TEXT functions

TODAY(), 58

TYPE, 54

user-defined, see User-defined functions

XOR, 41

Future dates, TODAY function check for, 105

Future values

confidence determination, use FORECAST.ETS.CONFINT function, 162–163

patterns, use FORECAST.ETS.SEASONALITY function, 164–165

use FORECAST.ETS function, 161–162

use FORECAST.LINEAR function, 159–160

FV function, calculate total savings account balance, 236–237

G

Gain/loss of stock, 17

Gallons, liters convertion to, 22

Gantt chart in Excel, 320–321

GCD function, determine greatest common divisor, 214

Generate randomized values

use RANDBETWEEN function, 201–202

use RAND function, 200–201

Geography, in data types, 480–482

Goal Seek, as powerful analysis tool, 377–379

Greatest common divisor (GCD), 214

H

Histogram tool, view the frequency of sales, 493–494

HLOOKUP function

determine sales

and costs for team, 265–266

for particular day, 266–267

generate list for specific month, 267–268

HOUR function, calculate with 100-minute hours, 132–133

Hourly pay rates, WEEKDAY function use, 121

Hours to minutes convertion, 5–6

100-minute hours

convert normal time to, 133

HOUR function to calculate with, 132–133

HYPERLINK function

jump directly to cell inside current worksheet, 280–281

to link to Internet, 282

I

Ideal and recommended weight calculation, 7–8

IFERROR function, 60–61

IF functions

calculation

commissions for individual sales, 48

daily working hours, 59–60

with different tax rates, 47

to check

cells in worksheets and workbooks, 46

for larger, equivalent, or smaller values, 43–44

combine with AND function, 44–45

compare

columns and return, 42–43

dates with actual date, 58

two cells, 51

create own timesheet, 59–60

to determine quarter of year, 45–46

INT function with, 53

last column used in range, 339–340

lowest nonzero value in range, 340–341

to sum last row in dynamic list, 350

sum values with several criteria, 343

taking zero values, 342

worksheet using, 105

IFS function

commissions for individual sales, 49

to compare two cells, 50

multiple condition methods using, 55

Increment row numbers by 10, 11

INDEX functions, see also VLOOKUP function

determine and locate best salesperson, 143

determine last number

in column, 274–275

in row, 276

find last number

in column, 337–338

in row, 338–339

matches two criteria, 344

search for data in list, 271–272

INDIRECT functions, 257–258

to copy cell values of different worksheets, 273–274

largest gain/loss of shares, 353–354

to play “Battleship,” 272–273

Insert icons, 465–466

Interest, POWER function to calculate, 194

Interest rate calculation, use RATE function, 238–239

INT functions

compare, ROUND and TRUNC function, 219–220

with IF function, 53

Invalid to valid numbers convertion, 64–65

Invalid values, TYPE function for, 54

Inventory value calculation, 435–436

use SUMPRODUCT function, 177–178

ISERROR function to mark errors, 326–327

ISEVEN/ISODD functions, number even/odd, 205

ISNUMBER functions, last number in row, 338–339

ISODD and COLUMN functions, determine odd columns, 207

ISODD and ROW functions, determine odd rows, 206

K

Kilometers per hour convertion, miles to, 20

L

LARGE functions

average of x largest numbers, 356–357

determine and locate best salesperson, 143

find highest value, 142

to find three largest values, 304–305

LCM function, determine least common multiple, 215

LEFT functions

convert

invalid numbers to valid numbers, 64–65

to extract date parts, 110–111

in product search, 331–332

to separate text string of numbers, 63–64

LEN functions, 35, 64

count all digits in range, 353

count occurrences of specific word in range, 351–352

Linear forecasting model, 161

Liters convertion

to barrels, 22

to gallons, 22

to pints, 22

to quarts, 22

Logical functions

AND function

combine with IF function, 44–45

compare to two columns, 37–38

for sales in time period, 38–39

IFERROR function, 60–61

IF function, see IF functions

IFS function

commissions for individual sales, 49

to compare two cells, 51

INT function with IF function, 53

nested IF functions, multiple condition methods using, 55

OR function

to check cells for numbers, 40–41

to check cells for text, 39–40

SWITCH function

to compare two cells, 52

multiple conditions method using, 57

TYPE function

for invalid values, 54

XOR function

to check for mutually exclusive conditions, 41–42

Lookup and reference functions

ADDRESS function

largest number position, 255–256

smallest number position, 257

sum sales up to today, 257–258

CHOOSE function to lookup values, 283

COUNTA function, determine last number in row, 276

HLOOKUP function

determine sales and costs for team, 265–266

determine sales for particular day, 266–267

generate list for specific month, 267–268

HYPERLINK function

jump directly to cell inside current worksheet, 280–281

to link to Internet, 282

INDEX function

determine last number in column, 274–275

determine last number in row, 276

search for data in list, 271–272

INDIRECT function

to copy cell values of different worksheets, 273–274

to play “Battleship,” 272–273

LOOKUP function

directory of store, 268–269

indicator for current temperature, 270–271

MATCH function

largest number position, 255–256

smallest number position, 257

sum sales up to today, 257–258

MAX function, largest number position, 255–256

MIN function, smallest number position, 257

OFFSET function

to consolidate sales for day, 278

to filter every other column, 279

to filter every other row, 279–280

sum sales for specified period, 276–277

TODAY function, sum sales up to today, 257–258

VLOOKUP function

compare offers from different suppliers, 264

look up and extract data from list, 260–262

LOOKUP function

directory of store, 268–269

indicator for current temperature, 270–271

LOWER function, convert text uppercase to lowercase, 79–80

M

Map Chart, 475–476

MATCH functions

determine and locate best salesperson, 143

largest number position, 255–256

matches two criteria, 344

numeric values of text, 358–359

smallest number position, 257

sum sales up to today, 257–258

Mathematical functions

ARABIC function, convert Roman to Arabic numerals, 209

BASE function, convert decimal to binary numbers, 210

CEILING function, round up prices to nearest $100, 187–188

compare INT, TRUNC, and ROUND functions, 219–220

COUNTIF function

to calculate an attendance list, 176–177

count phases cost more than $1,000, 175–176

phases cost more than $1,000, 217–218

DECIMAL function, convert binary to decimal numbers, 211

EVEN function, nearest even value, 204

FLOOR function, round down prices to nearest $100, 189

GCD function, 214

generate random values

RANDBETWEEN function, 201–202

RAND function, 200–201

ISEVEN/ISODD functions, 205

ISODD

and COLUMN functions, 207

and ROW functions, 206

LCM function, 215

MOD function

for divisors larger than number, 196–197

to extract remainder of division, 195–196

MROUND function

to round prices to 5 or 25 cents, 185–186

to round values to nearest multiple of 10 or 50, 186–187

ODD functions

nearest odd value, 204

POWER function

to calculate interest, 194

to calculate square and cube roots, 193–194

PRODUCT function

to multiply conditional values, 191

to multiply values, 190

QUOTIENT function, 192

ROMAN function

to convert Arabic to Roman numerals, 208

ROUNDDOWN function

to round numbers down, 181–182

ROUND function

to round numbers, 180–181

to round time values to whole hours, 184–185

to round time values to whole minutes, 183–184

ROUNDUP function to round numbers up, 182–183

ROW function to mark every other row, 197–198

SIGN function, check for sign of number, 212

SUBTOTAL function

to count all visible rows in filtered list, 199–200

to perform several operations, 198–199

SUM function

to sum range, 169–170

to sum several ranges, 170–171

SUMIF function

to determine sales of team, 171–172

to sum costs higher than $1,000, 173

to sum costs up to certain date, 174

SUMIFS function, sales of team and gender, 216–217

SUMPRODUCT function

to calculate the value of the inventory, 177–178

to multiply and sum at same time, 179–180

to sum sales of team, 178–179

SUMSQ function, determine square sum, 213

MAX functions

determine last cell used, 336–337

to find largest value, 303–304

largest gain/loss of shares, 353–354

largest number position, 255–256

largest value in range, 135–136

last column used in range, 339–340

last number in row, 338–339

to sum last row in dynamic list, 350

whether all numbers are unique, 359–360

MAXIFS function, highest monthly sales, 138–139

MEDIAN function

calculate

average sales, 154

median sales, 154–155

MID functions

count certain characters in range, 350–351

to extract date parts, 110–111

numeric values of text, 358–359

separate last name from first name, 67

to sum digits of number, 68

Miles to kilometers per hour convertion, 20

MIN functions

in combination with VLOOKUP function, 264

lowest nonzero value in range, 340–341

lowest sales for month, 136–137

search for lowest nonzero number, 307–308

smallest number position, 257

smallest value in column, 140

for worst month, 306–307

MINIFS function, lowest monthly sales, 137–138

Minutes convertion, hours to, 5–6

MOD functions

and COLUMN functions, 302–303

for divisors larger than number, 196–197

to extract remainder of division, 195–196

and ROW functions, 300–301

WEEKNUM function and, 299–300

Monitor daily production calculation, 25

Monitoring process, 377

MONTH functions

birthdays in current month, 328–329

to extract month part of date, 114–115

sort birthdays by, 116–117

Months

clients obtained in a month, rank list, 501–502

EDATE function to calculate, 123

last day of, EOMONTH function use, 118–119

MROUND function, 434

to round prices to 5 or 25 cents, 185–186

to round values to nearest multiple of 10 or 50, 186–187

Multiple condition methods using IFS function, 56

using nested IF functions, 55

using SWITCH function, 57

Multiply conditional values, use PRODUCT function to, 191

Multiply values, use PRODUCT function to, 190

N

Negative to positive values convertion, 11–12

Nested IF functions, multiple condition methods using, 55

Net and gross prices calculation, 414–415

Net income, 31

NETWORKDAYS function, 425–427

number of workdays, 125–126

Non-printable characters, 84

NOW function

calculate with time, 108–109

to show current time, 107–108

Numbering system, 10

Numbers

of characters, 63

of characters in string, 34–36

convert

invalid to valid, 64–65

to words, 72–73

convert to currency in text format, 91–92

of employees for project, 29–30

of hours between two dates, 26–27

of pieces in box, 28–29

separate text string of, 63–64

Unicode characters and, 89–90

of workdays, NETWORKDAYS function use, 125–126

Numeric Unicode value, of character, 90–91

O

ODD functions, nearest odd value, 204

OFFSET functions

combination with SUMIF, 278

to consolidate sales for day, 278

to filter every other column, 279

to filter every other row, 279–280

to sum last row in dynamic list, 350

sum sales for specified period, 276–277

Operation, multiply and sum in, 180

OR functions

to check cells for numbers, 40–41

to check cells for text, 39–40

differences higher than 5% and lower than ?5%, 322–323

duplicate numbers in list, 357–358

Own to-do list generation, 9–10

P

Percentage

of completion, 19

of price reduction, 32

tax, 31

Person age in days calculation, 2–3

Person’s exact age calculation, 427–429

PMT function, determine payment of loan, 235–236

Positive values convertion, negative to, 11–12

Powerful analysis tool, Goal Seek as, 377–379

POWER function

to calculate interest, 194

to calculate square and cube roots, 193–194

Prevent duplicate input, use COUNTIF function, 369–370

Price per pound calculation, 27–28

Price reduction

calculation, 3–4

percentage, 32

PRODUCT function

to multiply conditional values, 191

to multiply values, 190

Production per hour calculation, 1–2

Profitability, evaluate of, 17–18

PROPER function, convert initial characters lowercase to uppercase, 80–81

PV function

to compare investments, 233

to decide an amount to invest, 231–232

Q

QUARTILE function, calculate quartiles, 156–157

Quarts, liters convertion to, 22

Question mark, 65

Quick Analysis Tool, 473–475

Quick calendar creation, 8–9

QUOTIENT function, return integer portion of division, 192–193

R

RANDBETWEEN function, generate random values in specified range, 201–202

RAND function, generate random values, 200–201

Random number generation, 500

Range, 151, 371

SUM function to sum, 169–170

RANK function, sales in rank order, 153–154

RATE function, calculate interest rate, 238–239

R1C1-style reference, 272

REPLACE function, 77

replace and calculate, 75–76

REPT function

data

in chart, 86

in graphic mode, 85

RIGHT functions

to extract date parts, 110–111

to separate text string of numbers, 63–64

ROMAN function, convert Arabic to Roman numerals, 208

Roman to Arabic numerals, ARABIC function to convert, 209

ROUNDDOWN function, round down numbers, 181–182

ROUND functions

compare, INT and TRUNC function, 219–220

to round numbers, 180–181

to round time values

to whole hours, 184–185

to whole minutes, 183–184

Round numbers, use ROUND function to, 180–181

ROUNDUP function to round up numbers, 182–183

ROW functions, 279

determine last cell used, 336–337

to mark every other row, 197–198

MOD functions and, 300–301

numeric values of text, 358–359

to sum last row in dynamic list, 350

S

Sales distribution, 30–31

Sales taxes calculation, 12–13

SEARCH function

separate first name from last name, 65–66

syntax for, 76

Share Files, 470–471

Shortcut keys, 507, 510

clipboard actions, 510

excel and workbooks, 509

format cell contents, 509

go to cells or highlight cell ranges, 508

highlight group of cells, 509

move around within a workbook and worksheet, 509

SIGN function, check for sign of number, 212

SLN function, calculate straight-line depreciation, 230–231

SMALL function

compare prices and cheapest offers, 144

smallest value in list, 141

Smart Lookup, 469

Space, 64

Special characters, use CHAR function, 87–88

Special ranking list generation, 15–16

Special solutions with formulas

custom function, see Custom function

EXACT function to allow only uppercase characters, 370–371

prevent duplicate input, use COUNTIF function, 369–370

use controls, 375–377

validation to allow data input, 371–372

Square and cube roots calculation, 193–194

Standard deviation, use STDEV function, 158–159

Statistical functions

calculation

average output, use AVERAGE function, 145

median sales, use MEDIAN function, 154–155

quartiles, use QUARTILE function, 156–157

COUNTA function

to count cells data, 148

to count cells text, 149

last filled row, 151

count cells number, use COUNT function, 147

data correlation determination, use CORREL function, 165–166

future values, see Future values INDEX and MATCH functions, 143

LARGE function, see LARGE functions

MAX function, largest value in range, 135–136

MAXIFS function, highest monthly sales, 138–139

MEDIAN function, calculate median sales, 154–155

MIN function

lowest sales for month, 136–137

smallest value in column, 140

MINIFS function, lowest monthly sales, 137–138

RANK function, sales in rank order, 153–154

SMALL function

compare prices and cheapest offers, 144

smallest value in list, 141

standard deviation, use STDEV function, 158–159

SUBTOTAL function, 146

STDEV function, standard deviation, 158–159

Stock, gain/loss of, 17

Stocks icon, 478–479

String, number of characters in, 34–36

SUBSTITUTE functions, 34–36

to combine and separate columns, 74–75

convert numbers to words, 72–73

count occurrences of specific word in range, 351–352

to remove word wrapping in cells, 73–74

to search for text, 317–318

substitute

characters, 70–71

parts of cell, 71–72

SUBTOTAL function

to count all visible rows in filtered list, 199–200

filtered lists

count rows in, 152

sum, 146

for multiple calculations, 198–199

to perform several operations, 198–199

SUM functions, 257–258

count

all digits in range, 353

certain characters in range, 350–351

numbers from x to y, 346–347

occurrences of specific word in range, 351–352

special values, 344

today’s sales of a specific product, 348

unique records in list, 355

values match several criteria, 346

values match two criteria, 345

sum

last row in dynamic list, 350

range, 169–170

several ranges, 170–171

values with several criteria, 343

SUMIF function, 178

to determine sales of team, 171–172

to sum costs

higher than $1,000, 173

up to certain date, 174

SUMIFS function, sales of team and gender, 216–217

SUMPRODUCT function

to calculate the value of the inventory, 177–178

to multiply and sum at same time, 179–180

to sum sales of team, 178–179

SUMSQ function, determine square sum, 213

SWITCH function

to compare two cells, 52

multiple condition method using, 57

SYD function, calculate depreciation, 229–230

T

Target, 25

Tax percentage, 31

Text/character, 65

TEXT functions

calculate with TODAY function, 106–107

CHAR functions, see CHAR functions

CLEAN function, 84

combine text, see Combine text

EXACT function to compare two columns, 69–70

to extract date parts, 111–112

FIXED function, 81–82

LEFT function, see LEFT functions

LOWER function, 79

MID function

separate last name from first name, 67

to sum digits of number, 68

PROPER function, 80–81

REPLACE function, to replace and calculate, 75–76

REPT function, see REPT function

RIGHT function, separate text string of numbers, 63–64

SEARCH function, separate first name from last name, 65–66

SUBSTITUTE, see SUBSTITUTE functions

T function, 92–93

TRIM function, 82–84

UNICHAR function, 89–90

UNICODE function, 90–91

UPPER function, 78–79

TEXTJOIN function, combine text, 97–99

T function, for valid numbers, 92–93

360-day year, use DAYS360 function, 119–120

Time format, customized formatting to create, 131–132

TIME function, combine single time parts, 133–134

Timesheet creation, use IF function, 59–60

TIMEVALUE function, convert text to time, 130–131

TODAY functions, 58

birthdays in current month, 328–329

check for future dates, 105–106

to shade specific column, 298–299

to show completed sales, 295–297

sum sales up to today, 257–258

TEXT function calculate with, 106–107

TRANSPOSE functions

duplicate numbers in list, 357–358

vertical/horizontal range, 360–361

TRIM function

convert “text-numbers” to real numbers, 83–84

to delete spaces, 82–83

TRUNC functions, compare, INT and ROUND function, 219–220

TYPE function, for invalid values, 54

U

UNICHAR function, Unicode character from number, 89–90

Unicode characters, 89–90

UNICODE function, numeric Unicode value of character, 90–91

Unlocked cells, use CELL function to, 323–324

UPPER function, convert text lowercase to uppercase, 78–79

User-defined functions

cell contains

data validation, 394–395

formula, 393

in conditional formatting, 315

create own AutoText, 408–409

cross sum

of cell, 404–405

in range, 405–406

current Windows user, 391

delete all leading zeros, 399–400

in detect cells with formulas, 313–314

to find all comments, 395–396

first number position, 403–404

specific cells

delete all letters in, 400–401

delete all numbers in, 401–402

display formulas of, 392

sum all cells with colored font, 398

to sum all shaded cells, 396–397

with valid numeric values, 315–316

in Visual Basic Editor, 406

workbook

copy name of into cell, 389

full name of, 390

path of, 390

worksheet

copy name into cell, 387–388

empty, 406–407

protected, 407–408

U.S. (NASD) method, 120

V

Validation, 369

to allow data input, 371–372

prevent duplicate input, use COUNTIF function, 369–370

Valid numbers

convertion, invalid to, 64–65

T function for, 92–93

VBA, see Visual Basic for Applications Visual Basic Editor, 406

Visual Basic for Applications (VBA), 379

VLOOKUP function, 247, see also INDEX functions

compare offers from different suppliers, 264

look up and extract data from list, 260–262

W

WEEKDAY function

calculate weeks of Advent, 129

calculate with different hourly pay rates, 121

detect and shade weekends, 293–295

to determine weekend, 104–105

Weekend, WEEKDAY function to determine, 104–105

WEEKNUM function

determine week number, 122

and MOD functions, 299–300

Weeks of Advent calculation, 129

Whole number, divided by 4, 53

Wildcard characters, 65

Word wrapping, use SUBSTITUTE function, 73–74

Workbooks

cells in, use IF function, 46

delete all external links in, 384

use user-defined functions

copy name of into cell, 389

full name of, 390

path of, 390

WORKDAY function, to calculate workdays, 124–125

Working with array formulas

ADDRESS functions, determine last cell used, 336–337

AVERAGE functions

average of x largest numbers, 356–357

taking zero values, 342

COLUMN functions

count certain characters in range, 350–351

last column used in range, 339–340

last number in row, 338–339

COUNT functions, largest gain/loss of shares, 353–354

COUNTIF functions

count unique records in list, 355

whether all numbers are unique, 359–360

DATEVALUE function, 348

FREQUENCY function, 362

IF functions

last column used in range, 339–340

lowest nonzero value in range, 340–341

to sum last row in dynamic list, 350

sum values with several criteria, 343

taking zero values, 342

INDEX functions

last number in column, 337–338

last number in row, 338–339

matches two criteria, 344

INDIRECT functions, 353–354

ISNUMBER functions, last number in row, 338–339

LARGE functions, average of x largest numbers, 356–357

LEN functions

count all digits in range, 353

count occurrences of specific word in range, 351–352

MATCH functions

matches two criteria, 344

numeric values of text, 358–359

MAX functions

determine last cell used, 336–337

largest gain/loss of shares, 353–354

last column used in range, 339–340

last number in row, 338–339

to sum last row in dynamic list, 350

whether all numbers are unique, 359–360

MID functions

count certain characters in range, 350–351

numeric values of text, 358–359

MIN functions, lowest nonzero value in range, 340–341

OFFSET functions, 350

OR functions, duplicate numbers in list, 357–358

ROW functions

determine last cell used, 336–337

numeric values of text, 358–359

to sum last row in dynamic list, 350

SUBSTITUTE functions, 351–352

SUM functions, see SUM functions

TRANSPOSE functions

duplicate numbers in list, 357–358

vertical/horizontal range, 360–361

Worksheets

cells in, use IF function, 46

invalid values in, 54

use user-defined functions

copy name into cell, 387–388

empty, 406–407

protected, 407–408

X

XOR function, check for mutually exclusive conditions, 41–42

Y

YEARFRAC function, calculate employees ages, 126–127

YEAR function, extract year part of date, 113–114