Asger
Asger

Reputation: 1

VBA-excel inserting a new cell every nth row in a dataset

I have a very basic knowledge of VBA coding and am in dire need of some help.

I want to insert an empty cell every nth row in my data set.

I have found the following VBA which achieves a similar goal and i was wondering if anyone has an idea of tweaking the linked or have had a similar problem.

VBA Excel: Insert a new column every nth column filled with a formula which refrences the immediate column to the left

Upvotes: 0

Views: 1069

Answers (1)

Dy.Lee
Dy.Lee

Reputation: 7567

Use union method.

Sub insertRow()
    Dim rngU As Range, rng As Range
    Dim i As Long
    For i = 4 To 20 Step 3
        If rngU Is Nothing Then
            Set rngU = Range("a" & i)
        Else
            Set rngU = Union(rngU, Range("a" & i))
        End If
    Next i
    rngU.EntireRow.Insert
End Sub

Upvotes: 1

Related Questions