How To Write Macros In Excel

Table of contents:

How To Write Macros In Excel
How To Write Macros In Excel
Anonim

Do you work in Microsoft Excel every day and do the same things? You can automate your routine work by recording a macro - a short program code. It will automatically replay your actions in Excel when you click a button or open a workbook. The advantage of macros is that you do not need to know the programming language, and the disadvantage is that you can not record all your actions (only mouse clicks and keystrokes), and in some cases you need to edit the code manually.

Excel macros make your work easier
Excel macros make your work easier

Instructions

Step 1

Start Excel of any version (2003, 2007, 2010, or 2013). The number and location of work tabs on the work ribbon in recent versions, starting with Excel 2007, are approximately the same. On the "View" tab, find the "Macros" menu item.

Image
Image

Step 2

Click on the arrow button to expand the drop-down menu. Click on the "Record Macro" item. The macro recording window will open. Enter its name, for example, "How Simple." In the Shortcut Keys field, you can enter the name of the key, for example, Y. Then the recorded macro will run when you press the Ctrl and Y keys at the same time.

Image
Image

Step 3

You can save the macro to this workbook. But then you will not be able to run it in other files if this file is not opened in Excel. When you write to your personal macro book, you can use the macro in any workbook on your computer.

Step 4

Enter a description for the macro so you don't forget what it can do. After pressing the "OK" button, its recording will start.

Step 5

Enter the text "How easy it is to record a macro in Excel!" In cell A1. Format it to your liking.

Image
Image

Step 6

To stop recording, go back to the View tab, open the Macros drop-down menu and click Stop Recording.

Step 7

Delete the cell with the created caption, go to the Macros menu or use the keyboard shortcut alt="Image" + F8. Select the AsEasy macro and click the Run button.

Image
Image

Step 8

Cell A1 will display the text "How easy it is to record a macro in Excel!", Formatted according to your sample. If you need the text to be created in any cell selected by the cursor, then before recording, click on the "Relative links" item in the "Macros" menu.

Step 9

To edit or delete a macro, select it and click the Edit or Delete button. To change the macro code, the editor will open (you can also call it with the keyboard shortcut alt="Image" + F11). To edit a macro, you need to know the Visual Basic for Applications (VBA) programming language.

Step 10

If you decide to save the macro in the current workbook, you will need to save it in.xlsm format (Excel workbook with macro support).

Step 11

If in the future you want to use macros and study them in more detail, it will be more convenient for you to work with the developer panel. You can connect it in the Excel options on the "Customize the Ribbon" tab.

Recommended: