

Click on it or press ALT+ F11 to go to VBA.īelow we will discuss the examples of Excel Macro Example #1 – Write a Program to get Text Hello To get into VBA, click on the Developer tab and the left-hand side, and you will see the first option, “Visual Basic”. Sometimes we have to write macros as per our requirements in VBA. We cannot always record macros because they have a limited scope. It can’t be saved as a normal Excel file. We can only save the files with macros as Excel Macro-Enabled Template (file type).
#Excel macro sample how to#
Method 3 – How to Save a File with Macro? Now click the button, and the macro will work.

Then click on OK.Īnd drag the mouse to outline/create a button, and rename it to “Data”. Once you click on the Command Button, you can then assign the macro as shown below. Then from Active X Controls, select the Command Button. Go to the Developer tab and click on the Insert tab. If you want to paste the data in sheet 2, just go to sheet 2 and press Ctrl+V or view macros. Click it to see the Macro window where you can select “Macro11” and click Run. The macro “Macro11” is stored on the Macros button. Now go to Macros and click on Stop Recording. Click on OK, and the macro will start recording. We will then store the macro in “This Workbook”. Then we will assign a shortcut key to run the macro I assign CTRL+V. Ensure there should be no space and special characters in it. In our example, we will create/record a table of companies and their sales.Ĭlick on Record Macros to see the below window pop up. Now, click on the Macros tab to find the Record Macro option.Ĭlick on it to record whatever you want, be it writing or copying and pasting something. To begin, click the View button on the tab, then move to the right-hand side, and you will see the “Macros” tab, as shown below. We will record the name of companies and their sales. Let’s take the example of recording a Macro. Once the Macro is recorded, we can run it, and our work will be done. We can record a task that we use daily or which is repetitive.

We can record a macro and use it any number of times. Method 2 – Creating Macros using Record Button You will see the Developer tab on the ribbon. Select the Developer (Custom) option and then press OK.
