How to filter a list and delete the rest hidden or visible rows in Excel?
For a filtered list, you may need to delete the hidden or visible rows in order to keep only the useful data. In this article, we will show you methods of deleting the rest hidden or visible rows of a filtered list in Excel.
This section will show you VBA code to delete hidden rows in active sheet. Please do as follows.
1. Activate the worksheet you need to delete hidden rows, press Alt + F11 keys simultaneously to open the Microsoft Visual Basic for Applications window.
2. In the Microsoft Visual Basic for Applications window, click Insert > Module. And then copy and paste the below VBA code into the Module window.
VBA code: Delete hidden rows
Sub RemoveHiddenRows() Dim xRow As Range Dim xRg As Range Dim xRows As Range On Error Resume Next Set xRows = Intersect(ActiveSheet.Range("A:A").EntireRow, ActiveSheet.UsedRange) If xRows Is Nothing Then Exit Sub For Each xRow In xRows.Columns(1).Cells If xRow.EntireRow.Hidden Then If xRg Is Nothing Then Set xRg = xRow Else Set xRg = Union(xRg, xRow) End If End If Next If Not xRg Is Nothing Then MsgBox xRg.Count & " hidden rows have been deleted", , "Kutools for Excel" xRg.EntireRow.Delete Else MsgBox "No hidden rows found", , "Kutools for Excel" End If End Sub
3. Press the F5 key to run the code. If there are hidden rows in active sheet, after running the code, a dialog box will pop up to tell you how many hidden rows have been deleted. Click the OK button to delete the hidden rows. See screenshot:
Otherwise, you will get the following dialog box after running the code.
Note: the above VBA code not only can delete hidden rows of filtered list, but also delete hidden rows which you have manually hidden before.
For deleting visible rows of filtered list, please do as follows.
1. Select all filtered out rows, and press F5 key to open the Go To dialog box, then click the Special button. See screenshot:
2. In the Go To Special dialog box, check the Visible cells only option, and then click the OK button.
3. Now all visible rows are selected, right click the selection, and then click Delete Rows.
Until now, all visible rows are deleted from the filtered list.
The above two methods may be not the desire solutions for many Excel users, here we introduce you a handy tool. With the Delete Hidden (Visible) Rows & Columns utility of Kutools for Excel, you can easily delete hidden rows in selected range/sheets, active sheet or all worksheets in Excel.
Before applying Kutools for Excel, please download and install it firstly.
1. If you only want to delete hidden or visible rows of a filtered list, please select the filtered range manually, and then click Kutools > Delete > Delete Hidden (Visible) Rows & Columns. See screenshot:
2. In the Delete Hidden (Visible) Rows & Column dialog box, keep the In selected Range selected in the Look in drop-down list (you can select other options as you need), check the Rows option in the Delete type section, and in the Detailed type section, check Visible rows or Hidden rows option as you need. And finally click the OK button.
3. Then a dialog box pops up to tell you how many rows have been deleted, please click the OK button.
Best Office Productivity Tools
Supercharge Your Excel Skills with Kutools for Excel, and Experience Efficiency Like Never Before. Kutools for Excel Offers Over 300 Advanced Features to Boost Productivity and Save Time. Click Here to Get The Feature You Need The Most...
Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier
- Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
- Open and create multiple documents in new tabs of the same window, rather than in new windows.
- Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!