20170821xlVBA隐藏空行

Sub HideBlankRowsBetweenUsedRange()
    Dim URows As Range, i As Long, EndRow As Long
    With ActiveSheet
        EndRow = .Cells.Find("*", .Cells(1, 1), xlValues, xlWhole, xlByRows, xlPrevious).Row
        For i = 1 To EndRow
            If Application.WorksheetFunction.CountA(.Rows(i)) = 0 Then
                If URows Is Nothing Then
                    Set URows = .Rows(i)
                Else
                    Set URows = Union(URows, .Rows(i))
                End If
            End If
        Next i
        If Not URows Is Nothing Then URows.EntireRow.Hidden = True
    End With
    Set URows = Nothing
End Sub

  

posted @ 2017-08-21 09:03  wangway  阅读(365)  评论(0编辑  收藏  举报