Automatically Delete Empty Rows in Excel Spreadsheets

Tested prompts for remove blank rows in excel automatically compared across 5 leading AI models.

BEST BY JUDGE SCORE Claude Haiku 4.5 9/10

You have a spreadsheet with hundreds or thousands of rows, and someone left empty rows scattered throughout. Sorting breaks, formulas miscount, pivot tables choke, and scrolling past gaps wastes time. You need those blank rows gone, and you do not want to Ctrl+click each one manually.

Excel has built-in ways to do this (Go To Special, Filter, Power Query, VBA), but each has tradeoffs depending on whether your blanks are fully empty rows or rows with a few empty cells, whether you have merged headers, and whether you need the process to repeat on a schedule. The fastest manual route takes about four clicks; the fully automatic route runs every time the file opens.

This page shows how to get AI to generate the exact macro, Power Query step, or formula you need, tailored to your sheet structure. Below you will find a tested prompt, four model outputs side by side, and guidance on which approach to pick for your data.

When to use this

Use an AI-generated automation when you clean the same report repeatedly, when blank rows appear in unpredictable positions, or when your file is too large for manual selection. AI is also useful when you cannot remember VBA syntax or Power Query M code but know exactly what result you want. For a one-time cleanup of a small sheet, skip automation and use Go To Special.

  • Weekly exports from CRM, ERP, or accounting software that always ship with empty spacer rows
  • Spreadsheets with 50,000+ rows where manual selection is too slow
  • Files shared across a team where the cleanup must run identically each time
  • Reports feeding a pivot table or Power BI dashboard that breaks on blank rows
  • CSV imports where blank rows represent failed records you need removed before analysis

When this format breaks down

  • Your blank rows are meaningful (section separators in a printed report you want to keep visually)
  • Only some cells in a row are blank and the row still contains valid data you need to preserve
  • You have merged cells across rows, which VBA row-deletion will mangle
  • The file contains formulas with absolute row references that will break when rows shift up

The prompt we tested

You are an Excel automation expert helping users remove blank rows from their spreadsheets automatically. Based on the user's situation below, provide clear step-by-step methods to delete empty rows.

Instructions: Respond with 2-3 distinct methods (e.g., Go To Special, Filter, VBA macro) formatted as numbered steps under bold method headings. Include exact menu paths, keyboard shortcuts, and any VBA code in a code block. Keep each method under 8 steps and end with a one-line tip on which method suits which scenario.

User's situation:
I have a sales report in Excel with about 5,000 rows, but there are hundreds of completely blank rows scattered throughout the data. I need a way to remove them all at once without manually scrolling and deleting each one. I'm using Excel 365 on Windows.

Provide the solution now.

Model comparison

ModelQualityCostLatencyTokens
Claude Opus 4.7 9 $0.0713 14.1s 287 / 893
Claude Haiku 4.5 9 $0.0044 9.3s 197 / 836
GPT-5.4Not run yet
Gemini 2.5 Pro 3 $0.0008 22.2s 184 / 104
Grok 4.1 Fast Reasoning 9 $0.0004 11.8s 323 / 574

Outputs

Claude Opus 4.7 9/10
# Removing Blank Rows in Excel 365 (Windows)

## **Method 1: Go To Special (Fastest for Most Users)**

1. Select the entire data range (e.g., click any cell in the data, then press **Ctrl + A**).
2. Press **F5** (or **Ctrl + G**) to open the Go To dialog.
3. Click **Special…**
4. Choose **Blanks**, then click **OK** — all blank cells are now selected.
5. On the **Home** tab, go to **Cells → Delete → Delete Sheet Rows** (or press **Ctrl + -**).
6. Choose **Entire row** if prompted, then click **OK**.

⚠️ *Caution:* This also deletes rows where only *some* cells are blank. Use Method 2 if your data has partial blanks.

---

## **Method 2: Filter for Blanks**

1. Select your data range and press **Ctrl + Shift + L** to enable filters.
2. Click the filter arrow on any key column (e.g., Date or Order ID).
3. Uncheck **(Select All)**, then check only **(Blanks)** → click **OK**.
4. Select the visible blank rows (click the first row number, then **Ctrl + Shift + End**).
5. Right-click the selected row numbers → **Delete Row**.
6. Click the filter arrow again and choose **(Select All)** to restore your data.
7. Press **Ctrl + Shift + L** to turn off filters.

---

## **Method 3: VBA Macro (Best for Repeating the Task)**

1. Press **Alt + F11** to open the VBA editor.
2. Click **Insert → Module**.
3. Paste the code below:

