Delete Hidden Rows in a Workbook

Add to Favorites
Author:
This macro will delete hidden rows from every worksheet in an entire workbook. However, note that this will only delete one hidden row from a group at once. This means that if you have rows 3-9 hidden on a sheet and rows 45-55 hidden on the same sheet, the last hidden rows (row 9 and row 55) will be deleted on that worksheet. This means that the entire section of rows 3-9 etc. will not be deleted in one pass. Obviously if you are working with workbook that relies heavily on hidden data and hidden rows, this might not be the best macro.

Where to install the macro:  Module

Delete Hidden Rows

Sub DeleteHiddenRows_Workbook()

'This Microsoft Excel Macro will remove hidden rows from
'all worksheets in a workbook.

For i = 1 To Worksheets.Count
If Worksheets(i).Visible Then
Worksheets(i).Select
ActiveCell.SpecialCells(xlLastCell).Select
k = ActiveCell.Row
For j = 1 To k
If Rows(j).Hidden Then
Rows(j).Hidden = False
Rows(j).Delete
End If
Next j
End If
Next i
If Worksheets(1).Visible Then Worksheets(1).Select

End Sub







Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons 50+ Hours of Instruction 200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

Similar Content on TeachExcel
Delete Duplicate Rows
Macro: This macro will delete rows that appear twice in a list or worksheet. If two cells are...
Delete Blank Rows in Excel
Macro: This is a macro which will delete blank rows in excel. This version will delete an entire ...
Delete All Comments in a Worksheet in Excel Macro
Macro: Excel macro that will delete all of the comment contained within the active or current wor...
Delete Hidden Worksheets
Macro: This macro will delete all hidden worksheets within a workbook. When you run this macr...
Count the Visible Rows in a Filtered List in Excel
Tutorial: How to use the COUNT or COUNTA function on a filtered list of data so that hidden rows ar...
Average the Visible Rows in a Filtered List in Excel
Tutorial: Average the results from a filtered list in Excel. This method averages only the visible ...


How to Install the Macro
  1. Select and copy the text from within the grey box above.

  2. Open the Microsoft Excel file in which you would like the Macro to function.

  3. Press "Alt + F11" - This will open the Visual Basic Editor - Works for all Excel Versions.  Or For other ways to get there, Click Here.

  4. On the new window that opens up, go to the left side where the vertical pane is located. Locate your Excel file; it will be called VBAProject (YOUR FILE'S NAME HERE) and click this.

  5. If the Macro goes in a Module, Click Here, otherwise continue to Step 8.

  6. If the Macro goes in the Workbook or ThisWorkbook, Click Here, otherwise continue to Step 8.

  7. If the Macro goes in the Worksheet Code, Click Here, otherwise continue to Step 8.

  8. Close the Microsoft Visual Basic Editor window and save the Excel file. When you close the Visual Basic Editor window, the regular Excel window will not close.

  9. You are now ready to run the macro.

Tutorial Details
Similar Content
Delete Duplicate Rows
Macro: This macro will delete rows that appear twice in a list or worksheet. If two cells are...
Delete Blank Rows in Excel
Macro: This is a macro which will delete blank rows in excel. This version will delete an entire ...
Delete All Comments in a Worksheet in Excel Macro
Macro: Excel macro that will delete all of the comment contained within the active or current wor...
Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course