How to use VBA to select all unhide rows in a table?

Azuki

Board Regular
Joined
Feb 14, 2013
Messages
73
I have a table. I want to write macro to filter a column. The result will hide some rows. I want to delete all unhide rows. How can I do that?
 
Hello,

Maybe I can answer part of your question.

To delete rows that are hidden try:

Sub delete_hidden_rows()
Dim i As Integer

For i= 1 To 100 'Note, this will look at only rows 1 to 100
If ThisWorkbook.Sheets("Sheet1").Rows(i).Hidden = True Then​
ThisWorkbook.Sheets("Sheet1").Rows(i).Delete Shift:=xlUp​
i = i - 1 'Must do this in case there are 2 hidden rows in a row.
End If​
Next i

End Sub
 
Last edited:
Upvote 0
Yes, the entire codes as follow:

Code:
Sub Macro1()
    
    ActiveSheet.ListObjects("Project_List").Range.AutoFilter Field:=2, Criteria1 _
        :="=RDD", Operator:=xlOr, Criteria2:="=SWCC"


    ActiveSheet.AutoFilter.Range.Offset(1).SpecialCells(xlCellTypeVisible).Select
End Sub

Basically, I want to delete rows which field 2 is "RDD" or "SWCC".

Have you AutoFiltered the active sheet?
 
Upvote 0
Thanks all who have helped. I manage to get it.

Code:
Sub Macro1()
'
' Macro1 Macro
'


'
    Dim colNoProjCluster
    Range("Project_List[[#Headers],[Project Cluster]]").Offset(0, 1).Select
    ActiveSheet.ListObjects("Project_List").Range.AutoFilter Field:=2, Criteria1 _
        :="=RDD", Operator:=xlOr, Criteria2:="=SWCC"
    Range("Project_List").SpecialCells(xlCellTypeVisible).EntireRow.Delete
        
End Sub
 
Upvote 0
Sorry, I don't know why this didn't work. But I thought I manage to get it to work just now. :(
 
Upvote 0
Does this work for you?

Code:
Sub Macro1()
    Dim Rng As Range
    With ActiveSheet.ListObjects("Project_List")
        .Range.AutoFilter Field:=2, Criteria1 _
            :="=RDD", Operator:=xlOr, Criteria2:="=SWCC"
        Set Rng = .DataBodyRange.SpecialCells(xlCellTypeVisible)
        .Range.AutoFilter
        Rng.Delete
    End With
End Sub
 
Upvote 0

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top