```vba
Sub DeleteBlankRows()
    Dim rng As Range
    Dim i As Long
    Set rng = ActiveSheet.UsedRange
    Application.ScreenUpdating = False
    For i = rng.Rows.Count To 1 Step -1
        If Application.WorksheetFunction.CountA(rng.Rows(i)) = 0 Then
            rng.Rows(i).EntireRow.Delete
        End If
    Next i
    Application.ScreenUpdating = True
    MsgBox "Blank rows removed!"
End Sub
```

4. Press **F5** to run the macro (or close the editor and run it via **Alt + F8**).
5. Save your file as **.xlsm** to keep the macro.

---

💡 **Tip:** Use **Method 1** for a quick one-time cleanup, **Method 2** when you need to inspect before deleting, and **Method 3** if you handle sales reports like this regularly.
Judge notes: Excellent response that directly addresses the user's query with three practical, well-explained methods suited to their situation, includes accurate menu paths and working VBA code, and provides clear guidance on method selection—minor deduction only for Method 1's cautionary note potentially creating unnecessary concern about partial blanks in a clearly defined scenario.
Claude Haiku 4.5 9/10
# Methods to Remove Blank Rows from Your Sales Report

## Method 1: Using Go To Special (Fastest for Most Users)

1. **Select your entire data range** – Click on the first cell with data, then press **Ctrl+Shift+End** to select all data
2. **Open Go To Special** – Press **Ctrl+H** (Find & Replace), then click **Options > Other options** (or use **Ctrl+G** then **Special** in older versions)
3. **In Excel 365**, use **Edit > Delete Cells** approach: Select data, press **Ctrl+Minus (−)**, choose **Entire row**, click **OK**
4. **Alternatively**, select your range and go to **Home > Find & Select > Go To Special**
5. **Select "Blanks"** and click **OK** (this selects only empty cells)
6. **Right-click** on the selected blank cells and choose **Delete > Entire Row**
7. **Confirm** the deletion when prompted

**Tip:** Use this method when blank rows are scattered randomly throughout your dataset—it's the fastest manual approach.

---

## Method 2: Using AutoFilter (Best for Visibility)

1. **Select your data range** – Click any cell in your data table
2. **Apply AutoFilter** – Go to **Data > Filter** (or press **Ctrl+Shift+L**)
3. **Click the dropdown arrow** on any column header
4. **Uncheck "Blanks"** to hide empty rows (or check only data-containing rows)
5. **Select all visible rows** – Click the row number of the first data row, then **Ctrl+Shift+End** to select all visible rows
6. **Right-click** and choose **Delete > Delete Rows**
7. **Remove the filter** – Go to **Data > Filter** again to show all remaining rows

**Tip:** Use this method when you want to verify which rows are truly blank before deletion—provides clear visibility.

---

## Method 3: VBA Macro (Best for Large Datasets & Automation)

1. **Press Alt+F11** to open the VBA Editor
2. **Go to Insert > Module** to create a new module
3. **Paste the following code:**

```vba
Sub DeleteBlankRows()
    Dim ws As Worksheet
    Dim lastRow As Long
    Dim i As Long
    
    Set ws = ActiveSheet
    lastRow = ws.Cells(ws.Rows.Count, 1).End(xlUp).Row
    
    ' Loop from bottom to top to avoid skipping rows
    For i = lastRow To 1 Step -1
        If WorksheetFunction.CountBlank(ws.Rows(i)) = ws.Columns.Count Then
            ws.Rows(i).Delete
        End If
    Next i
    
    MsgBox "Blank rows deleted successfully!", vbInformation
End Sub
```

4. **Close the VBA Editor** – Press **Alt+Q**
5. **Run the macro** – Press **Alt+F8**, select **DeleteBlankRows**, and click **Run**
6. **Confirm** the completion message

**Tip:** Use this method for 5,000+ rows or when you need to automate this task repeatedly—it processes in seconds.

---

**Quick Recommendation:** For your 5,000-row dataset with scattered blanks, **Method 3 (VBA Macro)** is fastest; use **Method 2 (Filter)** if you want to double-check before deleting.
Judge notes: Excellent response that directly addresses the user's scenario with three well-explained, practical methods including exact menu paths, keyboard shortcuts, and working VBA code; minor issue is Method 1's explanation is slightly convoluted with multiple approaches mentioned, but the VBA macro and filter methods are clearly superior solutions for the stated 5,000-row problem.
Gemini 2.5 Pro 3/10
Of course. Here are three distinct methods to automatically remove all completely blank rows from your sales report.

### **Method 1: Go To Special**

