Search TeachExcel.com
TeachExcel.com
TE
Teach Excel MS Office Tutorials Excel Consulting Services Excel Forum
Excel Video Tutorials Excel Tips Free Excel Macros Excel Help Resources Contact TeachExcel
Video Tutorials
  • Free Macros
  • Excel Help Directory
  • Excel 2007 Resources
  • Keyboard Shortcuts
  • Excel Forum
  • Contact/About

Macros
Excel Tutorials For Macros

Delete Hidden Rows in a Workbook


Bookmark and Share

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


Bookmark and Share


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.

      For Excel Versions Prior to Excel 2007
      Go to Tools > Macros > Visual Basic Editor

      For Excel 2007
      Go to Office Button > Excel Options > Popular > Click Show Developer tab in the Ribbon. Then go to the Developer tab on the ribbon menu and on the far left Click Visual Basic

  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.

    1. Go to the menu at the top of the window and click Insert > Module
    2. Another window should have opened within the Visual Basic Editor's window. Within this new window, paste the macro code. Make sure to paste the code underneath the last line of anything else that is in the window.
    3. Go to Step 8.

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

    1. Directly underneath your excel file called VBAProject(your file's name here), click the Microsoft Excel Objects folder icon to open that drop-down list.
    2. Then, at the bottom of the list that appears, double-click the ThisWorkbook text.
    3. A new window inside the Visual Basic Editor's window will appear. In this new window, paste the code for the macro. Make sure to paste this code underneath the last line of any other code which is already in the window.
    4. Go to Step 8.

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

    1. Directly underneath your excel file called VBAProject(your file's name here), click the Microsoft Excel Objects folder icon to open that drop-down list.
    2. Within the list that appears you will see every worksheet that is in that excel file. They will be listed as such: Sheet1(NAME OF SHEET HERE) and under that will be Sheet2(NAME OF SHEET HERE). Select the sheet in which you want the macro to run and double-click that sheet.
    3. A new window inside the Visual Basic Editor's window will appear. In this new window, paste the code for the macro. Make sure to paste this code underneath the last line of any other code which is already in the window.
    4. Repeat steps b and c for every sheet you want the macro to work in. Putting the macro in one sheet will not enable it for any other sheets in the workbook.
    5. Go 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.



Similar Helpful Excel Resources

Macros To Delete Hidden Sheets And Hidden Rows - Excel

View Content
Hi there,

I have built a monster spreadsheet, with the aim for it to cover all possible scenarios at my job. It basically involves a sheet for each type of test I may do. Some days it may need 1 sheet, others it may need 10. These all get populated into a single "Report" sheet.

What I am pulling my hair out over is trying to create 2 macros, which would be run one after the other.

The first would be to delete all hidden sheets in the workbook.

The second would be to delete all hidden rows, in the "Report" sheet only, and at the same time find any ",!#REF!" occurences that may have been generated by deleting rows, and replacing them with nothing. i.e. some cells may average 10 cells, deleting some rows will introduce say 5 valid cells, and 5 which have been deleted, leaving the ",!#REF!".

Can anyone out there help me out with these 2 macros please?

Thanks, James

How To Delete Multiple Rows Without Deleting The Hidden Rows When Filtered? - Excel

View Content
I have a filtered data and I need to delete only the visible rows.

How do you do that without deleting the hidden rows?

Thanks!

Delete Hidden Rows - Excel

View Content
I need to loop through 1200 workbooks and delete all hidden rows. How can I kick off and execute the document inspector in 2007, save, then close?

Cheers

Delete Hidden Rows - Excel

View Content
I have written code to do an advanced filter, filtering to a list of criteria. Now I need code to delete the hidden rows, leaving me with only the rows that I filtered to. Can someone help?

Thanks in advance!

How To Delete All Hidden Worksheets When Workbook Saved - Excel

View Content
I have working code to unhide specific worksheets from a large number of hidden worksheets and would like to be able to delete all the hidden sheets when the workbook is saved or maybe have a button to delete all the hidden (un-needed) worksheets beside the selection drop-down menu, so that only the selected sheets are saved.

Geoff

Delete Hidden Rows & Columns - Excel

View Content
Hello,

Can anyone help how to delete hidden rows and columns.

In my worksheets I have a macro, which in some cases hide some rows or columns.

Now I need a macro, which will delete these hidden rows and columns.

Is it possible?

Thank you in advance

Tomas

Delete All Hidden Rows After Filtering - Excel

View Content
Hello All,

I currently have this code here that deletes any rows that have "Grape" in the "Fruit" column...

Code:

 
Sub Delete_rows_with_text_x_in_col_x()
Dim cell_to_check As Variant
Dim range_to_check As Range
Dim nCol As Long
Dim rCount As Long
With ActiveSheet
    nCol = Application.Match("Fruit", .Rows(1), 0)
    For rCount = .UsedRange.Rows.Count To 2 Step -1
        Select Case .Cells(rCount, nCol).Value
                Case "grape", "GRAPE"
                .Rows(rCount).EntireRow.Delete
        End Select
    Next
End With




But the code seems pretty slow. Is there a way, using the autofilter that this code can be faster?


I was thinking, logically, it could be this way here...

1. Autofilter the entire workbook
2. Filter the fruit column for all values except "grape" or "GRAPE".
3. Delete any rows not visible, which would be any rows that contain "grape" or "GRAPE".

Can this be done via code?

Thanks much

Code To Delete Hidden Rows? - Excel

View Content
I am writing a macro and need to delete the hidden cells (filtered using an advanced filter). I have done it before through the document inspect option, but have no idea how to do this in VB. Can someone point me to some code I can start with?

How To Delete The Hidden Rows After Autofilter The Worksheet - Excel

View Content
Hi,
Does anyone know, what is the VBA code to delete the hidden rows after autofilter the worksheet?

Thanks so much for help!

Delete All Blank Rows On A Hidden Sheet - Excel

View Content
Hi guys

normaly i would just sort the values and then delete the bottom rows
but the sheet is very hidden
which means that it cant be sorted with out unhiding it (as far as i know)
is there a way that i can just delete all the blank rows in the sheet??

Random Tutorials
Make a Thermometer Style Chart in Excel
(Intermediate)
FV() Find the Future Value of Cash Today
         -Savings/Retirement Plan Calculations

(Intermediate)
Extract Text from Cells - Intermediate Example
(Intermediate)
Remove #N/A Error Result from Empty VLOOKUP() Formulas
(Intermediate)
Lookups With MATCH() and INDEX() Functions
(Intermediate)
IF Statement Introduction & Using Nested IF's
(Easy)
Submit Inquiry Here
  • Prices From $10
Name:*
E-mail:*
Request:*
The macro(s) on this page will be sent with the request.
Contact | Privacy Policy | Disclaimer
Copyright© 2012 TeachExcel.com