0% found this document useful (0 votes)
3 views

Excel Notes Part3

The document provides a comprehensive guide on using macros in Microsoft Excel to automate repetitive tasks, including recording and managing macros using the Macro Recorder and Visual Basic for Applications (VBA). It also covers the AVERAGEIF function for calculating averages based on specific criteria, along with the definitions and calculations of mean, median, and mode. Additionally, it explains how to freeze panes in Excel to keep certain rows or columns visible while scrolling.

Uploaded by

shivani.garg
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Excel Notes Part3

The document provides a comprehensive guide on using macros in Microsoft Excel to automate repetitive tasks, including recording and managing macros using the Macro Recorder and Visual Basic for Applications (VBA). It also covers the AVERAGEIF function for calculating averages based on specific criteria, along with the definitions and calculations of mean, median, and mode. Additionally, it explains how to freeze panes in Excel to keep certain rows or columns visible while scrolling.

Uploaded by

shivani.garg
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

Macros

To automate a repetitive task, you can record a macro with the Macro Recorder in Microsoft
Excel. Imagine you have dates in random formats and you want to apply a single format to all of
them. A macro can do that for you. You can record a macro applying the format you want, and
then replay the macro whenever needed.
When you record a macro, the macro recorder records all the steps in Visual Basic for
Applications (VBA) code. These steps can include typing text or numbers, clicking cells or
commands on the ribbon or on menus, formatting cells, rows, or columns, or even importing data
from an external source, say, Microsoft Access. Visual Basic Application (VBA) is a subset of
the powerful Visual Basic programming language, and is included with most Office applications.
Although VBA gives you the ability to automate processes within and between Office
applications, it is not necessary to know VBA code or computer programming if the Macro
Recorder does what you want.
It is important to know that you when you record a macro, the Macro Recorder captures almost
every move you make. So if you make a mistake in your sequence, for example, clicking a
button that you did not intend to click, the Macro Recorder will record it. The resolution is to re-
record the entire sequence, or modify the VBA code itself. This is why whenever you record
something, it's best to record a process with which you're highly familiar. The more smoothly
you record a sequence, the more efficiently the macro will run when you play it back.
Macros and VBA tools can be found on the Developer tab, which is hidden by default, so the
first step is to enable it.

Record a macro
There are a few helpful things you should know about macros:
 When you record a macro for performing a set of tasks in a range in Excel, the macro will
only run on the cells within the range. So if you added an extra row to the range, the
macro will not run the process on the new row, but only the cells within the range.
 If you have planned a long process of tasks to record, plan to have smaller relevant
macros instead of having one long macro.
 It is not necessary that only tasks in Excel can be recorded in a macro. Your macro
process can extend to other Office applications, and any other applications that support
Visual Basic Application (VBA). For example, you can record a macro where you first
update a table in Excel and then open Outlook to email the table to an email address.
Follow these steps to record a macro.
1. On the Developer tab, in the Code group, click Record Macro.
-OR-
Press Alt+T+M+R .

2. In the Macro name box, enter a name for the macro. Make the name as descriptive as
possible so you can quickly find it if you create more than one macro.
Note: The first character of the macro name must be a letter. Subsequent characters can be
letters, numbers, or underscore characters. Spaces cannot be used in a macro name; an
underscore character works well as a word separator. If you use a macro name that is also a cell
reference, you may get an error message that the macro name is not valid.
3. To assign a keyboard shortcut to run the macro, in the Shortcut key box, type any letter
(both uppercase or lowercase will work) that you want to use. It is best to
use Ctrl + Shift (uppercase) key combinations, because the macro shortcut key will
override any equivalent default Excel shortcut key while the workbook that contains the
macro is open. For instance, if you use Ctrl+Z (Undo), you will lose the ability to Undo
in that Excel instance.
4. In the Store macro in list, select where you want to store the macro.
In general, you’ll save your macro in the This Workbook location, but if you want a macro to be
available whenever you use Excel, select Personal Macro Workbook . When you select Personal
Macro Workbook, Excel creates a hidden personal macro workbook (Personal.xlsb) if it does
not already exist, and saves the macro in this workbook.
5. In the Description box, optionally type a brief description of what the macro does.
Although the description field is optional, it is recommended you enter one. Also, try to enter a
meaningful description with any information that may be useful to you or other users who will be
running the macro. If you create a lot of macros, the description can help you quickly identify
which macro does what, otherwise you might have to guess.
6. Click OK to start recording.
7. Perform the actions that you want to record.

8. On the Developer tab, in the Code group, click Stop Recording .


-OR-
Press Alt+T+M+R .
Working with recorded macros in Excel
In the Developer tab, click Macros to view macros associated to a workbook. Or press Alt+ F8.
This opens the Macro dialog box.

Caution: Macros cannot be undone. Before you run a recorded macro for the first time, make
sure that you’ve either saved the workbook where you want to run the macro, or better yet work
on a copy of the workbook to prevent unwanted changes. If you run a macro and it doesn’t do
what you want, you can close the workbook without saving it.
AVERAGEIF
Returns the average (arithmetic mean) of all the cells in a range that meet a given criteria.
Syntax
AVERAGEIF(range, criteria, [average_range])
The AVERAGEIF function syntax has the following arguments:
 Range Required. One or more cells to average, including numbers or names, arrays, or
