Microsoft Office Tutorials and References
In Depth Information
Add a Macro to a Module
Add a Macro
to a Module
If you have a macro that you want to create or
copy, you need to add the VBA code for the
macro to a module in the VBA Editor.
As you become familiar with manipulating
Excel using VBA, you will likely come up with
many ways to simplify complex tasks and
automate routine and repetitive chores using
macros. To implement these macros, you need
to type your code into an existing module in
the VBA Editor.
Similarly, you may run across a macro that you
want to use for your own work, either as it is
or by modifying the code to suit your needs.
You can either transcribe these macros into a
module on your system, or better yet, copy the
macros and then paste them into a module.
1 Start the VBA Editor.
Note: For more information, see
the section, “Open the VBA Editor.”
2 Double-click the module
into which you want to
add the macro.
If you prefer to add your
code to a new module,
you can click Insert and
then click Module,
Excel opens the module
3 Position the cursor where
you want to start the new
Note: You must add the new macro
either before or after an existing