Delete Active row using VBA

Home/VBA/Delete Active row using VBA

Excel VBA code to Delete Active row example will help us to delete the row in excel worksheet which is active. We can use Delete method of Rows to delete the Active row. In this example we will see how to delete the Active row in excel worksheet using VBA. Excel VBA Macro code for deleting Active row 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 Active row


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

VBA Delete Active row: Syntax


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


Rows(ActiveCell.Row).EntireRow.Delete

Here ActiveCell.Row return the row number of the active cell. And EntireRow.Delete method will delete the rows from the Excel spreadsheet.

Delete Active row using VBA: Examples


The following Excel VBA macro code is to delete Active row from the worksheet. This VBA macro will delete the row which currently active.

Sub sbVBS_To_Delete_Active_Rows()
Rows(ActiveCell.Row).Delete
End Sub 

Instructions to run the VBA Macro code to delete Active row


Please follow the below steps to execute the VBA code to delete Active row.
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: select/ activate a cell for testing purpose
Step 6: Now press F5 to execute the code

Now you can observe that the Active Cell row is deleted from worksheet.

Explained VBA Code to Delete Active Row :


‘Starting program and sub procedure to write VBA code to delete Active Cell Row for worksheet
Sub sbVBS_To_Delete_Active_Rows()
‘ActiveCell.Row returns the Active Row number
‘And Delete method will delete the entire row from the worksheet
Rows(ActiveCell.Row).Delete
‘Ending the Excel VBA Macro to delete the active row
End Sub

LIMITED TIME OFFER
By |April 21st, 2014|VBA|6 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).

6 Comments

  1. February 17, 2015 at 12:40 AM - Reply

    very good
    with regards

  2. Himanshu January 11, 2017 at 9:16 PM - Reply

    Sir is this also correct? Thanks

    Sub sbVBS_To_Delete_Active_Rows()
    Activesheet.Rows.Select
    Selection.Entirerows.delete
    End Sub

    V/S

    Sub sbVBS_To_Delete_Active_Rows()
    Rows(ActiveCell.Row).Delete
    End Sub

  3. genaro July 19, 2017 at 12:51 AM - Reply

    If Range(“M” & i).Value Like “Complete” Then
    Rows(i).Copy Sheets(“Complete”).Range(“A” & Rows.Count).End(xlUp).Offset(1)
    Range(“A:J”).Select
    Selection.Rows(i).Delete
    End If

    does anyone know what can i do with this code. im trying to delete just some columns from the row but i get a error message

    • PNRao July 19, 2017 at 8:59 PM - Reply
      Sub DeleteRowsBasedOnCondition()
      lastRow = 10
      'Always delete from last row to first
      For i = lastRow To 1 Step -1
      If Range("M" & i).Value Like "Complete" Then
      Rows(i).Copy Sheets("Complete").Range("A" & Rows.Count).End(xlUp).Offset(1)
      Rows(i).EntireRow.Delete
      End If
      Next
      End Sub
      

      Thanks!

      • genaro July 19, 2017 at 11:28 PM - Reply

        the code that i have works but what i want to do is delete part of the row from A to J. i want to do this because when i delete the row the formulas that i have in cells K to M gets delete and i need to drag my formula down every time the whole row is delete that is why i want to know if there is a way to just delete cells A to J. right now i want to copy the whole row to another sheet which it does but i just dont want to delete part of the row where the formulas are.

        This is my code

        Dim UsdRws As Long
        Dim i As Long

        Application.ScreenUpdating = False

        UsdRws = Range(“A1”).CurrentRegion.Rows.Count

        For i = UsdRws To 2 Step -1

        If Range(“M” & i).Value Like “Complete” Then
        Rows(i).Copy Sheets(“Complete”).Range(“A” & Rows.Count).End(xlUp).Offset(1)
        Rows(i).Delete
        End If

        Next i

        Application.ScreenUpdating = True

        Thanks you

Leave A Comment


Related pages


how to delete macrosexcel charts and graphs tutorialhow to apply sumif formula in excelshow userform vbaexcel vba columnwidthvba beginner tutorialhow to unhide in excelexcel dashboard add insmerge worksheets into onevba code wordascending and descending order worksheetscreate sheet vbapivot graph excelsample gantt chart excel templatems excel 2007 shortcut keys listbubble chart excel 2007excel vba radio buttonenable macro vbaifs function in excelproject planning and scheduling in excelhow to create a excel worksheetwhat is vlook up in excelexcel formulas shortcutschange width of column in excel 2010fso objectbuild a dashboard in excelvbscript file handlingoffset command excelsimple excel test for interviewvba mergewhat is grouping in sqlsql programming interview questions and answershow to find duplicates in excel 2007vba delete filesvb6 listbox columnsexcel remove empty linescells.select vbaloop vba excelsql ddl commandiserror function in accesswrite excel macroexcel highlight duplicates in columnvba open pdf fileopen recordset vbapivot table descending orderdeveloper tool in excelhow to insert combobox in excelautofit columns excellookup function excel 2013vba msg boxprotect sheet vbavba workbook activateexcel vba printsql tutorials for beginnershow do i delete blank rows in excelexcel macro applicationapplication function vbahow to open xlsx files in excel 2003how do you unhide rows in excelfind last row vbahow to check duplicate rows in excelmerge excel worksheets into one master worksheetexcel project calendar templatecountif in excel examplesql interview questions for freshers pdfremove duplicate rows in excelif statements vbaexcel macro recordingsumif excel formularemove blank from pivot tableexcel vba errunhide all tabs in excelexcel 2010 multiple if statementsmark duplicates in excelexcel vba loop through rowshow to delete gaps in excelxml converter to excelmerging cell in excelexcel macro dialog boxexcel hide buttonmsgbox example vba