Protected Learning Content

AICPE Gurukul content is created for learning purposes. Printing, copying and unauthorized reuse are restricted.

AICPE Learning Hub Advanced Excel
Chapter 32
Introduction to Macros
Chapter 32 | Excel Automation

Introduction to Macros

Transform repeated Excel work into reliable one-click actions. Learn how to plan, record, save, run, inspect and safely distribute macros before moving into full VBA programming.

Automate RepetitionRecord recurring formatting, cleaning, reporting and workbook actions.
Record CorrectlyChoose absolute or relative recording according to the required result.
Save and RunUse macro-enabled files, Personal.xlsb, shortcuts, buttons and the Macro dialog.
Use Macros SafelyRun only trusted code and follow responsible macro-security practices.
Advanced Excel • Chapter 32 of 40
Learning Objectives

After This Chapter, You Will Be Able To

Recognize suitable automation opportunities, record dependable macros, store them correctly, run them safely and understand the VBA code created by Excel.

Select Tasks

Identify stable, repetitive and rule-based Excel activities that are suitable for macro automation.

Record Actions

Use the Macro Recorder with correct names, storage locations and reference behaviour.

Deploy Macros

Run automation through the Macro dialog, shortcuts, shapes, buttons and Quick Access Toolbar.

Work Safely

Save macro-enabled files correctly and avoid enabling untrusted or unexplained code.

Macro Foundation

What Is an Excel Macro?

A macro is a stored set of instructions that Excel can run again to perform a sequence of actions automatically.

ObserveIdentify a repeated task with clear, stable steps and predictable inputs.
RecordLet Excel translate your actions into Visual Basic for Applications code.
TestRun the macro on a safe copy with different starting conditions and sample data.
DeployAssign an easy run method, document the purpose and control who can use it.

1 Suitable and Unsuitable Macro Tasks

Macros are most valuable when a task is repeated frequently, follows consistent rules and consumes unnecessary manual time. Examples include formatting a monthly report, importing a fixed data layout, preparing a print area, refreshing reports, creating headers or cleaning standardized fields.

Good Macro CandidateWhy It WorksUse Caution When
Apply the same report formatting every weekSteps and output are stableThe workbook layout changes frequently
Insert a standard title, date and footerActions are repeatableEach report needs different judgement
Clean imported columns with fixed rulesRules can be recorded or codedSource fields are inconsistent or unknown
Create a one-click print setupThe target sheet and print rules are knownUsers may accidentally print confidential information
Professional Tip: Do not automate a broken process. First simplify and standardize the manual workflow, then record or code it.

Practical Experiment 1: Find Three Automation Opportunities

Review your recent Excel work and identify tasks that could become repeatable macros.

Step 1: Observe

List five tasks you performed more than once during the last week or month.

Step 2: Score

Rate each task for repetition, rule stability, time consumed and risk of manual error.

Step 3: Select

Choose three tasks with stable steps and measurable time-saving potential.

Learning Output: A practical macro opportunity list based on real office work.

2 Prepare Excel for Macro Work

The Developer tab contains the main tools for recording, running, editing and securing VBA macros. It may be hidden in a new Excel installation, so learners should enable it before beginning.

1

Open Options

Choose File → Options.

2

Customize Ribbon

Open Customize Ribbon.

3

Enable Developer

Select Developer under Main Tabs.

4

Confirm

Click OK and verify the tab.

Essential Developer Tab Commands

CommandPurposeBeginner Use
Visual BasicOpens the Visual Basic EditorInspect or edit recorded code
MacrosLists available macrosRun, edit, delete or manage macros
Record MacroStarts recording user actionsCreate automation without writing code initially
Use Relative ReferencesChanges how cell movement is recordedBuild location-flexible macros
Macro SecurityOpens Trust Center macro settingsReview how Excel handles VBA content
Useful Shortcut: Press Alt + F8 to open the Macro dialog, and Alt + F11 to open the Visual Basic Editor.

Practical Experiment 2: Build a Safe Practice Environment

Create a separate workbook and sample dataset so macro experiments cannot damage important business files.

