Delete rows in a range using VBA

Home/VBA/Delete rows in a range using VBA

VBA code to delete rows in range example will helps to delete empty rows in specific range from excel worksheet. We can use Delete method of Rows to delete the rows in a range. In this example we will see how to delete the rows from a range in excel worksheet using VB. Excel VBA Macro code for deleting rows in a range should work for all the version of Microsoft Excel 2003, Excel 2007, Excel 2010, and Excel 2013.



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 rows in a range

Here is the Example VBA syntax and Example VBA Macro to delete rows in range from excel worksheets. This will help you to know how to delete specific rows in a range from Excel workbook using VBA.

VBA delete rows in range: Syntax

Following is the VBA syntax and sample VBA code to delete rows in a range from worksheet using VBA. We are using the Delete method of the Rows object of worksheet.


Here Rows.delete method will delete the row in the worksheet..

Delete rows in Range: Examples

The following VBA code is to delete rows in range A10 to D20 .

Sub sbVBS_To_Delete_Rows_In_Range()
Dim iCntr
Dim rng As Range
Set rng = Range("A10:D20")
For iCntr = rng.Row + rng.Rows.Count - 1 To rng.Row Step -1
End Sub 

Instructions to run the VBA code to delete rows in range

Please follow the below steps to execute the VBA code to delete rows in range from Excel worksheets.
Step 1: Open any 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 in range A1 to D20 in any column. And leave some rows for testing purpose.
Step 6: Now press F5 to execute the code

Now you can observe that the all rows are deleted from worksheet in in Range A10 to D20.

Explained VBA Code to Delete Rows in a range

Start writing the Excel VBA Macro to delete rows in a particular range.
Sub sbVBS_To_Delete_Rows_In_Range()

‘Declaring a variable iCntr as Long to store the row number iteration to use in for loop.
Dim iCntr As Long
‘Declaring range variable rng to set the range
Dim rng As Range

‘Assigning the range A10 to D20 to rng range object
Set rng = Range(“A10:D20”)

‘Looping through the rows in the range from last to first. Here step statement will helps.
For iCntr = rng.Row + rng.Rows.Count – 1 To rng.Row Step -1
‘And deleting the rows

End Sub
Ending the sub procedure to delete rows in a range.

By |April 21st, 2014|VBA|0 Comments

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).

Leave A Comment

Related pages

xl to xml convertervba choosedelete duplicate entries excelsample charts in excelexcel column auto widthmacro recorder excel 2007hlookup functioncombo box in exceladvanced filter excel 2013data mining add inswhat are the ddl commandsvba check if file existshow to remove a drop down box in excelhow to hide tabs in excelvbscript coding examplescolumns vbavlookup formula for excelexcel schedule plannerwhere is the developer tab in excel 2013excel formulas to find duplicateshow to unprotect excel sheet without passwordfileformat vbahow to unhide hidden columns in excelopen excel file from access vbashortcut to switch between excel workbookshow to do a vlookup on excel 2010auto save excel 2010how do you concatenate in exceltechnical interview questions and answers for freshers pdfvba set cell colorhow to draw pie chart in excel 2007vbscript read excel fileadvanced sql interview questions and answershow to insert many rows in excelexcel combine spreadsheetsexcel slicer formulaenable macros in vbahow to hide formula in excel sheetaccess vba query tablesumif formulacreate checkbox in excel 2010timeline in excel templatevba last row in rangesql pivot tutorialarrange ascending orderhow to merge three columns in exceluseful formulas in excelexcel vba case statementproject checklist template excelexcel hlookup examplevba save as xlsxlookup excellogical functions in excel 2010excel functions and syntaxvba open file for readinghow to do pivot tables in excel 2013excel vba statementsexcel hlookup tutorial pdfexcel delete named rangehow to lock a tab in excelexcel autofit cellsexcel highlight duplicates in columnclose file vbaexcel bar chart templatescopy duplicates in excelleft excel vbavba selection.copyadvanced sas interview questionswhat are the ddl commands in sqlhow to call a function in vbaconcatenate excel 2007data analyst interview questions and answers for fresherssyntax for sql commandsdelete empty cells in excelvlookup function in excel