Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 30

1.

EXCEL Basic Functions


Worksheet functions are categorized by their functionality. Click a
category to browse its functions. Or press Ctrl+F to find a function
by typing the first few letters or a descriptive word. To get detailed
information about a function, click its name in the first column.

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

Rules -> If (cell A1) is less than 20, then times it by 1,


If it is greater than or equal to 20 but less than 50, then times it by 2
If its is greater than or equal to 50 and less than 100, then times it by 3
And if it is great or equal to than 100, then times it by 4
Answer: You can write a nested IF statement to handle this:
=IF(A1<20, A1*1, IF(A1<50, A1*2, IF(A1<100, A1*3, A1*4)))
5. DATE and TIME Functions

In excel, A date is simply a number. More precisely, a date is a serial


number that represents the number of days since the fictitious date of
January 0, 1900. A serial number of 1 corresponds to January 1, 1900; a
serial number of 2 corresponds to January 2, 1900, and so on.

Excel support dates from January 1, 1900, through December 31, 9999
(serial number = 2,958,465).

The following function displays the current date in a cell: =TODAY()

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

This function will return the current date and time.

Syntax
NOW()
Example
In this example we return today’s date and time.

=NOW()
TODAY Function

This function will return the current date.

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

DAYS(Start Date, End Date)

 Start Date (required) – This is the starting date of the period.

 End Date (required) – This is the ending date of the period.


Example

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

DATE(Year, Month, Day)

 Year (required) – This is the year number from 1900 to 9999.

 Month (required) – This is the month number from 1 to 12.

 Day (required) – This is the day number from 1 to 31.

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

The formula returns TRUE if a


Returns TRUE if all of the
=AND(A2>=10, value in cell A2 is greater than or
AND arguments evaluate to B2<5) equal to 10, and a value in B2 is
TRUE.
less than 5, FALSE otherwise.

The formula returns TRUE if A2


is greater than or equal to 10 or
Returns TRUE if any
=OR(A2>=10, B2 is less than 5, or both
OR argument evaluates to B2<5) conditions are met. If neither of
TRUE.
the conditions it met, the formula
returns FALSE.
The formula returns TRUE if
either A2 is greater than or equal
Returns a logical
=XOR(A2>=10, to 10 or B2 is less than 5. If
XOR Exclusive Or of all B2<5) neither of the conditions is met or
arguments.
both conditions are met, the
formula returns FALSE.

Returns the reversed


logical value of its
The formula returns FALSE if a
argument. I.e. If the
NOT =NOT(A2>=10) value in cell A1 is greater than or
argument is FALSE, then
equal to 10; TRUE otherwise.
TRUE is returned and
vice versa.

Using the AND function in Excel


the AND function tests the conditions you specify and returns TRUE if all of the conditions evaluate
to TRUE, FALSE otherwise.

The syntax for the Excel AND function is as follows:

AND(logical1, [logical2], …)

Formula Description

=AND(A2="Bananas", Returns TRUE if A2 contains "Bananas" and B2 is greater


B2>C2) than C2, FALSE otherwise.

=AND(B2>20, B2=C2)
Returns TRUE if B2 is greater than 20 and B2 is equal to
C2, FALSE otherwise.

=AND(A2="Bananas", Returns TRUE if A2 contains "Bananas", B2 is greater than


B2>=30, B2>C2)
or equal to 30 and B2 is greater than 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:

=IF(AND(A2="Bananas", B2>C2), "Good", "Bad")

Using the OR function in Excel


As well as AND, the Excel OR function is a basic logical function that is used to compare two values
or statements. The difference is that the OR function returns TRUE if at least one if the arguments
evaluates to TRUE, and returns FALSE if all arguments are FALSE.

The syntax of the Excel OR function is very similar to AND:

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(A2="Bananas", Returns TRUE if A2 contains "Bananas" or "Oranges",


FALSE otherwise.
A2="Oranges")