Step 1: Create

Make a workbook named Macro-Practice with Raw Data, Report and Notes sheets.

Step 2: Populate

Add a small sales table containing dates, regions, products, quantities and values.

Step 3: Preserve

Save an untouched backup before recording any macro.

Learning Output: A controlled sandbox for recording and testing macros.

3 Record Your First Macro

The Macro Recorder captures many actions exactly as you perform them and writes the corresponding VBA instructions. It is a powerful learning tool, but it also records inefficient selections, unnecessary scrolling and accidental clicks. Plan the steps before pressing Record.

1
PlanWrite the exact action sequence
2
StartDeveloper → Record Macro
3
ActPerform only required steps
4
StopStop Recording immediately
5
TestRun on a fresh sample

Record Macro Dialog

FieldProfessional GuidanceExample
Macro nameBegin with a letter; avoid spaces; use a descriptive action nameFormatMonthlyReport
Shortcut keyUse cautiously so you do not replace an important Excel shortcutCtrl+Shift+R
Store macro inSelect the workbook scope according to how and where the macro will be usedThis Workbook
DescriptionExplain purpose, target sheet, assumptions and ownerFormats the active monthly sales report
Recorder discipline: Every selection, click and formatting action can become code. Avoid exploratory actions while recording; stop, reset and record again if the sequence becomes unclear.

Practical Experiment 3: Record a Report Formatting Macro

Record a macro that turns a plain data range into a readable office report.

Step 1: Plan

List the required title, header formatting, borders, number format, column widths and freeze-pane action.

Step 2: Record

Name it FormatSalesReport and perform only the planned steps.

Step 3: Test

Apply it to a fresh copy of the same report layout and record any unwanted behaviour.

Learning Output: A working macro that applies standardized report formatting.

4 Absolute and Relative Macro Recording

The most important beginner decision is whether recorded cell actions should always affect the same address or should move relative to the active cell. Excel records absolute references by default unless Use Relative References is enabled.

Absolute Recording

Targets fixed addresses such as A1, B2 or a named worksheet. Use it when the macro must always update the same title, report area or control cell.

Relative Recording

Records movement from the starting cell. Use it when the macro should perform the same pattern wherever the user begins.

RequirementRecommended ModeReason
Format the fixed report heading in A1:H2AbsoluteThe target location never changes
Insert a subtotal two rows below the active recordRelativeThe target depends on the starting cell
Clear a fixed input form rangeAbsoluteThe input form has known addresses
Move one column right and apply a formulaRelativeThe same movement should work in different locations
Remember: Relative recording depends heavily on the active cell. Always document the required starting position and test from more than one location.

Practical Experiment 4: Compare Reference Modes

Record the same simple formatting action once with absolute references and once with relative references.

Step 1: Absolute

Record a macro that formats cell B3, then run it while another cell is active.

Step 2: Relative

Enable Use Relative References and record movement one cell right before applying formatting.

Step 3: Compare

Run both macros from three starting cells and document the difference.

Learning Output: Clear understanding of fixed-address and location-flexible automation.

5 Save and Store Macros Correctly

A macro stored inside a normal .xlsx workbook will not be preserved. Save the workbook as an Excel Macro-Enabled Workbook (.xlsm) when the file must retain VBA code.

Storage ChoiceAvailabilityBest Use
This WorkbookAvailable when that macro-enabled workbook is openAutomation belongs to a specific report or solution
New WorkbookStored in a newly created workbookSeparating a macro during development
Personal Macro WorkbookAvailable whenever desktop Excel starts for that userPersonal productivity tools used across many workbooks

Macro-Related File Types

.xlsx

Standard workbook format. It does not retain VBA macro code.

.xlsm

Macro-enabled workbook format for files that contain VBA projects.

Personal.xlsb

Hidden personal macro workbook used for macros that should be available across desktop Excel sessions.

Save warning: When Excel reports that VBA features cannot be saved in a macro-free workbook, do not ignore the message. Choose a macro-enabled format or preserve a separate code-free copy intentionally.

