VBA Delete First Row: Code and Safe Options

VBA & macros · Updated November 3, 2026

VBA Delete First Row: Code and Safe Options

To delete row 1 of a worksheet with VBA, use ws.Rows(1).Delete, where ws is the worksheet you intend to change. For example, set ws to a named worksheet first; this is safer than deleting row 1 of whichever sheet happens to be active.

What “delete the first row” means in VBA

In Excel, row 1 means the worksheet row with the number 1 at the far left. It does not necessarily mean the first row containing data, the first visible row, or the first record in a table. That distinction matters: a worksheet might have a title in row 1, column headings in row 3, and records beginning in row 4.

The Rows(1).Delete statement deletes the entire worksheet row. Cells below it move up, and Excel adjusts many formulas and references as it normally does when a row is deleted. This is different from clearing the row’s contents: a delete removes the row’s cells and shifts cells upward, while clearing contents leaves the row in place.

In a procedure, qualify the row with a worksheet object, such as ws.Rows(1).Delete. Without that qualification, Rows(1).Delete acts on the active sheet. A macro can change the active sheet during its work, so relying on the active sheet can lead to an unintended deletion.

Delete row 1 from a named worksheet

This is a basic, explicit example. Change Data to the exact worksheet tab name in your workbook. The name is case-insensitive, but spaces and punctuation must match.

Sub DeleteRowOneFromData()
    Dim ws As Worksheet

    'Target the worksheet in the workbook containing this VBA code.
    Set ws = ThisWorkbook.Worksheets("Data")

    'Delete the entire first worksheet row.
    ws.Rows(1).Delete
End Sub

ThisWorkbook means the workbook that contains the running VBA code. That is often the right choice when the macro is stored in the workbook being edited. If the macro is stored in Personal.xlsb or an add-in, ThisWorkbook refers to that file instead. In that situation, explicitly set a workbook variable to the workbook that contains the data before choosing its worksheet.

To insert and run the procedure in Excel for Microsoft 365 on Windows, press Alt+F11 to open the Visual Basic Editor, choose Insert > Module, paste the code into the module, and run it with the cursor inside the procedure by pressing F5. You can also use Developer > Visual Basic. On Mac, use Option+F11 to open the editor; depending on the keyboard’s function-key settings, you may need Fn+Option+F11. Save a macro-enabled workbook as an .xlsm file if it needs to retain VBA.

Choose the right worksheet and workbook

Before deleting anything, identify the workbook and sheet the code should affect. Worksheet names are generally more reliable than sheet positions because users can reorder tabs. For example, Worksheets(1) means the first worksheet in the workbook’s worksheet collection, not necessarily the tab named “Data.” A chart sheet is not a worksheet and is not included in that collection.

If the macro should act on the workbook the user currently has selected, you can use ActiveWorkbook, but that choice is deliberate: the active workbook can differ from the workbook that stores the macro. Likewise, ActiveSheet can be a different sheet from the one expected. For a repeated or automated task, assigning a specific workbook and worksheet to variables makes the target easier to review and reduces accidental changes.

A missing or misspelled sheet name causes a run-time error when VBA tries to set the worksheet variable. That is preferable to silently deleting from a different sheet, but a production macro can check whether the sheet exists and show a useful message. Do not add a broad error handler that simply ignores every error: it can make a failed deletion look as though it succeeded.

Delete the first data row but keep the headings

If row 1 contains column headings and the first record is in row 2, deleting row 1 removes the headings, not the first record. To remove the first data row while keeping those headings, target row 2:

Sub DeleteFirstDataRow()
    Dim ws As Worksheet

    'The headers are in row 1 and the first record is in row 2.
    Set ws = ThisWorkbook.Worksheets("Data")
    ws.Rows(2).Delete
End Sub

This example assumes the layout is stable. If headings or introductory rows can move, hard-coding row 2 may no longer identify the first record. In that case, base the row number on a known label, a named range, or an Excel table rather than assuming a fixed position. A worksheet’s first nonblank cell is not automatically its first record: notes, formulas returning empty text, or stray formatting can complicate attempts to infer where data begins.

Also distinguish deleting a record from clearing its values. Deleting row 2 shifts all rows below it up, which may affect layout outside the data area. If you only need to empty selected cells while preserving row positions and formatting, clear those cells instead of deleting the entire worksheet row. Choose based on whether the surrounding worksheet should move up.

Remove the first record from an Excel table

When the data is an Excel table, use the table’s row collection to remove its first data record. This leaves the table header intact and expresses the operation in terms of the table rather than a worksheet row number.

Sub DeleteFirstTableRecord()
    Dim ws As Worksheet
    Dim tbl As ListObject

    'Use the worksheet and table names from the workbook.
    Set ws = ThisWorkbook.Worksheets("Data")
    Set tbl = ws.ListObjects("SalesTable")

    'A table can have no data rows, so check before indexing it.
    If tbl.ListRows.Count > 0 Then
        tbl.ListRows(1).Delete
    End If