=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.

=OR(B2=" ", C2="")


Returns TRUE if either B2 or C2 is blank or both, 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:

IF function with nested OR

=IF(OR(B2>30, C2>20), "Good", "Bad")

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.

Using the XOR function in Excel


XOR function, which is a logical Exclusive OR function.

The syntax of the XOR function is identical to OR's :

XOR(logical1, [logical2],…)

In the simplest version, an XOR formula contains just 2 logical statements and returns:

 TRUE if either argument evaluates to TRUE.


 FALSE if both arguments are TRUE or neither is TRUE.

This might be easier to understand from the formula examples:


Formula Result Description

Returns TRUE because the 1st argument is TRUE and the


=XOR(1>0, 2<1) TRUE
2nd argument is FALSE.

=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:

 TRUE if an odd number of the arguments evaluate to TRUE;


 FALSE if is the total number of TRUE statements is even, or if all statements are FALSE.

The screenshot below illustrates the point:

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.

A simple XOR formula works exactly as we want:


=XOR(B2="Won", C2="Won")

Using the NOT function in Excel


The NOT function is one of the simplest Excel functions in terms of syntax:

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.

To apply these Data Validation rules;

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.

Allow Uppercase Entries Only


You may need to ensure that data is entered in uppercase, such as this example
of UK postcodes being entered.
The cells need to accept the entry of both text and numbers, but the text must
be uppercase.
For this we can use a formula with the UPPER and the EXACT functions.
The UPPER function probably speaks for itself. It converts text into uppercase.
The EXACT function is used to compare the cell entry with the uppercase version
to see if they are the same. If they are, then the entry is valid.
For this example, the validation was applied to range A2:A6. Select Custom from
the Allow list and enter the following formula into the Formula box.
=EXACT(A2,UPPER(A2))

Prevent Future Dates


Entering dates is very common on a spreadsheet. Unfortunately users entering
the wrong date is also commonplace.
By using validation rules, we can limit the mistake a user may make.
In this example, we prevent the entry of a future date. Maybe users are
recording a transaction that has occurred. Therefore, it must be a date in the
past or todays date.
Select Date from the Allow list and then Less than or equal to from Data.
In the End Date box, type the formula below.
=TODAY()
The TODAY function returns the current date from the computer. Incredibly
useful. Check out more great Excel date functions.
Creating Drop Down Lists
Creating drop down lists is the reason most people become familiar with the
Data Validation feature. Creating lists is a simple and effective way of controlling
data entry.
Select List from the Allow list. You can then either type the list items directly into
the Source box separated by a comma, or refer to a range of cells that contain
the list items.

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.

Prevent Duplicate Values


Duplicate values are a very common problem in Excel. There are many techniques for
identifying and removing duplicates, but it would be better if you could prevent them in
the first place.

By using the COUNTIF function in a custom formula we can.

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.

Adding Fields to the Pivot Table

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

Generate Pivot Chart