Practical Experiment 5: Test Macro Storage

Save the same practice solution in different formats and verify what happens to the macro.

Step 1: Save .xlsm

Save the workbook as a macro-enabled file, close it, reopen it and confirm the macro remains.

Step 2: Create Copy

Save a separate .xlsx copy and carefully read Excel's warning about VBA content.

Step 3: Document

Record which format should be used for the master automation file and recipient copies.

Learning Output: Correct understanding of macro storage and file-format consequences.

6 Run a Macro in Different Ways

A professional automation should have a run method appropriate for its audience. Developers may use the Macro dialog or Visual Basic Editor, while routine users may need a clearly labelled shape or button.

Macro Dialog

Press Alt+F8, select the macro and click Run. Best for testing and occasional use.

Shortcut Key

Useful for trained users, but it must not conflict with important Excel shortcuts.

Shape or Button

Provides an intuitive one-click action for forms, reports and operational workbooks.

VBA Editor

Place the cursor inside a procedure and run it during development or debugging.

Quick Access Toolbar

Add a frequently used personal macro for convenient access in desktop Excel.

Workbook Event

Advanced VBA can run from events, but this should be introduced only after understanding VBA fundamentals.

Before running: Verify the active workbook, worksheet, cell selection, input values and backup status. Many macros act immediately and may not support normal Undo.

Practical Experiment 6: Deploy Three Run Methods

Run the same formatting macro through three different interfaces.

Step 1: Dialog

Run it from Alt+F8 and observe the macro name and location.

Step 2: Shape

Insert a shape, label it Format Report and assign the macro.

Step 3: Shortcut

Assign a safe shortcut and document it in the workbook Notes sheet.

Learning Output: A user-friendly macro deployment plan.

7 Inspect Recorded VBA Code

Recording a macro creates VBA code in a standard module. Beginners do not need to understand every line immediately. Start by recognizing the procedure name, objects, properties, methods and the sequence of actions.

Example Recorded Macro
Sub FormatReport()
    'Format the active report heading
    Range("A1:H1").Select
    Selection.Font.Bold = True
    Selection.Interior.Color = RGB(6, 40, 95)
    Selection.Font.Color = RGB(255, 255, 255)
    Columns("A:H").AutoFit
End Sub

Read the Code in Layers

Code ElementMeaningExample
ProcedureThe named block that Excel can runSub FormatReport()
ObjectThe Excel item being controlledRange, Selection, Columns
PropertyA characteristic being read or changedFont.Bold, Interior.Color
MethodAn action performed by an objectSelect, AutoFit, ClearContents
CommentA note for humans, ignored by VBALine beginning with an apostrophe
Learning strategy: Record a very small action, inspect the code, change one setting, run it again and observe the result. The Macro Recorder becomes a practical bridge into VBA.

Practical Experiment 7: Make a Controlled Code Edit

Open the recorded macro and modify one visible formatting property.

Step 1: Open

Press Alt+F11, locate Modules and open the procedure.

Step 2: Edit

Change the bold setting, colour value or target range on a safe copy.

Step 3: Test

Run the macro and compare the result with the original version.

Learning Output: Confidence reading and safely adjusting simple recorded VBA.

8 Create a User-Friendly Macro Interface

A macro is more useful when the user knows exactly what it does, where it should be run and what result to expect. A labelled shape or Form Control button can turn code into a simple operational tool.

1

Insert

Add a shape or Form Control button.

2

Assign

Right-click and choose Assign Macro.

3

Label

Use an action phrase such as Refresh Report.

4

Guide

Add status, warning or starting-position instructions.

Button Design Rules

  • Use a clear verb: Format Report, Clear Input Form, Prepare PDF or Refresh Dashboard.
  • Do not use vague labels such as Run, Go or Click Here when the action changes data.
  • Place destructive actions away from routine actions and require confirmation in future VBA development.
  • Include a Notes or Instructions sheet listing macro names, purpose, owner, inputs and expected outputs.
  • Test the button after sheet protection and on the same Excel environment used by the learner or office.

