我在Excel电子表格中具有以下内容,



如何根据J列= 0内的发布内容删除行?

最好将行剪切并将其粘贴到另一张纸中。.但是如果您可以删除它就可以帮助我,那会很好。

最佳答案

此代码自动过滤活动表上J = 0的行,将它们复制到第二个工作表上的第一空白行,然后从活动表中删除行。

更改此行Set ws2 = Sheets(2)将行复制到另一张工作表,即第五张工作表的Set ws2 = Sheets("Your Sheet Name")Set ws2 = Sheets(5)

Sub MoveEm()
    Dim ws1 As Worksheet
    Dim ws2 As Worksheet
    Set ws1 = ActiveSheet
    Set ws2 = Sheets(2)
    Dim rng1 As Range
    Application.ScreenUpdating = False
    With ws1
        .AutoFilterMode = False
        .Columns("j").AutoFilter Field:=1, Criteria1:="0"
        With .AutoFilter.Range.Offset(1, 0).EntireRow
        Set rng1 = ws2.Cells.Find("*", ws2.[a1], xlValues, , xlRows, xlPrevious)
        If rng1 Is Nothing Then
        Set rng1 = ws2.[a1]
        Else
        Set rng1 = ws2.Cells(rng1.Row + 1, "A")
        End If
            .Copy rng1
            .Delete
        End With
        .AutoFilterMode = False
    End With
    Application.ScreenUpdating = True
End Sub

09-03 18:19