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

Vba Excel 2010 2013 and 2016 Tutorial pdf.300

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
342 views

Vba Excel 2010 2013 and 2016 Tutorial pdf.300

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

IT Training

Unit name goes here

Microsoft Excel 2013™


Macros (Level 3)
Contents
Introduction 1
Absolute and Relative References 1
Using Absolute References 2
Using Relative References 4
Editing a Macro 5
Repeating an Action 6
Using Variables 6
Running a Macro from a Toolbar Button or Control 7
Controls 8
Changing a Shortcut Key 8
Deleting a Macro 8
Saving an Excel Workbook with Macros 9
Setting Macro Security Levels 9

Introduction
A macro is a series of instructions which can be issued using a single command. The
macro can be invoked in various different ways - from the keyboard (using a Control key
combination), from a special icon on a toolbar or through the menu system. Ideally, you
need to know a programming language (Microsoft Visual Basic) to create really useful
macros; the examples below give you an introduction to macro writing.

Absolute and Relative References


Whenever you write a macro you have the option of using absolute or relative cell referencing. If you
want to perform instructions on specific cells (e.g. move to cell A14, calculate the sum of the values
above and format the result to appear as a currency in bold), then you use an absolute reference. If you
want to move to a cell a certain number of rows/columns away from your present position (wherever
that may be) then you use a relative reference. Hopefully the examples below will make this clear. First,
open up the example file and set it up ready for use - users off campus can download the file by clicking
on the filename in Step 1, below:
Microsoft Excel 2013 Macros
1. Load up Excel, click on Open Other Workbooks then computer and [Browse] to the file called
phoenix.xlsx in the D:\Training folder
2. Next, move to the FILE tab then click on Options
3. Click on Customize Ribbon and tick the box next to Developer in the Main Tabs box on the right.
Click on [OK] to show the DEVELOPER tab at the top of your Excel window. You’ll need the
buttons on this tab later (though you can also use a [Macros] button on the far right of the VIEW
tab)

Using Absolute References


In this first example you are going to write a macro that adds up the values in columns A to E and applies
a bold format to the totals.
1. Move to the DEVELOPER tab and click on the [Record Macro] button – a dialog box appears:

2. Set the Macro name: as Sum and the Shortcut key: to Ctrl+ S (i.e. press <Shift> + s to give an
uppercase S)
Note that case matters - avoid existing key combinations: <Ctrl s> is currently set to the Save
command.
3. Store macro in: This Workbook - the alternative is to store it in your Personal Macro Workbook,
which would make the macro available every time you used Excel
4. Amend the Description: if you like (use this to say what the macro does & who recorded it)
5. Press <Enter> or click on [OK] to start recording
You now need to carry out the keystrokes required:
6. Press <Ctrl Home> (or click on A1) to make sure the macro starts in cell A1
7. Hold down <Ctrl> and press <down arrow> to move the active cell to the end of column A
8. Release <Ctrl> then press <down arrow> once more to move to cell A52
9. Press <Alt => (or click on the [AutoSum] button on the HOME tab) then press <Ctrl Enter> to
confirm the formula =SUM(A2:A51) and stay in cell A52
10. Next, press <Ctrl b> (or click on the [Bold] button) to embolden the result
11. Click on the green square in the bottom right-hand corner of cell A52 and drag the formula in
A52 across to E52 to automatically fill the totals for all the columns (these may be rounded up)
12. Click on the DEVELOPER tab then on [Stop Recording] to end the macro
You should now have a macro which sums up the values in column A. Test out the macro as follows:
13. First, press <Delete> to empty the cells A52 to E52
14. Hold down the <Ctrl> and <Shift> keys together and type the letter s - the sums appear again in
bold characters in cells A52 to E52
Microsoft Excel 2013 Macros

To demonstrate what is meant by Absolute Referencing:


15. Select rows 51 and 52 then press <Ctrl c> for [Copy]
16. Right click on cell A54 and under Paste Options… choose Values (the second icon shown as
123)
17. Select rows 51 and 52 again and <Delete> the contents – click on any cell to release the
selection
18. Run the macro again (<Ctrl Shift s>) - you'll find that the totals appear in the same cells based on
the same data range (including the empty row 51), with the new total differing from that in row
55
19. Press <Delete> to remove the incorrect values
20. Select row 54 and drag the border of the selection to row 51 to reset the data for sample 50. If a
message saying that We couldn’t free up space on the Clipboard appears, just click [OK]
21. Select row 55 and <Delete> the contents (these were the values from the sums pasted earlier)
This is a clear example of absolute references - the macro only works on the cells for which it was
recorded. Even though a control key combination was used to move to the foot of the column, the next
move (to cell A52 in step 8) was recorded as a move to a fixed cell.
In this second example, absolute references are left turned on but this does not affect the result. The
object of this macro is to search for Blue-Green eggs and highlight the cells in an appropriate colour.
1. Press <Ctrl Home> to move to cell A1
2. On the DEVELOPER tab click on the [Record Macro] button
3. Set the Macro name: as Colour and the Shortcut key: to Ctrl+ C (i.e. press <Shift> + c - <Ctrl c>
is for copy)
4. Store Macro in: This Workbook and amend the Description: if you want
5. Press <Enter> or click on [OK] to start recording
6. Press <Ctrl f> (or move to the HOME tab and click on [Find & Select] then choose Find…)
7. In the Find what: box type Blue-Green
8. Press <Enter> or click on [Find Next]
9. Press <Esc> or click on the [Close] button to close the Find window
10. Right click on the cell found then use the list arrow attached to the [Fill Colour] button (it looks
like paint coming out of a bucket)
11. Choose a suitable colour from the palette - e.g. Green
12. Click on the [Stop Recording] button on the DEVELOPER tab to end the macro
You should now have a macro which colours Blue-Green cells a suitable colour. Test out the macro by
pressing the appropriate key combination:
13. Hold down the <Ctrl> and <Shift> keys and type the letter c - repeat this a couple of times
The macro works from the active cell downwards, moving to the next blue-green cell rather than to a
fixed cell. To demonstrate this further:
14. Move the active cell down several rows, missing out some Blue-Green cells
15. Hold down <Ctrl> and <Shift> and type the letter c
You will see later how to edit the macro to colour all the Blue-Green cells, including those which were
skipped.
End of ebook preview
Download the full PDF tutorial from the link below :

Click Here

You might also like