Practical Experiment 8: Build a Mini Automation Panel

Create a simple control area for the practice workbook.

Step 1: Design

Create clearly labelled shapes for Format Report, Clear Practice Data and Go to Raw Data.

Step 2: Assign

Attach the available macros and add a short instruction beneath each button.

Step 3: User Test

Ask another person to use the panel without verbal help and record confusion points.

Learning Output: A clear, user-tested macro interface.

9 Macro Security and Platform Limitations

Macros contain executable code. They can automate valuable work, but malicious macros can also harm data or systems. Never enable a macro merely because the file looks familiar or arrived from a known contact.

Safer Practice

Use trusted internal sources, digitally signed code where required, controlled storage, antivirus protection and documented ownership.

Default Caution

Keep notification-based macro security so VBA content remains disabled until the user makes an informed decision.

Avoid

Do not enable all macros globally. Do not run unknown code, unexplained attachments or files from unverified download sources.

Important Current Platform Notes

Desktop Excel

VBA macros can be created, recorded, edited and run in supported desktop Excel versions.

Excel for the Web

A workbook containing VBA macros can be opened and edited, but VBA macros cannot be created, run or edited in the browser; use the desktop app.

Managed Organization

Macro settings may be controlled by IT policy, trusted locations, signed publishers or organizational security rules.

Trust decision: AICPE learners should enable macro content only when the file source, business purpose and code behaviour are understood and trusted. “Enable all macros” is not a safe routine setting.
Official learning references: Review Microsoft Support guidance for creating macros, running macros, saving macro-enabled workbooks and changing macro security settings before organizational deployment.
Interactive Macro Lab

Choose an Appropriate Macro Approach

Select the task characteristics to receive a practical recording and deployment recommendation.

Start here: Select the task, users and risk level to generate a responsible macro plan.
Real-Time Practical Assignment

Build a One-Click Monthly Report Formatter

Create a macro-enabled workbook that transforms a plain monthly sales report into a standardized management-ready output.

Project: Monthly Sales Report Automation

Your workbook should contain a Raw Report sheet, a formatted Report sheet, an Instructions sheet and a working macro interface.

Step 1: Prepare

Create a plain report with Date, Region, Executive, Product, Quantity, Sales and Collection columns.

Step 2: Plan

Write the exact formatting sequence: title, headers, number formats, borders, widths, freeze panes, filters and print setup.

Step 3: Record

Record FormatMonthlySalesReport using the appropriate reference mode and store it in This Workbook.

Step 4: Deploy

Create a clearly labelled button and add instructions describing the required starting sheet and expected output.

Step 5: Test

Run the macro on at least three fresh report copies, including one with more rows and one with fewer rows.

Step 6: Secure

Save as .xlsm, preserve a backup, document the macro source and review macro security before sharing.

Submission Output: A tested .xlsm workbook, macro button, Notes sheet, before-and-after screenshots, test log and a short statement of estimated monthly time saved.
AICPE Quality Learning Commitment: AICPE Gurukul focuses on practical, skill-based and career-oriented learning that helps learners build useful capabilities for employment, freelancing, self-employment and business improvement. Learn more at aicpeindia.org and aicpe.online.
Practice Worksheet

Macro Planning and Testing Tasks

Complete these tasks to create evidence of practical understanding and responsible automation behaviour.

1
Opportunity Audit

List five repeated Excel tasks and score them for frequency, rule stability, time saved and error risk.

Output:

Macro opportunity matrix

2
First Recording

Record a five-step formatting macro using a descriptive name and description.

Output:

Working recorded macro

3
Reference Comparison

Record one absolute and one relative macro, then run both from three starting positions.

Output:

Behaviour comparison table

4
Storage Test

Compare This Workbook, Personal Macro Workbook and macro-free file behaviour.

Output:

Storage decision note

5
Run Methods

Run one macro through Alt+F8, a shape and a safe keyboard shortcut.

Output:

Three verified interfaces

6
Code Reading

Highlight the procedure, objects, properties, methods and comments in recorded code.

Output:

Annotated VBA screenshot

