Professional Documents
Culture Documents
EXCEL Basic Functions:, But They Are Also The Root Cause of Many Spreadsheet Issues
EXCEL Basic Functions:, But They Are Also The Root Cause of Many Spreadsheet Issues
Excel If
In Excel, If function returns one value if a specified condition evaluates to TRUE, or another
value if it evaluates to FALSE.
The syntax for the If function is:
If( condition, value_if_true, value_if_false )
condition is the value that you want to test.
value_if_true is the value that is returned if condition evaluates to TRUE.
value_if_false is the value that is return if condition evaluates to FALSE.
e.g IF(Service=‘Y’,ServiceTax=12.33,ServiceTax=0)
The IF function is one of the most popular functions in Excel, and it allows you
to make logical comparisons between a value and what you expect. In its
simplest form, the IF function says:
IF(Something is True, then do something, otherwise do something else)
So an Simple IF statement can have two results. The first result is if your
comparison is True, the second if your comparison is False.
IF statements are incredibly robust, and form the basis of many spreadsheet
models, but they are also the root cause of many spreadsheet issues. Ideally, an
IF statement should apply to minimal conditions, such as Male/Female,
Yes/No/Maybe, to name a few, but sometimes you might need to evaluate more
complex scenarios that require nesting* more than 3 IF functions togethe r.
Excel Nested If
Excel support dates from January 1, 1900, through December 31, 9999
(serial number = 2,958,465).
The DATEVALUE function converts a text string that looks like a date into
a date serial number. The following formula returns 39316, the date serial
number for August 22, 2007: =DATEVALUE(“8/22/2007”)
The following formula returns TRUE if the year of the date in cell A1 is a
leap year. Otherwise, it returns FALSE.
=IF(MONTH(DATE(YEAR(A1),2,29))=2,TRUE,FALSE)
NOW Function
Syntax
NOW()
Example
In this example we return today’s date and time.
=NOW()
TODAY Function
Syntax
TODAY()
There are no arguments for this function.
Example
In this example we return today’s date.
=TODAY()
DAYS Function
This function will allow you to find the number of days between two dates.
Syntax
In this example we find the number of days between two dates. Notice that if the end
date is older than the start date the result is a negative number. The same result can
be obtained by subtracting the start date from the end date.
=DAYS(A2,B2)
DATE Function
This function will convert a day, month and year to a serial number that Excel uses for
date values.
Syntax
Example
In this example we create a few dates by reference to a year, month and day. Notice
that if we use a month greater than 12 or a day greater than the actual number of days
in the month, then the result rolls over into the next month or year.
=DATE(A2,B2,C2)
DAY Function
This function will take a date in any format and return the day as an integer from 1 to
31. Numbers not formatted as a date will return a day value as long as the number is in
the range 1 to 2,958,465 as this corresponds to the date range 01/01/1900 to
31/12/9999.
Syntax
DAY(Date)
Date (required) – This is the date value that you want to return the day from.
Example
In this example we use the function on several dates in different formats. Notice the
text values we try result in a #VALUE! error while numerical values outside of the range
1 to 2,958,465 result in a #NUM! error.
=DAY(A2)
MONTH Function (Same as YEAR())
This function will take a date in any format and return the month as an integer from 1 to 12. Numbers
not formatted as a date will return a month value as long as the number is in the range 1 to 2,958,465
as this corresponds to the date range 01/01/1900 to 31/12/9999.
Syntax
MONTH(Date)
Date (required) – This is the date value that you want to return the month from.
Example
In this example we use the function on several dates in different formats. Notice the text values we
try result in a #VALUE! error while numerical values outside of the range 1 to 2,958,465 result in a
#NUM! error.
=MONTH(A2)
8. LOGICAL FUNCTIONS
Microsoft Excel provides 4 logical functions to work with the logical values. The functions are AND,
OR, XOR and NOT.
Functio Formula
Description Formula Description
n Example
AND(logical1, [logical2], …)
Formula Description
=AND(B2>20, B2=C2)
Returns TRUE if B2 is greater than 20 and B2 is equal to
C2, FALSE otherwise.
For example, you can nest any of the AND functions above inside the IF function and get a result
similar to this:
OR(logical1, [logical2], …)
let's write down a few formulas for you to get a feel how the OR function in Excel works.
Formula Description
=OR(B2>=40, C2>=20)
Returns TRUE if B2 is greater than or equal to 40 or C2 is
greater than or equal to 20, FALSE otherwise.
As well as Excel AND function, OR is widely used to expand the usefulness of other Excel functions
that perform logical tests, e.g. the IF function. Here are just a couple of examples:
The formula returns "Good" if a number in cell B3 is greater than 30 or the number in C2 is greater
than 20, "Bad" otherwise.
XOR(logical1, [logical2],…)
In the simplest version, an XOR formula contains just 2 logical statements and returns:
=XOR(1<0, 2<1) FALSE Returns FALSE because both arguments are FALSE.
=XOR(1>0, 2>1) FALSE Returns FALSE because both arguments are TRUE.
When more logical statements are added, the XOR function in Excel results in:
Suppose you have a table of contestants and their results for the first 2 games. You want to know
which of the payers shall play the 3rd game based on the following conditions:
Contestants who won Game 1 and Game 2 advance to the next round automatically and
don't have to play Game 3.
Contestants who lost both first games are knocked out and don't play Game 3 either.
Contestants who won either Game 1 or Game 2 shall play Game 3 to determine who goes
into the next round and who doesn't.
NOT(logical)
You use the NOT function in Excel to reverse a value of its argument. In other words, if logical
evaluates to FALSE, the NOT function returns TRUE and vice versa. For example, both of the below
formulas return FALSE:
=NOT(TRUE)
=NOT(2*2=4)
EXAMPLE:
=NOT(C2="black")
9. DATA VALIDATIONS
Microsoft Excel data validation lets you define what type of data you want entered in a
cell. For example, you can allow entry of a letter grade with only the letters A through F.
You can set up data validation to prevent users from entering data that isn't valid, or
allow invalid data but check for it after the user is finished. You can also provide
messages to define what input you expect for the cell, and instructions to help users
correct any errors.
Data validation is particularly useful when you're designing forms or worksheets that
other people will use to enter data, such as budget forms or expense reports.
When data is entered that does not meet your requirements, Excel displays a message with
instructions you provide.
When data is entered that does not meet your requirements, Excel displays a message with
instructions you provide.
Types of data you can validate:
Excel lets you designate the following types of valid data for a cell:
• Numbers: Specify that the entry in a cell must be a whole number or a decimal
number. You can set a minimum or maximum, exclude a certain number or range,
or use a formula to calculate whether a number is valid.
• Dates and times: Set a minimum or maximum, exclude certain dates or times, or
use a formula to calculate whether a date or time is valid.
• Length: Limit how many characters can be typed in a cell or require a minimum
number of characters.
• List of values: Make a list of the choices for a cell — such as small, medium,
large — and allow only those values in the cell. You can display a dropdown arrow
when a user clicks the cell to make it easy to pick from your list.
1. First select the range of cells you want to apply the validation to.
2. Click the Data tab and then the Data Validation button on the Ribbon.
3. In the Settings tab, select the validation rule criteria.
When you need a simple list such as Open and Closed, or Yes and No, then
typing the entries in makes sense.
When you need a more dynamic list for items that change over time such as lists
of products, places and people, then referring to a range makes sense.
For this list, click in the Source box and then go and select the cells that contain
the items.
In this example, the items were in range A1:A5 of a sheet called Names.
The formula below counts the occurrences of the inputted value in the range A2:A8. If
the answer is 0 then the value is unique and allowed.
=COUNTIF($A$2:$A$8,A2)=0
Allow Only Numeric Or Text Entries
The ISNUMBER function can be used to create a validation rule that only allows the
entry of numeric values in a cell.
Select Custom from the Allow list and use the formula below. In this example, cell A2 is
the upper left cell of the selected range of cells.
=ISNUMBER(A2)
This will allow any numeric values only including dates and times.
To allow text values only we could use the ISTEXT function in the same way.
=ISTEXT(A2)
10. PIVOT TABLE
The first step in creating a Pivot Table is to organize your data in a list of rows
and columns. you can format this list as an Excel Table, and use that as the
dynamic source for your Pivot Table.
Before you create a pivot table, make sure your data is organized correctly. There
are instructions on the following pages, for setting up your source data in a table,
organized into rows and columns.
An empty pivot table is created in your workbook, either on a new sheet, or the existing sheet
that you selected. When you select a cell within the pivot table, a PivotTable Field List appears,
at the right of the worksheet.
Grouping Pivot Table
In a Pivot Table, you can group the items in a Row or Column field.
For example, items in a date field can be grouped by month, and items in a number
field can be grouped by tens.
In the Sample Pivot Sales book -> TestPivot sheet
Right-click the Date field button.
Choose Group to select the Group Field
After you create a chart, you can modify any one of its elements. For example, you
might want to change the way that axes are displayed, add a chart title, move or hide
the legend, or display additional chart elements.
To modify a chart, you can:
Change the display of chart axes You can specify the scale of axes and adjust the
interval between the values or categories that are displayed. To make your chart easier
to read, you can also add tick marks (tick marks and tick-mark labels: Tick marks are
small lines of measurement, similar to divisions on a ruler, that intersect an axis. Tick-
mark labels identify the categories, values, or series in the chart.) to an axis and specify
the interval at which they will appear.
Add titles and data labels to a chart To help clarify the information that appears in
your chart, you can add a chart title, axis titles, and data labels.
Add a legend or data table You can show or hide a legend, change its location, or
modify the legend entries. In some charts, you can also show a data table (data table: A
range of cells that shows the results of substituting different values in one or more
formulas. There are two types of data tables: one-input tables and two-input tables.)
that displays the legend keys (legend keys: Symbols in legends that show the patterns
and colors assigned to the data series (or categories) in a chart. Legend keys appear to
the left of legend entries.
Formatting a legend key also formats the data marker that's associated with it.) and the
values that are presented in the chart.
Apply special options for each chart type Special lines (such as high-low lines and
trendlines (trendline: A graphic representation of trends in data series, such as a line
sloping upward to represent increased sales over a period of months. Trendlines are
used for the study of problems of prediction, also called regression analysis.)), bars
(such as up-down bars and error bars), data markers (data marker: A bar, area, dot,
slice, or other symbol in a chart that represents a single data point or value that
originates from a worksheet cell. Related data markers in a chart constitute a data
series.), and other options are available for different chart types.
12. VBA Macros
VBA stands for Visual Basic for Applications an event driven programming language
from Microsoft that is now predominantly used with Microsoft office applications such as
MS-Excel, MS-Word and MS- Access.
Using Excel Macros can speed up work and save you a lot of time.
One way of getting the VBA code is to record the macro and take the code it
generates. However, that code by macro recorder is often full of code that is
not really needed. Also macro recorder has some limitations.
So it pays to have a collection of useful VBA macro codes that you can have
in your back pocket and use it when needed.
While writing an Excel VBA macro code may take some time initially, once it’s
done, you can keep it available as a reference and use it whenever you need
it next.
Click on Macros.
In the Macro dialog box, select the macro you want to run.
Click on Run button
Note that in this case, I have used UCase to make the text case Upper. You can use
LCase for lower case.