Macro recorder is Excel built-in tool to convert you excel actions into VBA code. Macro recorder is a powerful and useful tool, but it has some limitations:
- The macro recorder can’t record complex actions.
- Macro recorder can’t generate code that performs looping, conditional statement, and so on.
In this example we will record a macro that will merge selected cells. To record the macro follow these steps:
- Open a new blank workbook.
- On any worksheet, select cells from A3 to C3.
- Click Tools –> Macro -> Record New Macro...
- In the Record Macro dialog box, type “SubMergeCells” in Macro name textbox to set the macro name. Then click Ok.
- In the formatting toolbars, click Merge and Center button. This action will merge cells from A3 to C3.
- To stop recording macro, click the Stop button.
Run the recorded macro
To execute the recorded macro, follow these steps:
- On any worksheet, select cells from D4 to G4.
- Click Tools -> Macro -> Macros... or press Alt+F8.
- In the Macro dailog box, select “SubMergeCells”. Click the Run botton to run the macro.
- Cells D4 to G4 now have been merged.