Now that you know how macros work, try to write your own macro. We have a table and need to color the alternate table rows (odd will be colored green, even will become red). The table contains 200 rows and columns from A to S. It would take a lot of time to do that manually. So, using macros will be the best solution for this problem.
(function() { // ... your code goes here ... })();
var oWorksheet = Api.GetActiveSheet();
for (var i = 1; i < 200; i += 2) { }
var rowOdd = i, rowEven = i + 1;
oWorksheet.GetRange("A" + rowOdd + ":S" + rowOdd).SetFillColor(Api.CreateColorFromRGB(138, 181, 155));The same is for the even rows, but with a different color:
oWorksheet.GetRange("A" + rowEven + ":S" + rowEven).SetFillColor(Api.CreateColorFromRGB(216, 227, 220));
Now let's sum it up with the complete script code:
(function() { var oWorksheet = Api.GetActiveSheet(); for (var i = 1; i < 200; i += 2) { var rowOdd = i, rowEven = i + 1; oWorksheet.GetRange("A" + rowOdd + ":S" + rowOdd).SetFillColor(Api.CreateColorFromRGB(138, 181, 155)); oWorksheet.GetRange("A" + rowEven + ":S" + rowEven).SetFillColor(Api.CreateColorFromRGB(216, 227, 220)); } })();
Paste the code above to the macros window and click Run. The table rows from 1 to 200 will be colored alternately in less than a second.
In the spreadsheet editor, you can assign a macro to the graphic object:
To run the macro, just click the graphic object and the script will be executed.