This tutorial will outline an approach to create a macro, which will enable users to insert rows across workbooks.

The following presentation is a follow-up to earlier videos on inserting rows:

We will base the following video on the following data sets.

The below video will showcase an approach to insert the same number of rows across all worksheets, across all open workbooks.

Creating the insert rows across workbooks macro

Go to Visual Basic for Applications, and insert a module. Whenever writing a customized macro in Excel, it’s advisable to notate your macro. As it will help future users of your macro will understand its purpose.

Let’s call this macro, insertRowSheetsWorkbooks

There are a few important best practices with composing your own macro in Excel:

  • Disabling Excel properties. As it will improve the macro’s performance and efficiency.
  • Declaring object variables. This will mean you can change the value of a variable within the code. As well as continue to use that variable in the code.
  • Error handling code. It will prevent run-time errors caused by the erroneous use of the macro by users.

The iCountRows variable will quantify the number of rows to insert across the worksheets and workbooks. The macro contains two loops.

The first loop will enable the macro to move from open workbook to open workbook. Whilst the second loop will cycle through the worksheets for each respective workbook.

The macro to insert rows across workbooks contains two loops. One to loop through the workbooks. Whilst another to loop through the worksheets for each individual workbooks.

Using the macro

Make sure to write the entire code accurately, because otherwise the macro may not execute properly. Remember to review the macro one final time. Then it is time to trial the macro in our open Excel application.

In summary, here are the example workbooks which the video showcased, in order to compose the macro.