This is the fastest manual method for a one-time cleanup, using a built-in Excel feature to select all blank cells at once.

1.  Select the entire column that should always contain data (e.g., Column A if it has an ID for every valid sale). This prevents accidentally deleting rows that are not completely blank.
2.
Judge notes: The output is incomplete and cuts off mid-method, failing to deliver the promised 2-3 complete methods with exact steps, menu paths, shortcuts, and VBA code as instructed.
Grok 4.1 Fast Reasoning 9/10
### Method 1: Go To Special (Blanks)
1. Select your entire data range (e.g., click the top-left cell and press **Ctrl+A**, or **Ctrl+Shift+End** for used range).
2. Press **Ctrl+G** (or **F5**) to open Go To.
3. Click **Special** > select **Blanks** > **OK** (this selects all blank cells in the range).
4. With blanks selected, right-click any selected cell > **Delete** > **Entire row** > **OK**.

**Tip: Fastest for one-time manual cleanup on moderately large datasets like 5,000 rows.**

### Method 2: Filter for Blanks
1. Select your data range (e.g., **Ctrl+A**).
2. Go to **Data** tab > **Filter** (or **Ctrl+Shift+L**) to add dropdown arrows.
3. Click the filter arrow on any column header (completely blank rows will show as blank in all columns).
4. Uncheck **(Select All)** > check **(Blanks)** > **OK** (visible rows are now completely blank).
5. Select all visible rows: click the first row number > **Shift+click** the last (or **Ctrl+Shift+End**).
6. Right-click a row number > **Delete Row** > **OK**.
7. Go to **Data** tab > **Filter** (or **Ctrl+Shift+L**) to remove filters.

**Tip: Best when you want to visually preview blanks before deleting.**

### Method 3: VBA Macro
1. Press **Alt+F11** to open VBA Editor.
2. **Insert** > **Module** to create a new module.
3. Paste the following code into the module window:

```vba
Sub DeleteBlankRows()
    Dim ws As Worksheet
    Set ws = ActiveSheet
    Dim lastRow As Long, i As Long
    lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
    Application.ScreenUpdating = False
    For i = lastRow To 1 Step -1
        If Application.CountA(ws.Rows(i)) = 0 Then ws.Rows(i).Delete
    Next i
    Application.ScreenUpdating = True
End Sub
```

4. Press **Ctrl+S** to save, then **Alt+F11** to return to Excel (save workbook as .xlsm if needed).
5. Select your data sheet > press **Alt+F8** > select **DeleteBlankRows** > **Run**.

**Tip: Ideal for large datasets (5,000+ rows) or repeatable automation; handles completely blank rows precisely.**

**Overall tip: Choose Go To Special for speed, Filter for verification, VBA for efficiency on big scattered blanks.**
Judge notes: Excellently addresses the query with three well-explained, practical methods tailored to the user's specific 5,000-row scenario, including accurate menu paths, shortcuts, working VBA code, and contextual guidance on which method to use when.

What makes these work

  1. 01
    Specify your column range

    Tell the AI exactly which columns define a blank row. 'Row is blank if A:H are all empty' produces different code than 'row is blank if any of A:H is empty.' Ambiguity here is the top cause of wrong output.

  2. 02
    Give row counts for performance

    A macro that deletes rows one at a time works fine on 500 rows and crashes Excel on 500,000. Mention your row count so the AI picks the right strategy: loop for small files, AutoFilter or Union for large ones.

  3. 03
    Say where to save the code

    Specify personal workbook, this workbook, or a module in a shared add-in. The AI will include the right save path and button assignment steps, so you do not end up with a macro that only works in one file.

  4. 04
    Ask for a dry-run option

    Have the AI add a mode that highlights target rows instead of deleting them on the first run. You confirm the logic against your real data before committing to deletion, which prevents losing rows you actually needed.

More example scenarios

