Delete Hidden/Invisible Rows after Autofilter Excel VBA

后端 未结 2 1688
借酒劲吻你
借酒劲吻你 2020-12-01 18:36

I guess this is pretty straight forward, but for some reason it just does not seem to work for me :(

I have the below code which auto-filters the data based on the c

2条回答
  •  时光说笑
    2020-12-01 19:31

    So I was kind of looking to get rid of Unfiltered Data rather than trying to reverse all the criteria and delete the visible cells

    I would use this one:

    Sub RemoveHiddenRows()
        Dim oRow As Range, rng As Range
        Dim myRows As Range
        With Sheets("Sheet3")
            Set myRows = Intersect(.Range("A:A").EntireRow, .UsedRange)
            If myRows Is Nothing Then Exit Sub
        End With
    
        For Each oRow In myRows.Columns(1).Cells
            If oRow.EntireRow.Hidden Then
                If rng Is Nothing Then
                    Set rng = oRow
                Else
                    Set rng = Union(rng, oRow)
                End If
            End If
        Next
    
        If Not rng Is Nothing Then rng.EntireRow.Delete
    End Sub
    

提交回复
热议问题