How to Delete Hidden Rows in Excel: 3 Methods

Method 1 – Utilizing the ‘Inspect Document’ Option to Delete Hidden Rows in Excel

  • Hide the highlighted rows, select the rows.
  • Right-click on the cell index number.
  • Click Hide.

‘Inspect Document’ Option to Delete Hidden Rows in Excel

  • See the highlighted rows are not visible.

‘Inspect Document’ Option to Delete Hidden Rows in Excel

NFollow some steps to delete these hidden rows.

  • Got to the File option from the ribbon.

‘Inspect Document’ Option to Delete Hidden Rows in Excel

  • Select the Info section. Go to the ‘Inspect Workbook’. From the drop-down select the ‘Inspect Document’ option.

‘Inspect Document’ Option to Delete Hidden Rows in Excel

  • A box like this will appear. Select Yes.

‘Inspect Document’ Option to Delete Hidden Rows in Excel

  • From the Document Inspector window click on the option Inspect.

  • Scroll down. Select the option Remove All for the Hidden Rows and Columns section.

  • See that the hidden rows are not present anymore. The below image shows the uninterrupted sequence of row numbers after deleting the hidden rows.

Note: You can’t undo the deleted rows. If you don’t want to delete them permanently, you must keep a data backup.


Method 2 – Adding a Temporary Column to Delete Hidden Rows

Delete hidden rows by adding a temporary column. Use filtering to apply this method. Suppose we just want to keep the sales data of New York and Boston locations in the following dataset. Delete the rest of the rows. Just follow the simple steps to execute this:

Adding Temporary Column to Delete Hidden Rows

  • Select the entire dataset (B4:G14).

Adding Temporary Column to Delete Hidden Rows

  • Go to the Sort & Filter option. From the dropdown click on the option Filter.

Adding Temporary Column to Delete Hidden Rows

  • See a dataset like this with filtering options at the column head.

Adding Temporary Column to Delete Hidden Rows

  • Go to the filtering drop-down of the title Location. Just select the options New York and Boston.
  • Press OK.

Adding Temporary Column to Delete Hidden Rows

  • Get only the sales data for New York and Boston. Other rows are hidden now.

Adding Temporary Column to Delete Hidden Rows

  • Add a new column. Name it Temporary. Enter the value 0 in cell H5.
  • Drag the Fill Handle tool.

Adding Temporary Column to Delete Hidden Rows

  • Get the value 0 for all the rows.

Adding Temporary Column to Delete Hidden Rows

  • Select the entire dataset (B4:B15) again.

Adding Temporary Column to Delete Hidden Rows

  • Go to the Sort & Filter drop-down. Select the option Filter.

Adding Temporary Column to Delete Hidden Rows

  • All the hidden data are now visible. See 0 only in the rows that we want to keep.

Adding Temporary Column to Delete Hidden Rows

  • Select the entire dataset (B4:G15) again.

Adding Temporary Column to Delete Hidden Rows

  • Go to Sort & Filter. From the drop-down, select the option Filter.

Adding Temporary Column to Delete Hidden Rows

  • See the filtering drop-downs in the title bars of the dataset.

Adding Temporary Column to Delete Hidden Rows

  • Go to the drop-down option in the ‘Temporary’ column.
  • Deselect option 0.
  • Click OK.

  • Get the rows that we have to delete.

  • Select all the rows. Do a right-click and click on the option Delete Row.

  • All the rows without the value 0 are now deleted.

  • Go to the drop-down of the Temporary column. Select option 0.
  • Click OK.

  • The dataset for the cities of New York and Boston.


Method 3 – Using VBA Code to Delete Hidden Rows in Excel

3.1. Deleting Hidden Rows from Entire Worksheet

The following dataset of sales. In our experimental dataset, the highlighted rows are hidden. Delete these rows using VBA.

Delete Hidden Rows from Entire Worksheet

Hiding the highlighted rows or database will look like the below image. We can see that the row index number is not consecutive.

Delete Hidden Rows from Entire Worksheet

It should be noted that if we do not have the Developer tab in our Excel, we have to activate the Developer tab to create macro-enabled content.

See how to activate the Developer tab. Just follow the instructions given below.

  • Go to the File option in the top-left corner of our Excel.

Delete Hidden Rows from Entire Worksheet

  • Select the Options.

Delete Hidden Rows from Entire Worksheet

  • A new window will come. Select the option Customize Ribbon from the available options.

Delete Hidden Rows from Entire Worksheet

  • Select the Developer option and click OK.

Delete Hidden Rows from Entire Worksheet

  • Ssee the Developer tab in our Excel.

Now we will use the Developer tab to create macro-enabled content.

  • Go to the Developer tab. Select the Visual Basic option.

  • A new window will open. From the window select the Insert tab. From the drop-down, select the Module option. Get a new module named Module-1.

  • Select the option Module-1. A blank window will open. Insert the following code in the blank window.
Sub DeleteHiddenRows()
Dim sht As Worksheet
Dim LastRow
Set sht = ActiveSheet
LastRow = sht.UsedRange.Rows(sht.UsedRange.Rows.Count).Row
For i = LastRow To 1 Step -1
If Rows(i).Hidden = True Then Rows(i).EntireRow.Delete
Next
End Sub
  • Click on the run option that we can see in the image. Press F5 as well to run the code.

  • See that we have deleted all the hidden rows.


3.2. Removing Hidden Rows from Specific Range

Use VBA to delete the hidden rows from a specific range. Also continue with our earlier dataset.

Hidden Rows Delete from Specific Range

  • Our range is (B4:G9). We will not delete hidden rows after row number 10. That’s why we are using two colors to highlight the hidden rows.

Hidden Rows Delete from Specific Range

  • From the Developer tab go to the code window.
  • Insert the following code there:
Sub DeleteHiddenRows()
Dim sht As Worksheet
Dim Rng As Range
Dim LastRow As Integer
Dim RowCount As Integer
Set sht = ActiveSheet
Set Rng = Range("B4:G9")
RowCount = Rng.Rows.Count
LastRow = Rng.Rows(Rng.Rows.Count).Row
For i = LastRow To LastRow - RowCount Step -1
If Rows(i).Hidden = True Then Rows(i).EntireRow.Delete
Next
End Sub
  • Click on the run option that we can see in the below image. We can press F5 as well to run the code.

Hidden Rows Delete from Specific Range

  • See that the hidden rows within the range (B4:G9) are deleted. Hidden rows after row number 10 are still present.


Download Practice Workbook

You can download the practice workbook from here.


Related Articles


<< Go Back to Delete Rows | Rows in Excel | Learn Excel

Get FREE Advanced Excel Exercises with Solutions!
Mukesh Dipto
Mukesh Dipto

Mukesh Dipto is an excellent marine engineer who loves working with Excel and diving into VBA programming. For him, programming is like a superhero tool that saves time when dealing with data, files, and the internet. His skills go beyond the basics, including Rhino3D, Maxsurf C++, AutoCAD, HTML, CSS, JavaScript, and WordPress. He got his B.Sc in Naval Architecture & Marine Engineering from BUET, and now he's switched gears, working as a content developer. In this role, he... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo