首页 > 解决方案 > 如果范围内的单元格不为空,则在下面插入新行

问题描述

我有 B2:B60 范围内的数字和字母。

如果单元格 B2:B60 中有数据,我想在下面插入一行。

所以它看起来像:

   A B
1    e -> EntireRow.Insert below
2    
3    3 -> EntireRow.Insert below
4    a -> EntireRow.Insert below
5    
6    er -> EntireRow.Insert below
7    
8    w -> EntireRow.Insert below

我试过了:

Dim Rng As Range
For Each Rng In Range("B2:B60")
    If Is Not Empty (Rng.Value) Then
        Rng.Offset(1, 0).EntireRow.Insert
    End If
Next

标签: excelvba

解决方案


If Not IsEmpty

Option Explicit

Sub EmptyRows()

    Dim Rng As Range

    For Each Rng In Range("B2:B60")
        If Not IsEmpty(Rng) Then
            Rng.Offset(1, 0).EntireRow.Insert
        End If
    Next

End Sub

推荐阅读