Page 227 - CITS - Computer Software Application -TT
P. 227
COMPUTER SOFTWARE APPLICATION - CITS
How to create, change, copy and delete macros
This tutorial will set you on your way to learning Excel macros. You will find how to record a macro and insert
VBA code in Excel, copy macros from one workbook to another, enable and disable them, view the code, make
changes, and a lot more.
For Excel newbies, the concept of macros often looks insurmountable. Indeed, it may take months or even years
of training to master VBA. However, this does not mean you cannot take advantage of the automation power of
Excel macros right away. Even if you are a complete novice in VBA programming, you can easily record a macro
to automate some of your repetitive tasks.
This article your entry point to the fascinating world of Excel macros. It covers the essential basics that you need
to know to get started and provides links to the related in-depth tutorials.
What are macros in Excel?
Excel macro is a set of commands or instructions stored in a workbook in the form of VBA code. You can think of it
as a small program to perform a predefined sequence of actions. Once created, macros can be re-used anytime.
Running a macro executes the commands it contains.
Typically, macros are used to automate repetitive tasks and daily routines. Skilled VBA developers can write really
sophisticated macros that go well beyond reducing the number of keystrokes.
Quite often, you may hear people referring to a "macro" as "VBA". Technically, there is a distinction: a macro is
a piece of code while Visual Basic for Applications (VBA) is the programming language created by Microsoft to
write macros.
Why use Excel macros?
The main purpose of macros is to have more work done in less time. Like you use formulas to crunch numbers
and manipulate text strings, you can use macros to perform frequent tasks automatically.
Let's say, you are to create a weekly report for your supervisor. For this, you import various analytics data from a
couple or more external resources. The problem is that those data are messy, superfluous, or not in the format that
Excel can understand. That means you need to reformat dates and numbers, trim extra spaces and delete blanks,
copy and paste information into appropriate columns, build charts to visualize trends, and do a lot more different
things to make your report clear and user-friendly. Now, imaging that all these operations can be performed for
you instantly in a mouse click!
Of course, building a complex macro takes time. Sometimes, it can take even more time than performing the
same manipulations manually. But creating a macro is a onetime set-up. Once written, debugged and tested, VBA
code will do the job quickly and flawlessly, minimizing human errors and costly mistakes.
How to create a macro in Excel
There are two ways to create macros in Excel - by using the Macro Recorder and Visual Basic Editor.
Tip. Within Excel, most operations with macros are done via the Developer tab, so be sure to add Developer tab
to your Excel ribbon.
Recording a macro
Even if you don't know anything about programing in general and VBA in particular, you can easily automate
some of your work just by letting Excel record your actions as a macro. While you are performing the steps, Excel
closely watches and writes down your mouse clicks and keystrokes in the VBA language.
The Macro Recorder captures nearly everything that you do and produces a very detailed (often redundant) code.
After you've stopped the recording and saved the macro, you can view its code in the Visual Basic Editor and
make small changes. When you run the macro, Excel goes back to the recorded VBA code and executes the
exact same moves.
To start recording, click the Record Macro button on either the Developer tab or the Status bar.
214
CITS : IT&ITES - Computer Software Application - Lesson 63 - 77