references that contain numbers.
 Criteria Required. The criteria in the form of a number, expression, cell reference, or
text that defines which cells are averaged. For example, criteria can be expressed as 32,
"32", ">32", "apples", or B4.
 Average_range Optional. The actual set of cells to average. If omitted, range is used.
Remarks
 Cells in range that contain TRUE or FALSE are ignored.
 If a cell in average_range is an empty cell, AVERAGEIF ignores it.
 If range is a blank or text value, AVERAGEIF returns the #DIV0! error value.
 If a cell in criteria is empty, AVERAGEIF treats it as a 0 value.
 If no cells in the range meet the criteria, AVERAGEIF returns the #DIV/0! error value.
 You can use the wildcard characters, question mark (?) and asterisk (*), in criteria. A
question mark matches any single character; an asterisk matches any sequence of
characters. If you want to find an actual question mark or asterisk, type a tilde (~) before
the character.
 Average_range does not have to be the same size and shape as range. The actual cells that
are averaged are determined by using the top, left cell in average_range as the beginning
cell, and then including cells that correspond in size and shape to range. For example:

If range is And average_range is Then the actual cells evaluated are

A1:A5 B1:B5 B1:B5

A1:A5 B1:B3 B1:B5

A1:B4 C1:D4 C1:D4

A1:B4 C1:C2 C1:D4


Note: The AVERAGEIF function measures central tendency, which is the location of the center
of a group of numbers in a statistical distribution. The three most common measures of central
tendency are:
 Average which is the arithmetic mean, and is calculated by adding a group of numbers
and then dividing by the count of those numbers. For example, the average of 2, 3, 3, 5,
7, and 10 is 30 divided by 6, which is 5.
 Median which is the middle number of a group of numbers; that is, half the numbers
have values that are greater than the median, and half the numbers have values that are
less than the median. For example, the median of 2, 3, 3, 5, 7, and 10 is 4.
 Mode which is the most frequently occurring number in a group of numbers. For
example, the mode of 2, 3, 3, 5, 7, and 10 is 3.
For a symmetrical distribution of a group of numbers, these three measures of central tendency
are all the same. For a skewed distribution of a group of numbers, they can be different.
Examples
Copy the example data in the following table, and paste it in cell A1 of a new Excel worksheet.
For formulas to show results, select them, press F2, and then press Enter. If you need to, you can
adjust the column widths to see all the data.

Property Value Commission

100000 7000

200000 14000

300000 21000

400000 28000

Formula Description Result

=AVERAGEIF(B2:B5,"<23000") Average of all commissions less than 23000. Three of the 14000
four commissions meet this condition, and their total is
42000.

=AVERAGEIF(A2:A5,"<250000") Average of all property values less than 250000. Two of the 150000
four property values meet this condition, and their total is
300000.

=AVERAGEIF(A2:A5,"<95000") Average of all property values less than 95000. Because #DIV/0!
there are 0 property values that meet this condition, the
Property Value Commission

AVERAGEIF function returns the #DIV/0! error because it


tries to divide by 0.

=AVERAGEIF(A2:A5,">250000",B2:B5) Average of all commissions with a property value greater 24500


than 250000. Two commissions meet this condition, and
their total is 49000.

Example 2

Region Profits (Thousands)

East 45678

West 23789

North -4789

South (New Office) 0

MidWest 9678

Formula Description Result

=AVERAGEIF(A2:A6,"=*West",B2:B6) Average of all profits for the West and MidWest 16733.5
regions.

=AVERAGEIF(A2:A6,"<>*(New Average of all profits for all regions excluding new 18589
Office)",B2:B6) offices.

Freeze panes to lock rows and columns


To keep an area of a worksheet visible while you scroll to another area of the worksheet, go to
the View tab, where you can Freeze Panes to lock specific rows and columns in place, or you
can Split panes to create separate windows of the same worksheet.
Freeze rows or columns
Freeze the first column
 Select View > Freeze Panes > Freeze First Column.
The faint line that appears between Column A and B shows that the first column is frozen.
Freeze the first two columns
1. Select the third column.
2. Select View > Freeze Panes > Freeze Panes.
Freeze columns and rows
1. Select the cell below the rows and to the right of the columns you want to keep visible
when you scroll.
2. Select View > Freeze Panes > Freeze Panes.
Unfreeze rows or columns
 On the View tab > Window > Unfreeze Panes.

Measures of central tendency


Measures of central tendency help you find the middle, or the average, of a dataset. The 3 most
common measures of central tendency are the mode, median, and mean.
 Mode: the most frequent value.
 Median: the middle number in an ordered dataset.
 Mean: the sum of all values divided by the total number of values.
