VBA Delete Current Row: Safe Methods and Examples

VBA & macros · Updated November 3, 2026

VBA Delete Current Row: Safe Methods and Examples

To delete the current row in Excel with VBA, delete the entire worksheet row that contains the active cell. The basic operation is to identify the active cell’s row and delete that row; the examples below show how to do it safely, including when the row is inside an Excel table.

What “current row” means in VBA

Excel’s “current row” usually means the worksheet row containing the active cell—the cell with the selection cursor. If the active cell is C7, deleting its entire row removes row 7 across the worksheet, not just the value in C7. Other cells in that row, including data in columns far to the right, are removed too, and rows below shift upward.

This distinction matters because deleting a worksheet row is broader than clearing contents or deleting a cell. If you only want to empty selected cells, use a clearing operation instead. If your data is formatted as an Excel table, deleting a table row is often preferable because it removes a record from the table without deleting the worksheet row’s other cells.

The active cell also depends on where you last clicked. A macro that deletes the current row does not know which record you intended unless the selection is in that record. Check the active worksheet and selection before running a deletion macro, especially if you assign it to a button or keyboard shortcut.

Delete the active worksheet row

This macro captures the active worksheet and row, then deletes that complete row. It includes a simple safeguard that prevents deletion of row 1, which is commonly used for column headings. If your headings are elsewhere—or row 1 is not a header—adjust or remove that check before use.

Sub DeleteCurrentWorksheetRow()
    Dim targetSheet As Worksheet
    Dim targetRow As Long

    ' Work with the sheet containing the active cell.
    Set targetSheet = ActiveSheet
    targetRow = ActiveCell.Row

    ' Protect row 1, commonly used for headings.
    If targetRow = 1 Then
        MsgBox "Select a data row, not the header row."
        Exit Sub
    End If

    targetSheet.Rows(targetRow).Delete
End Sub

Before running any macro that deletes data, save a copy of the workbook. Deletions made by VBA cannot be reversed with Ctrl+Z, even if Excel’s Undo button is available for ordinary manual edits. A backup is the dependable way to recover a row if the wrong one is removed.

Delete a row inside an Excel table

An Excel table, created with Insert > Table or Ctrl+T on Windows, has its own data rows, headers, and possibly a totals row. If the active cell is in a table’s data area, deleting the entire worksheet row may also remove unrelated information located beside the table. To remove only the table record, use the table’s row-deletion method instead.

The following macro checks the active worksheet’s tables and deletes the table data row containing the active cell. It does nothing to a table header or totals row because neither belongs to the table’s data body.

Sub DeleteCurrentTableRow()
    Dim targetSheet As Worksheet
    Dim tbl As ListObject
    Dim tableBody As Range
    Dim tableRowIndex As Long

    ' Search tables on the active worksheet.
    Set targetSheet = ActiveSheet
    For Each tbl In targetSheet.ListObjects
        Set tableBody = tbl.DataBodyRange

        ' An empty table has no data body.
        If Not tableBody Is Nothing Then
            If Not Intersect(ActiveCell, tableBody) Is Nothing Then
                tableRowIndex = ActiveCell.Row - tableBody.Row + 1
                tbl.ListRows(tableRowIndex).Delete
                Exit Sub
            End If
        End If
    Next tbl

    MsgBox "Select a cell in a table data row first."
End Sub

This approach is useful when a worksheet contains a table alongside notes, formulas, or a second dataset. It preserves those other worksheet cells while removing the selected table record. If the active cell is not inside a table’s data rows, the macro displays a message instead of deleting a worksheet row by mistake.

Delete multiple rows that meet a condition

For a batch cleanup, such as removing records marked “Remove” in column B, loop from the bottom of the data upward. Deleting a row shifts all later rows up. A top-to-bottom loop can therefore skip the row that moves into the position just deleted. A bottom-up loop avoids that problem.

This example assumes row 1 contains headings, records start in row 2, and the status to check is in column B. It deletes entire worksheet rows, so review the sheet layout before using it if columns outside the dataset contain information that must remain aligned.

Sub DeleteRowsMarkedRemove()
    Dim targetSheet As Worksheet
    Dim lastRow As Long
    Dim rowNumber As Long

    ' Column B contains the status; row 1 is the header.
    Set targetSheet = ActiveSheet
    lastRow = targetSheet.Cells(targetSheet.Rows.Count, "B").End(xlUp).Row

    ' Work upward so row deletions do not skip records.
    For rowNumber = lastRow To 2 Step -1
        If LCase$(Trim$(CStr(targetSheet.Cells(rowNumber, "B").Value))) = "remove" Then
            targetSheet.Rows(rowNumber).Delete
        End If
    Next rowNumber
End Sub