End Sub

Replace SalesTable with the table’s actual name. You can find or change a table name by selecting a cell in the table and using the Table Design tab. ListRows(1) refers to the first data row within that table; it does not refer to the heading row.

Filtering introduces an important distinction. The first table data row in the table’s stored order may not be the first row currently visible after a filter. The example deletes the first data row in the table, not necessarily the first visible record. If you mean the first visible matching record, the macro needs to identify visible rows and select the intended one carefully. Do not assume that deleting worksheet row 2 will always remove the first visible table record.

What happens when VBA deletes a worksheet row

Deleting a worksheet row removes all cells in that row across the sheet, not just cells in the apparent data block. Cells below move upward. This can affect notes, calculations, or other content placed to the right of the main dataset, even if those cells look unrelated. If your goal is only to remove a record from one section, a table-row deletion or deletion of a bounded range may be more appropriate than deleting the entire worksheet row.

Excel often updates formulas that refer to cells affected by a row deletion, but do not assume every relationship is harmless. Formulas can change or display errors if their referenced cells are removed; external workbook links, names, charts, and other dependent features may need review. A macro that repeatedly deletes row 1 also has a cumulative effect: each run removes a different row because the remaining rows move up.

Deleting a row is not the same as hiding it or filtering it out. A hidden row remains in the worksheet, and a filtered-out row remains in the data. Use deletion only when the record or row should actually be removed. If the aim is temporary display or analysis, hiding or filtering is usually easier to reverse.

Common errors and safer ways to run the macro

One common error is “Subscript out of range,” often caused by a worksheet name that does not exist in the workbook referenced by the code. Another is deleting from the wrong workbook because the code uses ThisWorkbook when the data is open in a different file. Verify both the workbook reference and the exact tab name before running the procedure.

A protected worksheet may prevent deletion, depending on its protection settings. If deletion is blocked, check the sheet’s protection and the workbook’s intended security rules rather than trying to bypass them blindly. A worksheet can also have merged cells or other layout features that make row operations behave differently from a simple, unformatted list; test the procedure on a copy if the sheet is complex.

  • Save a separate copy of the workbook before running a destructive macro. VBA changes cannot be reversed with Ctrl+Z, and running a macro clears Excel’s normal undo history.
  • Confirm the active workbook, worksheet name, and row number before execution.
  • Test the code on a small copy or sample workbook first, particularly if the worksheet contains formulas, tables, filters, merged cells, or important formatting.
  • Keep a backup if the macro runs automatically or processes multiple sheets.

For a one-time operation, using the worksheet interface may be simpler: select the row heading, right-click, and choose Delete. For repeatable work, VBA is useful because it can target a named sheet or table consistently. A macro should still be as narrow as the task requires; automating a deletion does not make the deletion easier to recover from.

When to use another approach

Use Rows(1).Delete when the whole first worksheet row should be removed and the cells below should shift up. Use ListRows(1).Delete when the aim is to remove a table’s first data record while preserving the table structure. Use ClearContents on a carefully chosen range when values should be removed but the row and its formatting should remain.

If row 1 is a title or heading, do not remove it merely because it is the top row. If the first data row changes position over time, make the macro locate a dependable marker or use a table. If you need to delete several rows, decide whether the row numbers are consecutive and whether the macro should process them from the bottom upward; deleting from top to bottom can shift later target rows and cause the wrong rows to be skipped.

For a fixed, known set of rows, test the sequence on a copy before running it on the original. For a table, deleting by table row avoids much of the row-number bookkeeping. For occasional cleanup, manual deletion can be safer because you can inspect the selected row immediately before confirming the change.

Frequently Asked Questions

What is the VBA code to delete row 1?
Use Rows(1).Delete on the intended worksheet, such as ws.Rows(1).Delete. Assigning ws to a specific worksheet avoids relying on whichever sheet is active.

How do I delete the first row but keep the header?
If row 1 is the header and row 2 is the first record, delete row 2 with ws.Rows(2).Delete. For an Excel table, use tbl.ListRows(1).Delete to remove its first data record without targeting the header.

Can I undo a VBA row deletion with Ctrl+Z?
No. After VBA changes the workbook, Excel’s ordinary undo history is cleared, so Ctrl+Z cannot reverse the macro’s deletion. Save a backup copy before running it.

Does Rows(1).Delete remove the first visible row?
No. It targets worksheet row 1 by its row number, whether or not that row is visible. With filters, a visible record may be on a different worksheet row; identify that record explicitly if it is the one you intend to delete.

How can I delete the first row from every worksheet?
A loop can do that, but it may also remove titles, headers, or other content from sheets that should not be changed. First define which sheets are eligible, then loop only through those sheets and test on a backup. A blanket deletion across every sheet is risky in workbooks with varied layouts.

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.