Vba中 删除指定行

Sub classification()

Dim LastRow, max_level As Integer
    Dim slc, j, dele, a, b As Integer
  
    On Error Resume Next
    LastRow = ActiveSheet.UsedRange.Rows.Count

    For slc = 1 To LastRow
Line1:
    
        If Sheet1.Cells(slc, "e") = "FOLDERS" Then
        dele = slc + 1
            For j = slc + 1 To LastRow
             If Range("A" & j) > Range("A" & j + 1) Then
                  dele = j
                  Exit For
             End If
            Next j
            Range(Rows(slc), Rows(dele)).Delete
      GoTo Line1
        End If
    Next slc

End Sub

这里用了GOTO ,是因为删除的行,他会上移,也可以使用DO 

上一篇:【VBA】判断文件是否存在


下一篇:CorelDRAW VBA - 实现段落文本的HTML兼容 Text.MakeHTMLCompatible