11.Charts and Slicers
Charts can convey much more than numbers alone can because charts present data in
a visual way that makes it easier to see the meaning behind the numbers. And with the
new charting capabilities in Microsoft Office, it's easier than ever to turn raw data into
meaningful information.
Charts start with data. In Office Excel, you just select data in your worksheet, choose a
chart type that best suits your purpose, and click. Want to try a different chart type? Just
click again and select a new chart type from a huge range of possibilities. Then work
with the new Chart Tools to customize the design, layout, and formatting of your chart.
You can see how various options would look just by pointing at them in the dialog box
— you don't have to spend time applying different selections to find the look you want.
And when your chart is exactly the way you want it, you can save it as a template to use
again, in Excel or in other Office system programs such as Word.
1.The chart area (chart area: The entire chart and all its elements.) of the chart.
2.The plot area (plot area: In a 2-D chart, the area bounded by the axes, including all
data series. In a 3-D chart, the area bounded by the axes, including the data series,
category names, tick-mark labels, and axis titles.) of the chart.
3.The data points (data points: Individual values plotted in a chart and represented by
bars, columns, lines, pie or doughnut slices, dots, and various other shapes called data
markers. Data markers of the same color constitute a data series.) of the data series
(data series: Related data points that are plotted in a chart. Each data series in a chart
has a unique color or pattern and is represented in the chart legend. You can plot one
or more data series in a chart. Pie charts have only one data series.) that are plotted in
the chart.
4.The horizontal (category) and vertical (value) axis (axis: A line bordering the chart plot
area used as a frame of reference for measurement. The y axis is usually the vertical
axis and contains data. The x-axis is usually the horizontal axis and contains
categories.) along which the data is plotted in the chart.
5.The legend (legend: A box that identifies the patterns or colors that are assigned to
the data series or categories in a chart.) of the chart.
6. A chart and axis title (titles in charts: Descriptive text that is automatically aligned to
an axis or centered at the top of a chart.) that you can use in the chart.
7.A data label (data label: A label that provides additional information about a data
marker, which represents a single data point or value that originates from a datasheet
cell.) that you can use to identify the details of a data point in a data series.
Modifying Charts

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.

Using the Code from Excel Macro:

 Open the Workbook in which you want to use the macro.


 Hold the ALT key and press F11. This opens the VB Editor.
 Right-click on any of the objects in the project explorer.
 Go to Insert –> Module.
 Copy and Paste the code in the Module Code Window.
Once you have inserted the code in a workbook, you need to save it
with a .XLSM or .XLS extension.

How to Run the Macro


Once you have copied the code in the VB Editor, here are the steps to run the
macro:

 Go to the Developer tab.

 Click on Macros.
 In the Macro dialog box, select the macro you want to run.
 Click on Run button

Sort Worksheets Alphabetically Using VBA


If you have a workbook with many worksheets and you want to sort these
alphabetically, this macro code can come in really handy. This could be the case
if you have sheet names as years or employee names or product names.
'This code will sort the worksheets alphabetically
Sub SortSheetsTabName()
Application.ScreenUpdating = False
Dim ShCount As Integer, i As Integer, j As Integer
ShCount = Sheets.Count
For i = 1 To ShCount - 1
For j = i + 1 To ShCount
If Sheets(j).Name < Sheets(i).Name Then
Sheets(j).Move before:=Sheets(i)
End If
Next j
Next i
Application.ScreenUpdating = True
End Sub

Convert All Formulas into Values


Use this code when you have a worksheet that contains a lot of formulas and you
want to convert these formulas to values.
'This code will convert all formulas into values
Sub ConvertToValues()
With ActiveSheet.UsedRange
.Value = .Value
End With
End Sub
This code automatically identifies cells are used and convert it into values.

Protect/Lock Cells with Formulas


You may want to lock cells with formulas when you have a lot of calculations and you
don’t want to accidentally delete it or change it.
Here is the code that will lock all the cells that have formulas, while all the other cells
are not locked.
'This macro code will lock all the cells with formulas
Sub LockCellsWithFormulas()
With ActiveSheet
.Unprotect
.Cells.Locked = False
.Cells.SpecialCells(xlCellTypeFormulas).Locked = True
.Protect AllowDeletingRows:=True
End With
End Sub

Change the Letter Case of Selected Cells to Upper Case


While Excel has the formulas to change the letter case of the text, it makes you do that
in another set of cells.
Use this code to instantly change the letter case of the text in the selected text.
'This code will change the Selection to Upper Case
Sub ChangeCase()
Dim Rng As Range
For Each Rng In Selection.Cells
If Rng.HasFormula = False Then
Rng.Value = UCase(Rng.Value)
End If
Next Rng
End Sub

Note that in this case, I have used UCase to make the text case Upper. You can use
LCase for lower case.

You might also like