Lesson 15 of 60 – Recording Formula Macros
25%

Recording Formula Macros

Excel formulas are used to perform calculations automatically. When the same formula-related task is performed repeatedly, you can use the Macro Recorder to record the actions and repeat them automatically.

Note: In this lesson, you will learn how to record macros that enter formulas, copy formulas, and perform repeated calculation tasks in Excel.

1. What is a Formula?

A formula is an expression used in Excel to perform a calculation.

For example:

=A1+B1

This formula adds the values stored in cells A1 and B1.

2. Why Record Formula Actions?

Sometimes the same formula needs to be entered repeatedly in different worksheets or reports.

Instead of performing the same actions manually, a macro can record the process and repeat it.

3. Example of a Repetitive Formula Task

Suppose a student marksheet contains marks in columns B, C, D, E and F. You want to calculate the total in column G.

=SUM(B2:F2)

If many reports use the same calculation, recording a macro can help automate the process.

4. Prepare Sample Data

Create sample student marks in Excel:

A          B     C     D     E     F
Name       Hindi English Math  Science Computer
Rahul      70    75      80    72      85
Amit       65    70      76    68      74

You can use this data to practice recording a formula macro.

5. Open the Developer Tab

The Macro Recorder is available from the Developer tab.

Click Developer on the Excel Ribbon.

If the Developer tab is not visible, enable it from Excel Options.

6. Start Recording the Formula Macro

Click:

Developer → Record Macro

Enter a meaningful name such as:

CalculateTotal

Click OK to start recording.

7. Enter a Formula

After recording starts, select the cell where you want the result.

For example, select G2 and enter:

=SUM(B2:F2)

Press Enter.

This formula calculates the total marks of the first student.

8. Copy the Formula

After entering the formula, you can copy it to another row.

For example, copy the formula from G2 to G3.

G2 → Copy → G3 → Paste

The recorded macro can include these actions.

9. Relative Cell References

When you copy a formula, Excel normally adjusts relative cell references.

For example:

G2: =SUM(B2:F2)

Copied to G3:

G3: =SUM(B3:F3)

This behavior is important when working with formulas in multiple rows.

10. Using the Fill Handle

Instead of copying and pasting manually, you can use Excel's fill handle to copy a formula down a column.

For example, drag the formula from G2 down to G10.

The recorded actions can become part of the macro.

11. Calculating Percentage

A macro can also record the process of entering a percentage formula.

For example, if the total marks are in G2 and the maximum marks are 500:

=G2/500*100

This calculates the student's percentage.

12. Calculating Average

You can record a macro that enters an average formula.

For example:

=AVERAGE(B2:F2)

This calculates the average of the five subject marks.

13. Calculating Maximum Value

The MAX function returns the largest value from a range.

Example:

=MAX(B2:F2)

A macro can record the process of entering and copying this formula.

14. Calculating Minimum Value

The MIN function returns the smallest value from a range.

Example:

=MIN(B2:F2)

This can also be included in a recorded formula workflow.

15. Recording Multiple Formulas

A single macro can record multiple formula-related actions.

For example, you can calculate:

  • Total
  • Percentage
  • Average
  • Highest marks
  • Lowest marks

All of these actions can be recorded during one macro session.

16. Stop Recording

After completing the formula operations, stop the Macro Recorder.

Developer → Stop Recording

The formula actions are now stored in the macro.

17. Run the Formula Macro

To run the recorded macro:

Developer → Macros

Select the formula macro and click Run.

Excel will repeat the recorded formula-related actions.

18. Viewing Formula VBA Code

The Macro Recorder creates VBA code for the actions you perform.

Open the VBA Editor using:

Developer → Visual Basic

Then open the module containing your recorded macro.

19. Example of Recorded Formula Code

A recorded formula operation may create code similar to:

Range("G2").Select
ActiveCell.Formula = "=SUM(B2:F2)"

The exact generated code can vary depending on how the formula was entered and recorded.

20. Copying a Formula to Multiple Rows

One common formula task is copying a formula down many rows.

For example:

G2 = SUM(B2:F2)
G3 = SUM(B3:F3)
G4 = SUM(B4:F4)
G5 = SUM(B5:F5)

A recorded macro can automate the repeated copy operation.

21. Formula Macros for Student Marksheets

Formula macros are useful when creating student marksheets.

A macro can help automate calculations such as:

  • Total marks
  • Percentage
  • Average marks
  • Highest marks
  • Lowest marks

This can reduce repetitive calculation work.

22. Formula Macros for Reports

Formula macros can also be useful for preparing reports.

For example, a monthly report may require totals, averages, or percentages to be calculated repeatedly.

A macro can record these repeated actions.

23. Limitation of Recorded Formula Macros

A recorded formula macro generally records the specific cells and actions used during recording.

If the worksheet structure changes significantly, the recorded macro may not work as expected.

For more flexible calculations, VBA programming can be used.

24. Formula Macros and Dynamic Data

When the number of rows changes regularly, a fixed recorded range may not always be suitable.

For example, today's data may contain 20 students while tomorrow's data may contain 50 students.

VBA can later be used to identify the changing data range automatically.

25. Practical Marksheet Example

Suppose marks are stored in B2:F10. You want to calculate totals in column G and percentages in column H.

Total:
=SUM(B2:F2)

Percentage:
=G2/500*100

You can record the process of entering and copying these formulas.

26. Best Practices for Formula Macros

While recording formula macros:

  • Use meaningful macro names.
  • Prepare your worksheet before recording.
  • Use correct formulas.
  • Check cell references carefully.
  • Test the macro after recording.
  • Save the workbook as an .xlsm file.

27. Formula Macro Workflow

A basic workflow is:

Prepare Data
     ↓
Developer Tab
     ↓
Record Macro
     ↓
Enter Formula
     ↓
Copy Formula
     ↓
Perform Calculations
     ↓
Stop Recording
     ↓
Run Macro

28. Recorded Formula Macro vs VBA

The Macro Recorder is useful for simple and repetitive formula tasks.

VBA becomes more useful when you need conditions, loops, dynamic ranges, variables, or more complex calculations.

Learning recorded formula macros gives beginners practical experience before moving to advanced VBA programming.

29. Practical Exercise

Try this exercise:

  1. Create a student marksheet.
  2. Enter marks for five subjects.
  3. Start recording a macro.
  4. Enter a SUM formula for total marks.
  5. Enter a percentage formula.
  6. Copy the formulas to additional rows.
  7. Stop recording.
  8. Clear the calculated results.
  9. Run the macro.
  10. Check the calculated results.

30. Complete Understanding of Formula Macros

A formula macro records repetitive formula-related actions in Excel. It can help enter formulas, copy formulas, and repeat calculation steps.

The Macro Recorder is a simple way for beginners to understand how Excel automation can work. Later, VBA can be used to create more flexible and dynamic formula automation.

Formula → Record → Repeat → Automate

📌 Key Points

  • A formula performs calculations in Excel.
  • The Macro Recorder can record formula-related actions.
  • Formulas such as SUM, AVERAGE, MAX and MIN can be used in recorded workflows.
  • Relative references change when formulas are copied to other rows.
  • A macro can automate repeated formula entry and copying.
  • Recorded formula macros are useful for repetitive reports and marksheets.
  • VBA can provide more flexibility for dynamic formula automation.

🧠 Quick Quiz

Question: Which formula is commonly used to calculate the total of cells B2 to F2?