Recording Macros
When we perform repetitive tasks in a workbook, the best
thing we can do is to record a macro so we can do our task much faster. In this
tutorial, we will record a macro that applies conditional formatting to a table of student grades.
Imagine we have multiple sheets with student grades, and we
want to mark in red all grades below 8.
We can go page by page formatting all cells, or we can do it
just once and record a macro to do it faster.
1
The first step is to select the grades range:
2
Now on the developer tab we can find the option “Record
Macro” on the upper left corner.
Click the button and a new window will pop out asking you to
input the following information:
Please note that you can create a shortcut to activate the
macro (in this case I’ll use Ctrl+d). Now click OK and you will see that the “Record
Macro” icon changes to a blue square that says “Stop Recording”.
3
Now let’s go to our Home tab, and click Conditional
Formatting->Highlight Cells Rules->Less Than
4
Select to format cells that are less than 8, with a light
red fill and dark red text. Click the OK button.
5
Now go to the developer tab and click on the “Stop Recording”
button.
6
Your macro will be saved automatically. Now go to another
sheet, select the grades and press Ctrl+d .
It will set the same conditional formatting.
7
To view the code of your recorded macro, just go to the developer
tab, and click the Macros icon at the top left corner. A window with all your
saved macros will appear.
Select the macro we just created and click the Edit button.
The VBA code will appear on a new window, where you can
modify any command directly from there.
No hay comentarios:
Publicar un comentario