How to catch row(s) deleted in Excel VBA

我的未来我决定 提交于 2020-06-17 13:11:48

问题


I would like to get the row numbers of each deleted row after or before the rows are deleted in VBA.

There is an Event BeforeDelete() but when I delete a row it is not triggered?

Is there any other events or ways I could do this?

Here's kinda what I want:

Private Sub Worksheet_BeforeDelete() Dim i As Integer i = ActiveCell.Row End Sub


回答1:


The following event macro will tell you whenever an entire row is deleted or inserted:

Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Rows.Count = 1 And Target.Columns.Count = Columns.Count Then
        MsgBox Target.Row
    End If
End Sub


来源:https://stackoverflow.com/questions/49560431/how-to-catch-rows-deleted-in-excel-vba

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!