Delete Hidden Rows using VBA

Home/VBA/Delete Hidden Rows using VBA

Excel VBA code to Delete Hidden Rows example will help us to delete rows in excel worksheet which are hidden. We can use Delete method of Rows to delete the Hidden Rows. In this example we will see how to delete the Hidden Rows in excel worksheet using VBA. Excel VBA Macro code for deleting Hidden Rows macro should work for all the version of Microsoft Excel 2003, Excel 2007, Excel 2010, and Excel 2013.

PREMIUM TEMPLATES LIMITED TIME OFFER

ON SALE80% OFF

50+ Project Management Templates Pack
Excel PowerPoint Word

Advanced Project Plan & Portfolio Template
Excel Template

Business Presentations Templates Pack
PowerPoint Slides

20+ Excel Project Management Pack
Excel Templates

20+ PowerPoint Project Management Pack
PowerPoint Templates

10+ MS Word Project Management Pack
Word Templates


VBA code to Delete Hidden Rows


Here is the Example VBA syntax and Example VBA Macro code to Delete Hidden Rows from excel worksheets. This will help you to know how to delete Hidden Rows from Excel workbook using VBA.

VBA Delete Hidden Rows: Syntax


Following is the VBA Syntax and sample VBA macro command to Delete Hidden Rows from worksheet using VBA. We are using the Delete method of the Rows object of worksheet.


If Rows(RowNumber).Hidden = True Then Rows(RowNumber).EntireRow.Delete

Here Rows(RowNumber).Hidden is to check if the row is hidden. And EntireRow.Delete method will delete the rows from the Excel spreadsheet if they are hidden.

Delete Hidden Rows using VBA: Examples


The following Excel VBA macro code is to delete Hidden Rows from the worksheet. This VBA macro will delete the row which are hidden.

Sub sbVBS_To_Delete_Hidden_Rows()
Dim lastRow
lastRow = 100
For iCntr = lastRow To 1 Step -1
If Rows(iCntr).Hidden = True Then Rows(iCntr).EntireRow.Delete
Next
End Sub 

Instructions to run the VBA Macro code to delete Hidden Rows


Please follow the below steps to execute the VBA code to delete Hidden Rows.
Step 1: Open any existing Excel workbook
Step 2: Press Alt+F11 – This will open the VBA Editor
Step 3: Insert a code module from then insert menu
Step 4: Copy the above code and paste in the code module which have inserted in the above step
Step 5: enter some sample data and hide some rows for testing purpose
Step 6: Now press F5 to execute the code

Now you can observe that the Hidden Rows are deleted from worksheet.

Explained VBA Code to Delete Hidden Rows:


‘Starting program and sub procedure to write VBA code to delete Hidden Rows from sheet
Sub sbVBS_To_Delete_Hidden_Rows()

‘Declaring the variable lastRow to store the last row in the worksheet
Dim lastRow As Long

‘Declaring the iCntr to use it in for loop
Dim iCntr As Long

‘assigning the values to the last row
lastRow = 100

‘looping through the rows using for loop from bottom to top
For iCntr = lastRow To 1 Step -1
‘checking the row is hidden.
‘Deleting the hidden rows
If Rows(iCntr).Hidden = True Then Rows(iCntr).EntireRow.Delete
Next
‘Ending the Excel VBA Macro to delete the hidden rows
End Sub

LIMITED TIME OFFER
By |April 21st, 2014|VBA|1 Comment

About the Author:

PNRao is a passionate business analyst and having close to 10 years of experience in Data Mining, Data Analysis and Application Development. This blog is his passion to learn new skills and share his knowledge to make you expertise in Data Analysis (Excel, VBA, SQL, SAS, Statistical Methods, Market Research Methodologies and Data Analysis Techniques).

One Comment

  1. hamid May 10, 2015 at 1:24 AM - Reply

    thanks .its very good

Leave A Comment


Related pages


vbscript coding examplesshortcut of insert row in exceltimeline templates exceloffset example excelbasic excel macromacro code in excelvba beginnerms excel vlookupuserform excelexcel lookup examplehow to find duplicate records in excelwhat is vlookup excelexcel vba current sheetprograming excelprotect formulas in excel 2007macro buttons exceladvantages microsoft excelhow to learn formulas in excelhow to run sql query in excelhow to open xlsx files in excel 2003excel 2007 sort by datelearn excel macrosddl commands in sql server 2008 with examplesexcel vba range copymacros and vba in excelexcel vba matchdelete row based on cell value vbavba cell formathlookup in excel with exampleexcel vba while loopiferror excel vbaunprotect excel sheet with passwordconcatenate in vba excelexcel macro savefind duplicate row in excelexcel vba internet explorervba open filehow to protect excel with passwordsql interview questions and answers with examplestechnical interview questions for freshersexcel collection vbaexcel vba windows activateexcel vba range sortvba introductionmicrosoft excel vba referencerca templatevba referencesample vb programs for beginnerslen function in excelexcel vba application getsaveasfilenamecountifs in excel 2007how to hide a worksheet in excelgantt chart free downloadconsolidate multiple worksheets into onemacro to close excel filelearn excel vlookupproject status dashboard excelexcel vba insert row into tablehow do you get a tick in excelunlock password excel filevba nested ifcombo box vba excelformat column vbadelete excel rowsexcel insert hyperlinkvba datatypessave excel vbaunlock workbook exceladodb connection providervba macro in excelvlookup left to rightchart creation in excelexcel macro activate workbookproject status report template pptvba text box