Excel VBA: How to Delete the Current Row

VBA & macros · Updated November 3, 2026

Excel VBA: How to Delete the Current Row

To delete the worksheet row containing the active cell, use VBA’s ActiveCell.EntireRow.Delete method. For a safer macro that asks before deleting, save a copy of the workbook, then run the example below; a macro deletion cannot be reversed with Ctrl+Z.

What “current row” means in Excel VBA

Excel does not have a special row called the “current row.” In this context, it usually means the row containing the active cell: the cell currently selected on the active worksheet. If the active cell is D12, for example, the current row is worksheet row 12. The ActiveCell.Row property returns that row number, while ActiveCell.EntireRow refers to the full worksheet row.

This distinction matters when a user selects several cells. A selection can cover multiple rows, but it still has one active cell. A macro based on ActiveCell deletes only the row containing that active cell, not every row in the selected range. If you want to delete all selected rows instead, that requires different logic and deserves extra care.

“Delete the row” also means something specific in Excel: it removes the worksheet row and shifts the rows below it upward. It is not the same as clearing the values in the cells, hiding the row, or removing one record from an Excel table. Choose the operation that matches what you intend to remove.

A confirmation macro for the active row

This version identifies the active cell’s row, displays the worksheet and row number, and deletes the row only if you confirm. It is a useful default when a macro is triggered by a button or shortcut, where an accidental click could otherwise remove data immediately.

Sub DeleteCurrentRow()
    Dim ws As Worksheet
    Dim rowNumber As Long

    ' Use the worksheet containing the active cell.
    Set ws = ActiveSheet
    rowNumber = ActiveCell.Row

    ' Ask before removing the entire worksheet row.
    If MsgBox("Delete row " & rowNumber & " on " & ws.Name & "?", _
              vbYesNo + vbQuestion, "Confirm deletion") <> vbYes Then Exit Sub

    ws.Rows(rowNumber).Delete
End Sub

The macro uses ActiveSheet and ActiveCell, so the result depends on which sheet and cell are active when it runs. The Rows(rowNumber).Delete statement deletes the entire worksheet row, including cells outside the visible data table. If you do not need a confirmation prompt, the essential operation can be written as ActiveCell.EntireRow.Delete.

How to add and run the macro

In Excel for Microsoft 365 on Windows, open the Visual Basic Editor with Alt+F11. In the editor, choose Insert > Module, paste the code into the new module, and close the editor. If the Developer tab is not visible, enable it through File > Options > Customize Ribbon and select Developer.

  1. Save a backup copy of the workbook before testing a deletion macro.
  2. Save the working file as an Excel Macro-Enabled Workbook (.xlsm) if it needs to retain VBA code.
  3. Return to Excel, select a cell in the row you intend to remove, and choose Developer > Macros.
  4. Select DeleteCurrentRow, choose Run, and check the row number and sheet name in the prompt before confirming.

On a Mac, use the Developer tab’s Visual Basic command to open the VBA editor; keyboard shortcuts can vary with the keyboard and function-key settings. Add a module in the editor as on Windows. Excel for the web can open a macro-enabled workbook, but it cannot run VBA macros; use the desktop Excel application to execute this code. Only enable macros in files you trust.

Deleting a worksheet row versus deleting cells

Deleting a full row affects the whole worksheet, not just the columns that appear to contain your record. If your data occupies columns A through F but there are notes, formulas, or other data in column H on the same row, EntireRow.Delete removes those cells too. The cells below move up, and formulas elsewhere in the workbook may adjust to the changed references.

If your goal is only to remove contents while leaving the row and layout in place, clear the cells instead. You can use Excel’s Clear command or VBA’s ActiveCell.EntireRow.ClearContents, which clears contents across that row but does not delete the row itself. Be aware that clearing contents does not remove formatting, and clearing an entire worksheet row can still erase unrelated entries. To affect only a data range, refer to that range rather than the entire row.

For a single cell or selected range, Excel’s Delete command may offer choices such as shifting cells up or left. Those choices differ from deleting a whole worksheet row. A VBA statement should express the intended scope explicitly so the macro does not remove more than the user expects.

When the current row is inside an Excel table