The last-row calculation uses column B, so it finds the last non-empty cell in that column. If records can have a blank status in B but data elsewhere, this may not cover every record. Choose a column that is populated for every data row, or calculate the last row using a different reliable column. For table-based data, consider iterating over table rows and deleting records there instead of deleting whole worksheet rows.

Run and save a VBA macro

On Excel for Microsoft 365 on Windows, press Alt+F11 to open the Visual Basic Editor, choose Insert > Module, and paste the macro into the module. Return to Excel, select a cell in the row you intend to delete, and press Alt+F8. Choose the macro and select Run. You can also run it from the Visual Basic Editor with the cursor inside the procedure by pressing F5.

Save a workbook containing VBA as an Excel Macro-Enabled Workbook (.xlsm). Saving it as a standard .xlsx file removes the VBA code. Excel may also show a security notice when opening a workbook with macros; only enable macros in files you trust.

Excel for Mac also supports VBA, though keyboard shortcuts can vary with the keyboard and macOS settings. The Visual Basic Editor is available from Tools > Macro > Visual Basic Editor, and macros can be managed from Tools > Macro > Macros. On some Mac keyboards, function-key combinations may require Fn. Excel for the web does not run VBA macros; open the workbook in the desktop Excel app to use these examples.

Common mistakes and safeguards

The most frequent problem is deleting the wrong row because the active cell is not where expected. A macro can run successfully while removing unintended data. Select a recognizable cell in the target record, confirm the sheet name, and consider adding a confirmation prompt when a macro will be used repeatedly. For sensitive worksheets, a backup or a copy of the data on another sheet is safer than relying on Undo.

  • Deleting the whole row unintentionally: A worksheet-row deletion affects every column in that row, even outside the visible dataset. Use a table-row deletion when surrounding worksheet cells should stay in place.
  • Removing headings: A macro without a header check can delete row 1. Add a guard that matches the workbook’s actual header location rather than assuming every dataset starts on the same row.
  • Unexpected formulas or references: Excel adjusts many references when rows are deleted, but the result may still differ from what the workbook’s formulas or layout require. Check dependent calculations and charts after a bulk deletion.
  • Protected sheets: Excel can prevent a macro from deleting rows on a protected worksheet. Unprotect the sheet using its authorized settings, or design the workbook’s protection and macro behavior deliberately; do not assume VBA will bypass protection.
  • Filters and hidden rows: A filter can make the visible records differ from the full dataset. A macro that deletes the active row deletes that row whether it is visible or hidden. Review filters and hidden rows before running code that processes many records.

For a safer workflow, test a macro on a disposable copy with a small sample first. If the code will be used by other people, document which sheet and column it expects, what counts as a header, and whether it deletes table records or full worksheet rows. Those details help prevent a correct macro from being used in the wrong context.

Choose VBA, the ribbon, or another method

VBA is useful when deletion is part of a repeatable process, a button-driven workflow, or a larger cleanup routine. For a one-off deletion, select any cell in the row, right-click its row heading, and choose Delete. You can also select the row heading and use Home > Delete > Delete Sheet Rows. These manual methods are easier to inspect before committing, but they still remove the entire worksheet row.

For a table record, right-click a cell in the table row and choose Delete > Table Rows. This is the clearer choice when the table shares a worksheet with unrelated content. For a conditional cleanup, a filter can help you inspect matching records before deleting them; filtering alone does not remove data, so confirm the selected rows carefully before using a deletion command.

The right method depends on the shape of the data and how often the task occurs:

  • Use a manual command for a single, visible row when you want to verify the choice yourself.
  • Use a worksheet-row macro when the entire row should be removed and the task is repeatable.
  • Use a table-row macro when the target is a record in an Excel table and other cells beside it must remain.
  • Use a bottom-up loop for multiple worksheet rows selected by a condition, after testing the criteria on a copy.

Frequently Asked Questions

How do I delete the row of the active cell in VBA?
Use a macro that reads ActiveCell.Row and deletes that row from the active worksheet. The first example above adds a row 1 safeguard; remove or change it if your workbook uses a different header arrangement.

Does deleting a row with VBA clear only the selected cell?
No. Deleting the worksheet row removes cells across that row and shifts the rows below upward. To remove only a table record, delete the corresponding ListRow; to empty a cell, clear its contents instead.

Can I undo a VBA row deletion with Ctrl+Z?
No. Excel’s normal Undo history does not restore changes made by a VBA macro. Save a separate copy before running a deletion macro, particularly one that processes many rows.

How do I delete the current row in an Excel table?
Use the table-specific method shown above, which finds the active cell in a table’s data body and deletes that ListRow. You can also right-click in the table row and choose Delete > Table Rows.

Will the macro delete a hidden row?
Yes, if the active cell is in that row, a worksheet-row deletion still removes it whether the row is hidden or visible. Check filters and hidden rows before running a macro, especially when it processes a range in bulk.

Related

Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.

More in VBA & macros

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.