What is the Mean in Excel
The Mean, also known as the Average, is a fundamental statistics measure that represents the
central tendency of datasets. The term “mean” refers to the average value of a set of numbers
when using Excel. It is a common method of obtaining the central value or concept of a set of
statistical data. To calculate mean in Excel, one adds up all the numbers present in a dataset and
divides them by the number of values in that dataset. There are several ways which can be can be
used in Excel to find mean and the easiest way is using the AVERAGE function which quickly
computes the average value of a range selected.
How to Calculate Mean in Excel
The Arithmetic mean, commonly known as the average is likely a familiar concept to you. This
measure is determined by summing a set of numbers and then dividing the total by the Count of
those numbers to calculate mean in Excel.
For example, the numbers {1,2,2,3,4,6}. To know how to calculate mean in Excel, you add these
numbers together and then divide the sum by 6, resulting in 3: (1+2+2+3+4+6)/6=3.
Step 1: Open MS Excel
Step 2: Select Data
Step 3: Enter AVERAGE Formula
Step 4: Press Enter
In Microsoft Excel, you can calculate the mean using one of the following functions:
AVERAGE: This Function returns the average of a range of numbers.
AVERAGE: This Function provides the average of cells containing various types of data,
including numbers, Boolean values, and text.
AVERAGEIF: When you need to find the average based on a single criterion, this function can
be used.
AVERAGEIFS: It can be used for calculating the average based on multiple criteria, you can
employ this function.
AVERAGE function in Excel
In this method, we are going to use the AVERAGE function which returns the mean of the
arguments. For example, the =AVERAGE(A1:A10) returns the average of the numbers in the
range of A1 to A10.
Syntax:
AVERAGE(number1,[number2],…)
Here,
 number1 (Required): The first cell reference or number for which you want the average
 number2 (optional): Additional cell references or numbers for which you want the
average. The maximum limit is 255.
Notes:
 Arguments can either be numbers or names, ranges, or cell references that contain
numbers.
 If the argument contains text or logical values or empty cells then those values are
ignored. However, if the cell contains the value zero then it is included.
 If the argument contains error values or text that cannot be translated to numbers then it
will cause errors.
 AVERAGE: This function returns the average of cells with any data (logical values or
text representation of numbers)
 AVERAGEIF: This function is used to calculate the average of only the values that meet
a single criterion.
 AVERAGEIFS: This function is used to calculate the average based on multiple criteria.
Example:
Let us apply the above formula on some rough data as shown below:

Functions to calculate Mean


In the above example, we have used 4 different functions.
 =AVERAGE(c4:e12): Returns the average of the numbers in cells c4 to e12
 =AVERAGE(c4:f6,6): Computes the average of the values in cells C4 to F6 along with
the number 6.
 =AVERAGE(b4:b12, “sara”, c4:c12): Calculates the average of the numbers in cells C4
to C12 by considering the instances where the name “Sara” appears within the range B4
to B12.
 =AVERAGE(d4:d12,b4:b12,”sara”,g4:g12,”b”): Determines the average of the
numbers in cells D4 to D12, taking into account two conditions: occurrences of the name
“Sara” within the range B4 to B12, and occurrences of the grade “B” within the range G4
What is Median in Excel
Median helps us to find the middle number in a bunch of numbers. It’s the number that sits right
in the middle when you put all the numbers in order from smallest to biggest. This middle
number divides the group into two halves, with half the numbers being smaller and half being
bigger.
In Microsoft Excel, you can find the median using the MEDIAN function. To illustrate, if you
want to determine the median of all the sales amounts in our report, apply this formula:
How to Calculate Median in Excel
Follow the below steps to calculate Median in Excel:
Step 1: Enter your data

Data Entered
Step 2: Select a Cell
Choose an empty cell within your worksheet where you’d like the median value to be displayed.

Cell Selected
Step 3: Use the MEDIAN Function
In the selected cell, type “=MEDIAN(“

Enter the MEDIAN Function


Step 4: Select Your Data Range
Now, select the range of cells that contain your data. In this example, you would select cells A1
to I1. You can either manually type this range or click and drag to select it.
Select the Data range
Step 5: Close the Parenthesis and Press Enter
Once you’ve chosen your data range and closed the parenthesis, press Enter. Excel will then
compute the median of the data you selected and show the result in your chosen cell.
Step 6: Preview the Result

Preview the Result


This method works well when dealing with an odd number of values in a dataset. However, what
if you have an even number of values? In such a scenario, the median is the average (arithmetic
mean) of the two middle values.
For example in the Below example, there are 10 values in the data set.

10 Values in the Dataset


Repeat all the steps as of above and preview the result in the Below image:

Preview the Result


What is Mode in Excel
The mode represents the number that appears most frequently within a given set of numbers. In
simpler terms, it’s the number that occurs the most times in the set is known as mode in Excel.
Here are the steps to calculate mode in Excel.
How to Find Mode in Excel
Among all the statistical measures, finding the mode is the simplest and requires the least
mathematical computation. Essentially, you identify the mode by locating the score that appears
most frequently in a dataset. Here are some steps on how to calculate mode in Excel.
Step 1: Enter the Data Set

Data Set
Step 2: Select the Cell where you want the result to be displayed

Select the cell and Enter the Formula


Step 3: Enter the Formula and Press Enter
Use the Formula “=MODE(A1:A9)”.
Step 4: Preview Result

Preview the Result

You might also like