#01 · Sales export with spacer rows between regions
Input
I have a monthly sales report exported from Salesforce. It has columns A:H with headers in row 1. Between each region's data there is one fully blank row. The file has about 8,000 rows total and I run this report every Monday. Give me a VBA macro I can save in my personal workbook.
Expected output
A VBA macro that loops from the last used row upward, checks WorksheetFunction.CountA on each row within A:H, and deletes rows where the count is zero. Includes Application.ScreenUpdating = False for speed, targets the active sheet, and preserves row 1. Instructions added for saving to PERSONAL.XLSB and assigning a Quick Access Toolbar button.
#02 · Power Query refresh for a finance dashboard
Input
My Power Query pulls from a SharePoint Excel file. After the source step, I have empty rows where the source had formatting gaps. I need the query to drop these automatically on every refresh. Give me the M code step to add.
Expected output
The M code step: = Table.SelectRows(#"Previous Step", each not List.IsEmpty(List.RemoveMatchingItems(Record.FieldValues(_), {"", null}))). Explanation that this removes rows where every column is blank or null, while keeping rows that have at least one real value. Instructions to paste it into the Advanced Editor after the source transformation.
#03 · CSV import with failed-record blanks
Input
I import a daily CSV of 200,000 survey responses. Failed submissions come through as rows with only a timestamp in column A and nothing else. I want to delete any row where columns B through Z are all empty, keeping only complete responses.
Expected output
A macro using AutoFilter on the range B:Z to filter for blanks across all those columns, then deletes the visible rows below the header in one batch operation (not row-by-row, which would be slow on 200k rows). Uses SpecialCells(xlCellTypeVisible) and handles the case where no blanks exist to avoid runtime errors.
#04 · Inventory sheet, no macros allowed
Input
Corporate IT blocks VBA. I have an inventory sheet where warehouse staff leave blank rows between SKU groups. I need a formula-based approach that gives me a clean copy of the data on a second sheet.
Expected output
A FILTER formula on Sheet2: =FILTER(Sheet1!A2:H1000, (Sheet1!A2:A1000<>"")+(Sheet1!B2:B1000<>"")+(Sheet1!C2:C1000<>"")>0). Explanation that adding the Boolean arrays with + creates an OR condition, so the row is kept if any key column has a value. Works in Excel 365 and Excel 2021.
#05 · Accounting reconciliation with partial blanks
Input
My GL export has rows that look blank but actually have a space character or a zero-width string. Go To Special does not catch them. I need to delete rows that are visually empty even if they contain whitespace.
Expected output
A macro that evaluates LEN(TRIM(CONCAT(row))) for each row in the used range and deletes the row when the result is 0. This catches spaces, tabs, and empty strings that standard blank-detection misses. Includes a dry-run mode that highlights target rows yellow first so you can verify before deletion.

Common mistakes to avoid

  • Deleting top-down instead of bottom-up

    Looping from row 1 downward and deleting as you go causes the loop to skip rows because indexes shift. Always loop from the last row upward, or use AutoFilter to batch delete.

  • Trusting ISBLANK on formula cells

    A cell containing =IF(A1="","",A1) returns an empty string, not a blank. ISBLANK returns FALSE and Go To Special skips it. Use LEN or COUNTA instead when your sheet has formulas.

  • Forgetting to turn off ScreenUpdating

    On large files, leaving Application.ScreenUpdating = True makes a 30-second operation take 10 minutes. Always wrap deletion macros with ScreenUpdating and Calculation set to manual, then restored at the end.

  • Running on the wrong sheet

    ActiveSheet-based code deletes rows on whatever tab the user happens to have open. Reference the sheet by name (Sheets("Data")) so the macro cannot destroy a different tab.

  • No backup before first run

    Save a copy of the file or use Ctrl+Z-testing on a duplicate before deploying any deletion macro. Row deletion cannot be undone once the workbook is saved and closed.

Related queries

Frequently asked questions

What is the fastest way to remove blank rows in Excel without a macro?

Select your data range, press F5, click Special, choose Blanks, then right-click any highlighted cell and pick Delete Entire Row. This is four clicks and works for most cases. It fails if your rows are only partially blank.

Can I remove blank rows automatically every time a file opens?

Yes. Put the deletion macro inside the Workbook_Open event in ThisWorkbook. The cleanup runs on every open. For files shared with colleagues, you will need to save as .xlsm and they must enable macros.

How do I remove blank rows in Excel Online or Excel for the web?

Excel on the web does not support VBA. Use the FILTER function to output a clean version on a new sheet, or use Power Automate to run an Office Script that deletes blank rows. Office Scripts work in the web version.

Why does Go To Special miss some of my blank rows?

Because those cells are not truly empty. They contain formulas returning "", space characters, or leftover formatting. Use a macro that evaluates LEN(TRIM(cell)) = 0 instead, which catches all visually empty cells.

Will deleting blank rows break my formulas?

Relative references adjust automatically. Absolute references like $A$50 will now point to different data if row 50 shifted. Check any formulas that use INDEX, OFFSET, or hardcoded row numbers before and after deletion.

How do I remove blank rows across multiple sheets at once?

Wrap the deletion logic in a For Each loop over Worksheets. The AI prompt on this page can generate that version if you specify 'apply to all sheets except Summary' or whichever tabs to skip.