We have recently been learning how to activate the Developer tab in Excel , but today we are going to go one step further to learn how to create a macro in the program, a very interesting option to automate tasks .
Article Content
- what is a macro
- Steps to create a macro with Excel
- Create a button to associate the macro
- Create a macro in Excel
- Assign a macro
what is a macro
Macro is the abbreviation for macroinstruction , and it is nothing more than a series of instructions that are memorized and assigned to a specific control that allows us to carry out an action quickly and easily.
For example, a simple option that will allow us to understand the function of macros would be if, for example, we have to color certain boxes with a certain frequency, while changing the color of the font.
Carrying out this action a couple of times may not require much effort, but what if you have to carry out the task hundreds of times?… things get complicated.
For this reason, we are going to learn to create a button through which, just by pressing it, we will carry out this action in the chosen box or group of boxes .
But to avoid getting involved, we are going to go directly to the practical case.
Steps to create a macro with Excel
Well, let’s get to work. We open Excel and, in case we don’t have it, it is interesting to activate the Developer tab as we explained in the previous article . I remind you of the path: File / Options / Customize Ribbon.
Create a button to associate the macro
Ok, now we are going to create a button that we will assign the macro to . We can do this before or after creating said macro, as we like.
To do this we enter Programmer and click on Insert . From the list that is displayed, we choose, for example, the rectangle that appears in Form controls .
Then we click on any area of the document and a window like this will appear. Since we haven’t created the macro yet, we don’t have anything to assign, so we cancel and continue.
Now we will see the button already created. If we click on it we can move it, resize it, change its name, and even format it so that it has a less bland appearance. We’ve left it as is (we’ll learn how to make these changes a bit later) and entered the name of your favorite tech page .
Create a macro in Excel
Now we can go on to create the macro , and to do this we select any box in the document, go back to the Developer tab and click on the “ Record macro ” button (we can also click on the icon at the bottom of the whole, but today we are not going to mess).
Now, all the actions that we carry out will be memorized in the macro, so we must be careful and go step by step. In our case, what we will do is color the box dark red and put the white text.
When pressing the Record macro button, a window like the following appears:
We have to give the macro a name (no spaces or signs can be used ), we can choose a key combination to activate the macro (instead of assigning it to the button), choose where we want to save the macro and add a description.
By accepting , the recording will start , and in our case we will only go to the Start tab, select the dark red color and the white text color. Now we click on the square that we will see in the lower bar of Excel with which the recording will end (we can also end from the Programmer tab ).
To reset everything to zero, we remove the color from the cell that has been colored and select the black text.
Assign a macro
To finish we will only have to click with the right mouse button on the button that we created at the beginning and click on Assign macro . Now we select the macro and accept.
Let’s go to box B2 (for example) and write any text:
Now we select that box and press the button:
And voila, we are done. We can also select several boxes and perform the action at the same time. If you have questions or problems, do not hesitate to ask what is needed