当值更改时,VBA仅在可见的单元格中在D列中添加空白行


0

我希望我的VBA代码在d列中的单元格值更改时插入两个空白行。而且由于我使用了一些自动过滤器,所以我只希望它在可见的单元格上执行此功能。

我有这个:

Dim GCell As Range

SearchText = ""
Set GCell = Cells.Find(SearchText).Offset(0)
GCell.EntireRow.Insert
GCell.EntireRow.Insert

但是,仅当您输入要搜索的特定文本时,它才有效。但是这里我没有要搜索的特定内容。这只是数字

Answers:


0

如果您想将行插入更改后的值下方,而不管更改了什么,则可以使用以下方法:

Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Column = 4 Then
    If Target.Worksheet.Rows(Target.Row).EntireRow.Hidden = False Then
        Target.Offset(1, 0).EntireRow.Insert
        Target.Offset(1, 0).EntireRow.Insert
    End If
End If

End Sub

请注意,此代码必须放置在您希望它影响的工作表的代码页中。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.