VBA Delete Range Shift in Excel Explained with Examples

We can use VBA Delete Range to Shift Up and Shift Left the cells. Range.Delete method will Delete the selected cells or range as per the shift options. You can also delete entire rows or columns using EntireRow.Delete and EntireColumn.Delete methods of range object.

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 Delete Method Excel Range Object

VBA to Delete Range in Excel – Syntax

Here is the syntax to Delete a range using VBA. Here, Shift will be xlToLeft or xlUp. Shift:=xlLeft will shifts the cells towards Left side after deletion of the range. And Shift:=xlUp will shifts the cells towards Upper side after deletion of the range.

Range(“YourRange”).Delete(

[Shift])

The below syntax will delete the entire row of the selected range:

Range(“YourRange”).EntireRow.Delete

And the below syntax will delete the entire column of the selected range:

Range(“YourRange”).EntireColumn.Delete

VBA to Delete Range in Excel – Example:Shift:=xlToLeft

Here is the simple example to Delete a range in excel using VBA. In this example, we are deleting the range and shifting the cells left side. Here we are deleting range “B2:D10”.

Sub Delete_Range_To_ShiftLeft()
Range("B2:D10").Delete Shift:=xlToLeft
End Sub

VBA to Delete Range in Excel – Example:Shift:=xlToUp

Here is the Excel VBA macro to Delete a range. In this example, we are deleting the range and shifting the cells towards up. Here we are deleting range “B2:D10”.

Sub Delete_Range_To_ShiftUp()
Range("B2:D10").Delete Shift:=xlToUp
End Sub

VBA to Delete Range in Excel – Example: EntireRow

Here is the simple example to Delete a range in excel using VBA. In this example, we are deleting the entire row(s). Here we are deleting the rows of the range “B2:D10”, ie. we are deleting rows 2 to 10.

Sub Delete_Range_EntireRow()
Range("B2:D10").EntireRow.Delete 
End Sub

VBA to Delete Range in Excel – Example: EntireColumn

Here is the simple example to Delete a range in excel using VBA. In this example, we are deleting the entire column(s). Here we are deleting the columns of the range “B2:D10”, ie. we are deleting columns ‘B’ to ‘D’.

Sub Delete_Range_EntireColumn()
Range("B2:D10").EntireColumn.Delete 
End Sub

VBA to Delete Range in Excel – Execution Instructions

You can follow the below steps to execute the macro to Delete and paste a range using VBA.

  1. Open an Excel Workbook from your start menu or type Excel in your run command
  2. Enter some data in any cells in range “B2:D10″ to test this macro.
  3. Press Alt+F11 to Open VBA Editor or you can go to Developer Tab from Excel Ribbon and click on the Visual Basic Command to launch the VBA Editor
  4. Insert a Module from Insert Menu of VBA
  5. Copy the above code (to cut a range using VBA) and Paste in the code window(VBA Editor)
  6. Save the file as Macro Enabled Workbook (i.e; .xlsm file format)
  7. Press ‘F5′ to run it or Keep Pressing ‘F8′ to debug the code line by line.

Now you can observe that the Range “B2:D10” is deleted and moved in the specific range.
Example 1-Range(“B2:D10”).Delete Shift:=xlToLeft: It will delete the range and shift the cells towards left.
Example 2-Range(“B2:D10”).Delete Shift:=xlToUp: It will delete the range and shift the cells towards Up.
Example 3-Range(“B2:D10”).EntireRow.Delete: It will delete the complete row(s) of selected range (Rows 2 to 10).
Example 4-Range(“B2:D10”).EntireColumn.Delete: It will delete the complete column(s) of selected range (columns B to D).

LIMITED TIME OFFER

Leave A Comment


Related pages


how to copy data validation to other cellspassword protect a spreadsheetrange select vbaexcel xml tutorialddl and dml in sqlexcel vba file pathsql sasexcel to kml macrowhat is an operandshortcut key for excel 2007vba string manipulationworkbook unprotect vbaaccess vba rgb color codesfso read filevba custom message boxactivecell selectto merge cells in excelhow to merge cell data in excelvba copy rangecool excel tableseffort estimation templatemsg boxesnested vlookupiif in excelformula in pivot table excel 2010excel vba run macrodebug print vbaexcel vba filter rangeexcel merge columnsexcel 3d bubble chartinsert a row in excelwhat is vba macropie chart examples in excelcombine tabs in excelmerge macro excelexcel macro open worksheetexcel macro delete columnhow to remove all blank rows in excelexcel macro buttonssimple if statement excelexcel 2007 developer tabhow to adjust width of column in excelexcel vba shortcutvbcriticalms excel substitutenamed ranges vbavba output to text filecombobox additemhow do you do a tick on excelvba declarationexcel advanced filter criteria rangevba rowsexcel vba hide rowsmsgbox vba examplesmultiple if statement excelrange of cells in excel formulaadvanced vlookup exceltrim in excel 2007how to copy and paste excel sheetelseif vbahow to use hyperlink function in excelusing lookup function in excelexcel remove headerhow to adjust row height in excelwhat is a logical function in excelexcel vba userform positionf7 in excelexcel delete empty cellsexcel chart wizardexcel chart formattingexcel shortcut insert commentexcel lookup function exampleshow to remove a drop down box in excelhow do i unlock an excel fileconcatenate excel functiondeveloper tool in excel 2007dashboards excelhow to learn vba