How to Create Macro with VBA in Excel - Easy Guide

This function belongs to VBA, the Visual Basic for Applications version of Microsoft Office. The tasks you can perform with a macro range from copying formulas to a particular group of cells, to changing the color of a cell, to performing more complex calculation operations.

Crea una macro in VBA in Excel

The first thing to keep in mind when creating your first macro is that you need the Developer active tape to access VBA tools. Click the File menu and then click Options.




Under Excel Options, select Customize Ribbon and in the box on the right enable the Developer option. The Schedule option will appear automatically after pressing the Accept button.

Enable macros

reasons for safety , macros are disabled by default, to protect user safety and prevent malicious code execution. To activate them, you need to click on the Developer option on the ribbon.

  • Click on the option Macro Security.
  • Select the option Enable all macros.
  • Push the button OK to save the changes

How to Create Macro with VBA in Excel - Easy Guide

Create macro

The simplest way to create a macro is via the macro recorder. When activating the tool, it records all the actions we do in the Excel workbook and then replicates it.

If this is your first time creating a macro, it's the best option to get started as you don't need to know programming to do it. The disadvantage of using the macro recorder is that you can only record the actions you do directly on the sheet. If you want to create more complex macros, you should use VBA code.




  • To record a macro, click the Programmer option and select the Record Macro option.
  • Enter the macro name. Choose a name that clearly identifies the utility of the macro.
  • Choose a combination of shortcuts to run the macro. Try to use a combination that is not available to avoid errors in the macro.
  • Choose where you want save the macro and enter a description. If you save the macro in a personal folder you can use it with other Excel files.
  • Press the Accept button. The macro starts recording automatically and before the Record Macro option was found, Stop Macro is displayed.
  • Now take the necessary steps to perform a task on an Excel sheet. Delete text, change cell format, change font, etc.
  • When finished, press the button Stop Macro.

When you want to access the created macro, go to the Visual Basic tool located in the developer ribbon. All macros are added to Module1 of the project in question. From there you can change the steps of the macro, but the code it runs.




Run macro created

To run the macro you can do it from the shortcut link that you entered during creation. Use the key combination you selected (Ctrl + tasto) and the whole sequence of actions it has to do is performed in automatic mode.

How to Create Macro with VBA in Excel - Easy Guide

If you saved the macro without a link, run it from the Visual Basic tool. Open VBA and select the Macro option. A window opens with all the macros available, select the one you want and press the Run button to start it.

TagsEccellere
add a comment of How to Create Macro with VBA in Excel - Easy Guide
Comment sent successfully! We will review it in the next few hours.