An Excel table, created with Insert > Table or Home > Format as Table, has its own data-row structure. Deleting the entire worksheet row that contains a table record can also affect cells outside the table. If you mean “remove this record from the table,” use the table’s row collection instead. The following macro searches the active sheet’s tables and deletes the data row containing the active cell.

Sub DeleteActiveTableRow()
    Dim ws As Worksheet
    Dim tbl As ListObject
    Dim body As Range
    Dim tableRow As Long

    Set ws = ActiveSheet

    ' Find a table whose data body contains the active cell.
    For Each tbl In ws.ListObjects
        Set body = tbl.DataBodyRange
        If Not body Is Nothing Then
            If Not Intersect(ActiveCell, body) Is Nothing Then
                tableRow = ActiveCell.Row - body.Row + 1
                tbl.ListRows(tableRow).Delete
                Exit Sub
            End If
        End If
    Next tbl

    MsgBox "Select a data cell inside a table row.", vbInformation
End Sub

This code removes the table’s data row, rather than instructing Excel to delete the entire worksheet row. It does nothing when the active cell is outside a table’s data body, including when it is in a table header or totals row, and displays a message instead. For a filtered table, a row that is hidden by the filter is not necessarily the row containing the active cell; select a visible cell in the specific record you intend to remove.

Common problems and safer habits

  • The wrong row disappears: The macro uses the active cell, which may not be the cell you thought was selected. Check the prompt’s row number and sheet name before confirming.
  • The macro is missing after saving: A standard .xlsx file does not retain VBA code. Save the workbook as .xlsm to preserve the macro.
  • Excel says macros are disabled: VBA may be blocked by security settings or organizational policy. Do not enable macros in an unfamiliar file just to run a deletion routine.
  • The workbook is protected: Worksheet protection can prevent row deletion. Use the workbook’s authorized protection process rather than trying to bypass protection in the macro.
  • Undo does not restore the row: Excel’s undo history does not normally undo changes made by VBA. Keep a backup or use a confirmation prompt before deletion.

A backup is especially important when the macro is run repeatedly, used on a shared workbook, or attached to a button. Test it on a copy with sample data first. If the workbook has formulas, filters, merged cells, or other content beyond the target record, inspect the result carefully; deleting a row can change the layout and references beyond the visible area.

Choosing the right deletion method

Use the simplest method that matches the task. For a one-off deletion, select the row heading, right-click, and choose Delete. This makes the target visible before the action and avoids creating a macro. For a repeatable workflow that removes a complete worksheet row based on the active cell, use the confirmation macro. For a record in a structured table, use a table-row deletion method so that the operation is scoped to the table.

If users need to remove several records, consider whether a filter or a purpose-built cleanup process is safer than repeatedly deleting the active row. A macro that loops through rows must account for row shifting: when rows are deleted from top to bottom, the next row can move into the position just processed and be skipped. A common approach is to loop from the bottom upward, but the exact condition should be designed around the data and tested on a copy. Do not adapt a one-row macro into a bulk-delete routine without checking how it handles selection, filters, and formulas.

For a keyboard-driven workflow, you can assign a shortcut through Developer > Macros > Options. Choose a shortcut that does not conflict with a shortcut you rely on, and keep the confirmation prompt if accidental deletion is a concern. A button can also be assigned to the macro, but it will still act on the active cell when clicked; explain that behavior to anyone else using the workbook.

Frequently Asked Questions

What is the shortest VBA code to delete the current row?
Use ActiveCell.EntireRow.Delete in a procedure. It deletes the whole worksheet row containing the active cell, so the rows below shift upward.

Does VBA delete the selected row or the active cell’s row?
A statement using ActiveCell deletes the row containing the active cell, even if the selection spans several rows. It does not automatically delete every row in the selection.

Can I delete only the row in a table?
Yes. Use the table’s ListRows collection to remove a table data row, or choose Delete > Table Rows in Excel’s interface. That is different from deleting the entire worksheet row.

Can I undo a VBA row deletion with Ctrl+Z?
Usually not. VBA actions clear Excel’s normal undo history, so save a separate copy before running a deletion macro and use a confirmation prompt when appropriate.

Will this macro run in Excel for the web?
No. Excel for the web does not execute VBA. Open the macro-enabled workbook in desktop Excel for Windows or Mac to run the macro.

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.