VBA code to add blank lines to data

Excelpromax123

Board Regular
Joined
Sep 2, 2021
Messages
167
Office Version
  1. 2010
Platform
  1. Windows
Hello everyone. I have a table of data stored in groups (about 100 groups). 1 group consists of 3 columns and 5 rows. Now I want a group to increment by 2 rows. my data involves a lot of formulas so i can't insert blank lines manually. I need the code to do that. Sincerely thank ( The image below I framed for easy understanding. But I don't need to frame )

1634126167004.png
 
Last edited:

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Have a try with my macro to be copied into a standard module and adjust sheet name and ranges:
VBA Code:
Option Explicit
Sub InsertRows()
    Dim lr     As Long
    Dim x      As Long
    Dim y      As Long
    Application.ScreenUpdating = False
    With ThisWorkbook.Worksheets("Foglio1")       'adjust sheet name as suited
        lr = .Range("B" & Rows.Count).End(xlUp).Row 'find last row of groups
        For x = lr To 6 Step -5                   'loop to first row of first group from last row
            With .Range("B" & x & ":D" & x)       'applies to columns B to D
                For y = 1 To 2                    'add 2 rows and copy/paste formulas
                    .Cells.Copy
                    .Cells.Insert Shift:=xlDown
                Next y
                Application.CutCopyMode = False
            End With
        Next x
    End With
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Solution
Thanks for the positive feedback, glad having been of some help(y).
 
Upvote 0

Forum statistics

Threads
1,214,999
Messages
6,122,645
Members
449,093
Latest member
Ahmad123098

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top