Excel Notes Part3
Excel Notes Part3
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.
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:
100000 7000
200000 14000
300000 21000
400000 28000
=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
Example 2
East 45678
West 23789
North -4789
MidWest 9678
=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.
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(“
Data Set
Step 2: Select the Cell where you want the result to be displayed