VBA-excel在数据集中的每第n行插入一个新单元格

时间:2017-10-05 13:24:27

标签: excel excel-vba vba

我对VBA编码有非常基本的了解,并且迫切需要一些帮助。

我想在数据集的每第n行插入一个空单元格。

我发现以下VBA实现了类似的目标,我想知道是否有人想要调整链接或有类似的问题。

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

1 个答案:

答案 0 :(得分:1)

使用union方法。

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