How to Delete/Remove Hidden or Visible Cells Not In/In Filter in Excel

Suppose we have a long list in worksheet (1000 rows or more), and we do filter to show only some cells of the list by some criteria. If we want to keep the visible cells and remove the hidden rows to reduce redundant data and the size of file, how can we do? On the other side, if we want to remove the visible cells in the filter and keep the hidden rows, how can we do? In this article, we will introduce you some methods to remove hidden or visible rows in filter per your demands.

Precondition:

We have a list of numbers.

DeleteRemove Hidden or Visible Cells Not InIn Filter 1

Create a filter that only show rows where value is greater than 300.

DeleteRemove Hidden or Visible Cells Not InIn Filter 2

Method 1: Delete/Remove Hidden Rows Not in Filter


Before applying below method, make sure create a copy of your original file in case of improper operating.

Step 1: Click File in ribbon, and select Info.

DeleteRemove Hidden or Visible Cells Not InIn Filter 3

Step 2: Click arrow button in Check for Issues, select Inspect Document.

DeleteRemove Hidden or Visible Cells Not InIn Filter 4

Step 3: Verify that Document Inspector window displays. Drag the scroll bar to the bottom, verify that Hidden Rows and Columns option is checked by default.

DeleteRemove Hidden or Visible Cells Not InIn Filter 5

x
How to Create Dynamic Interactive Charts in Excel

Step 4: Click Inspect button in the bottom. Verify that Remove All button appears in Hidden Rows and Columns, and ‘Number of hidden rows found:5’ displays.

DeleteRemove Hidden or Visible Cells Not InIn Filter 6

Step 5: Click Remove All. Verify that all hidden rows and columns containing data were removed.

DeleteRemove Hidden or Visible Cells Not InIn Filter 7

Step 6: Click Close button to quit Document Inspector window. Go back to worksheet, verify that hidden rows are removed properly, only show rows in filter are kept.

DeleteRemove Hidden or Visible Cells Not InIn Filter 8

Method 2: Delete/Remove Hidden Rows Not in Filter by VBA Code


Step 1: On current visible worksheet, right click on sheet name tab to load Sheet management menu. Select View Code, Microsoft Visual Basic for Applications window pops up.

Or you can enter Microsoft Visual Basic for Applications window via Developer->Visual Basic. You can also press Alt + F11 keys simultaneously to open it.

Step 2: In Microsoft Visual Basic for Applications window, click Insert->Module, enter below code in Module1:

Sub DeleteHiddenRows()
Set myRows = Intersect(ActiveSheet.Range("A:A").EntireRow, ActiveSheet.UsedRange)
If myRows Is Nothing Then Exit Sub
For Each oneRow In myRows.Columns(1).Cells
If oneRow.EntireRow.Hidden Then
If myRange Is Nothing Then
Set myRange = oneRow
Else
Set myRange = Union(myRange, oneRow)
End If
End If
Next
If Not myRange Is Nothing Then
MsgBox myRange.Count & " hidden rows have been removed.", , "Removing Hidden Rows"
myRange.EntireRow.Delete
Else
MsgBox "No hidden rows were found", , "Remove Hidden Rows"
End If
End Sub

Step 3: Save the codes, see screenshot below. And then quit Microsoft Visual Basic for Applications.

Step 4: Click Developer->Macros to run Macro. Select ‘RemoveHiddenRows’ and click Run.

DeleteRemove Hidden or Visible Cells Not InIn Filter 10

Step 5: Verify that Remove Hidden Rows message pops up. And ‘5 hidden rows have been found. All were removed.’ shows on the message.

Step 6: Click OK and check the result. Verify that hidden rows are removed properly.

DeleteRemove Hidden or Visible Cells Not InIn Filter 8

Method 3: Delete/Remove Visible Rows in Filter by Go To Special


Step 1: Select visible cells, then press F5 to load Go To dialog, click Special.

DeleteRemove Hidden or Visible Cells Not InIn Filter 12

Step 2: On Go To Special dialog, check on Visible cells only option, then click OK.

DeleteRemove Hidden or Visible Cells Not InIn Filter 13

Step 3: Verify that visible cells are activated. Right click to load menu, select ‘Delete Row’.

DeleteRemove Hidden or Visible Cells Not InIn Filter 14

Step 4: Verify that visible cells are removed. Expand filter, verify that only hidden rows are shown.

DeleteRemove Hidden or Visible Cells Not InIn Filter 15

 

Related Posts

VBA Macro For VLOOKUP From Another Sheet
vba macro for vlookup from another sheet1

In the previous post, you should know that how to fix or remove the #N/A error when using VLOOKUP formula to lookup value from another sheet. And this post will show you how to use VBA code to vlookup data ...

How To Insert Comments in Protected Worksheet in Excel
insert commetns in protected workshee3

This post will show you how to allow comments in a protected worksheet in Excel. You can easily to insert comments into cells in a normal worksheet in Excel, but if want to insert a comment in a worksheet that ...

How To Convert Text to Upper Cases(Using VBA) in Excel
convert text to upper cases1

This post will show you how to switch from lower case to upper case in Excel. and I am going to show you two different ways of converting text to upper cases using formula or VBA macro in Excel 2013,Excel ...

How To Hide Every Other Row in Excel (Using VBA)
hide every other row1

This post will show you how to hide alternate rows or columns in Excel or how to hide every third, fourth, fifth row or column in Excel. If you want to hide every other row in your current worksheet, how ...

How to Disable the Save As Prompt in Excel
disable save as prompt1

This post will show you how to use a VBA Macro to save an Excel file and overwrite any existing file without a prompt so that you are going to get the little window that says file already exists do ...

How to Count Cells that Contain even or odd numbers in Excel
count cells that contain even numbers5

This post will guide you how to count the number of cells that contain odd or even numbers within a range of cells using a formula in Excel 2013/2016.How do I count cells that contain odd numbers through the use ...

How to Count Cells that Contain negative Numbers in Excel

This post will guide you how to count the number of cells that contain negative numbers within a range of cells using a formula in Excel 2013/2016.You can count the number of negative numbers in your data using easy functions ...

How to Count Cells Are Not Blank or Empty in Excel
count non blank nonempty cells5

This post will guide you how to count cells that are not blank or empty in a given range cells using a formula in Excel 2013/2016.How do I count the number of cells that are not blank in a particular ...

How to Count Cells Less Than a Specific Value in Excel
count cells lessr than5

This post will guide you how to count the number of cells less than a particular numeric value in a given range cells using a formula in Excel 2013/2016. How do I count cells that are less than a specific ...

How to Count Cells Greater Than a Specific Value in Excel
count cells greater than 5

This post will guide you how to count the number of cells greater than a particular numeric value in a given range cells using a formula in Excel 2013/2016. How do I count cells that are greater than a specific ...

Sidebar