How to Delete Blank Rows and Shift Data Up in Excel: Using Filter, Go To Special, and VBA Methods

スポンサーリンク
スポンサーリンク

How to Delete Blank Rows and Shift Data Up?

Blank rows in Excel can make it difficult to analyze or summarize data. By deleting these blank rows and shifting the data up, you can keep your sheet organized. This article explains how to efficiently delete blank rows in Excel.

Method 1: Using Filters to Delete Blank Rows

You can use the filter feature to quickly delete blank rows and shift the data up.

Steps

  1. Select the data range that includes blank rows (e.g., A2:A20).
  2. Go to the “Data” tab and click “Filter” to enable filtering.
  3. In the filter dropdown menu, select “Blanks” to display only blank rows.
  4. Select all blank rows, right-click, and choose “Delete.”
  5. Remove the filter and confirm that the data has shifted up.

Method 2: Using Go To Special to Delete Blank Rows

The “Go To Special” feature lets you quickly select all blank cells in a range, enabling you to delete blank rows in bulk.

Steps

  1. Select the data range (e.g., A2:A20).
  2. Go to the “Home” tab, click “Find & Select,” and choose “Go To Special.”
  3. In the dialog box, select “Blanks” and click “OK” to highlight all blank cells.
  4. Right-click the highlighted cells, select “Delete,” and choose “Entire Row” to remove the blank rows.

Method 3: Using VBA to Delete Blank Rows Efficiently (Recommended)

If there are many blank rows, using a VBA macro can help automate the process.

Steps

  1. Go to the “Developer” tab and click “Visual Basic” to open the VBA editor.
  2. Select “Insert” → “Module” and enter the following code:

VBA Code:

Sub DeleteEmptyRows()
    Dim LastRow As Long
    Dim i As Long
    LastRow = Cells(Rows.Count, 1).End(xlUp).Row
    For i = LastRow To 1 Step -1
        If Application.WorksheetFunction.CountA(Rows(i)) = 0 Then
            Rows(i).Delete
        End If
    Next i
End Sub

Explanation of the VBA Code

  • LastRow: Retrieves the last row containing data.
  • For i = LastRow To 1 Step -1: Loops through rows from the bottom to the top.
  • CountA(Rows(i)) = 0: Checks if all cells in the row are blank. If true, the row is deleted.

Example

In the table below, column A contains some blank rows. Deleting these blank rows shifts the data up.

A B
1 Data1 Value1
2
3 Data2 Value2
4
5 Data3 Value3

Result

  • Blank rows are removed, and the data is shifted up.

Summary

To delete blank rows and shift data up in Excel, you can use the filter feature, the Go To Special tool, or a VBA macro. Choose the method that best suits your dataset and workflow requirements.