7
Controlled Edit

Change one recorded formatting property and compare the result.

Output:

Before-and-after test

8
Risk Review

Write a checklist for deciding whether an incoming macro-enabled file should be trusted.

Output:

Macro security checklist

9
User Test

Ask another learner to run your macro using only the workbook instructions.

Output:

User feedback and corrections

10
Portfolio Note

Describe the manual process, automated steps, time saved, risks controlled and future VBA improvements.

Output:

One-page project summary

Macro works from a clean starting condition. It does not depend on accidental selections or temporary data.
Workbook is saved in the correct format. The .xlsm master file retains the VBA project.
User instructions are visible. Starting sheet, required inputs, result and risk are documented.
Security decision is responsible. Macros are not enabled globally or from unknown sources.
Common Mistakes

Mistakes Macro Beginners Should Avoid

Most early macro failures come from poor planning, uncontrolled recording, incorrect file formats or unsafe trust decisions.

Wrong Habits

  • Recording before writing the required step sequence
  • Including unnecessary selections, scrolling and corrections
  • Using a vague macro name such as Macro1
  • Choosing absolute recording for a location-flexible task
  • Saving the master file as .xlsx
  • Assigning shortcuts that replace useful Excel commands
  • Running a macro on important data without backup
  • Enabling content from an unknown or unexplained source

Correct Habits

  • Standardize the manual process before automation
  • Record only planned and required actions
  • Use descriptive action-based names and descriptions
  • Test absolute and relative behaviour deliberately
  • Preserve VBA in .xlsm or an appropriate macro-enabled format
  • Provide clear buttons, instructions and owner details
  • Test on safe copies and preserve original data
  • Trust code only after verifying source and purpose
Remember: A recorded macro repeats your actions, including your mistakes. Clean process design and disciplined testing are more important than recording speed.
Quick Quiz

Check Your Macro Fundamentals

Select the best answer for each question, then submit to view your score and explanations.

1. What is the primary purpose of an Excel macro?

A macro stores instructions that Excel can run again to automate repeated tasks.

2. Which tab contains Record Macro, Visual Basic and Macro Security?

The Developer tab provides the main Excel macro and VBA tools.

3. Which file format should normally be used to retain VBA macros in a workbook?

An Excel Macro-Enabled Workbook (.xlsm) preserves VBA code.

4. When is relative recording most useful?

Relative recording is designed for actions that should follow the same movement pattern from different starting locations.

5. Where should a personal macro be stored if it must be available whenever desktop Excel opens?

Personal.xlsb stores personal macros that can be available across desktop Excel workbooks for that user.

6. Which shortcut opens the Macro dialog?

Alt+F8 opens the Macro dialog; Alt+F11 opens the Visual Basic Editor.

7. What does the Macro Recorder create?

Excel converts many recorded actions into VBA code stored in a module.

8. What is the safest routine macro-security approach?

Macros should remain controlled and should be enabled only after the source and purpose are verified.

9. Which label is best for a button that applies report formatting?

A clear action-based label tells the user exactly what the macro will do.

10. Why should a macro be tested on a copy first?

A safe copy protects important data while the macro's assumptions and effects are being tested.

11. What can Excel for the web currently do with a workbook containing VBA macros?

VBA macro creation, execution and editing require the desktop app; the workbook itself can still be opened and edited on the web.

12. Which workflow is most professional?

Professional automation combines process planning, controlled recording, testing, documentation, correct storage and responsible security.
Quick Revision

Remember These Macro Principles

Revise these points before moving to VBA Fundamentals.

Automate Stable Work

Choose repeatable, rule-based tasks with clear inputs and outputs.

Plan Before Recording

Write the exact sequence and avoid unnecessary clicks or selections.

Choose References Carefully

Use absolute references for fixed locations and relative references for movable patterns.

Save in the Correct Format

Use .xlsm when the workbook must retain VBA code.

Test and Document

Use safe copies, varied test cases, instructions and a clear macro owner.

Trust Code Responsibly

Never enable unknown macros or use Enable All Macros as a routine setting.