In this article, we will learn how to insert the row after every 5th row through VBA in Microsoft Excel.
Let’s take an example and understand:
We have data in range A1:F31, in which column A contains Name, column B contains Street address, column C City, column D contains region, column E contains country name, and column F contains phone number.
We want to insert the row after every fifth row in the data, follow below given steps and code:
Sub InsertIT() x = 2 'Start Row Do Range("A" & x, "F" & x).Insert x = x + 5 Loop While x < 50 End Sub
First, we have defined the row number from where we want to insert the row. Then we have defined the range to insert the data. And, then we have defined the number to insert the row after how many rows. And then till which row, rows will be inserted.
To run the code press the key F5 on your keyboard.
In this way, we can insert row after specific number which we can define in macro.
We would love to hear from you, do let us know how we can improve, complement or innovate our work and make it better for you. Write us at email@example.com
The applications/code on this site are distributed as is and without warranties or liability. In no event shall the owner of the copyrights, or the authors of the applications/code be liable for any loss of profit, any problems or any damage resulting from the use or evaluation of the applications/code.