How to delete every other row or every Nth row in Excel

This short tutorial explains how to delete every other row in Excel by filtering or with VBA code. You will also learn how to remove every 3rd, 4th or any other Nth row.

There are many situations when you may need to delete alternate rows in Excel worksheets. For example, you might want to keep data for even weeks (rows 2, 4, 6, 8, etc.) and move all odd weeks (rows 3, 5, 7 etc.) to some other sheet.

Generally, deleting every other row in Excel boils down to selecting alternate rows. Once the rows are selected, a single stroke on the Delete button is all it takes. Further on in this article, you will learn a few techniques to quickly select and delete every other or every Nth row in Excel.

How to delete every other row in Excel by filtering

In essence, a common way to erase every other row in Excel is this: first, you filter alternate rows, then select them, and delete all at once. The detailed steps follow below:

  1. In an empty column next to your original data, enter a sequence of zeros and ones. You can quickly do this by typing 0 in the first cell and 1 in the second cell, then copying the first two cells and pasting them down the column until the last cell with data.

    Alternatively, you can use this formula:

    =MOD(ROW(),2)

    The formula's logic is very simple: the ROW function returns the current row number, the MOD function divides it by 2 and returns the remainder rounded to the integer.

    As the result, you have 0 in all even rows (because they are divided by 2 evenly without remainder) and 1 in all odd rows:
    Identify every other row using a Mod formula.

  2. Depending on whether you want to delete even or odd rows, filter out ones or zeros.

    To have it done, select any cell in your Helper column, go to the Data tab > Sort and Filter group, and click the Filter button. The drop-down filter arrows will appear in all header cells. You click the arrow button in the Helper column and check one of the boxes:

    • 0 to delete even rows
    • 1 to delete odd rows

    In this example, we are going to remove the rows with "0" values, so we filter them:
    Filter the rows with 0 values.

  3. Now that all "1" rows are hidden, select all the visible "0" rows, right-click the selection and click Delete Row:
    Delete every other row in Excel
  4. The above step has left you with an empty table, but don't worry, the "1" rows are still there. To make them visible again, simply remove auto-filter by clicking the Filter button again:
    Remove filter in Excel.
  5. The formula in column C recalculates for the remaining rows, but you don't need it anymore. You can now safely delete the Helper column:
    The Mod formula recalculates for the remaining rows.

As the result, only the even weeks are left in our worksheet, the odd weeks are gone!
Every other row is deleted.

Tip. If you'd like to move every other row to somewhere else rather than delete them altogether, first copy the filtered rows and paste them to a new location, and then delete the filtered rows.

How to delete alternate rows in Excel with VBA

If you are not willing to waste your time on a trivial task such as deleting every other row in your Excel worksheets, the following VBA macro can automate the process for you:

Sub Delete_Alternate_Rows_Excel()
	Dim SourceRange As Range

	Set SourceRange = Application.Selection
	Set SourceRange = Application.InputBox("Range:", "Select the range", SourceRange.Address, Type:=8)

	If SourceRange.Rows.Count >= 2 Then
		Dim FirstCell As Range
		Dim RowIndex As Integer

		Application.ScreenUpdating = False

		For RowIndex = SourceRange.Rows.Count To 1 Step -2
			Set FirstCell = SourceRange.Cells(RowIndex, 1)
			FirstCell.EntireRow.Delete
		Next

		Application.ScreenUpdating = True

	End If
End Sub

How to delete every other row in Excel using the macro

Insert the macro in your worksheet in the usual way via the Visual Basic Editor:

  1. Press Alt + F11 to open the Visual Basic for Applications window.
  2. On the top menu bar, click InsertModule, and paste the above macro in the Module
  3. Press the F5 key to run the macro.
  4. A dialog will pop up and prompt you to select a range. Select your table and click OK:
    Remove alternate rows in Excel using a macro.

Done! Every other row in the selected range is deleted:
Every other row in the selected range is deleted at once.

How to delete every Nth row in Excel

For this task, we are going to expand the filtering technique that we've used to remove every other row. The difference is in the formula on which the filtering is based:

MOD(ROW()-m, n)

Where:

  • m is the row number of the first cell with data minus 1
  • n is the Nth row you want to delete

Let's say your data begins in row 2 and you want to delete every 3rd row. So, in your formula n equals 3, and m equals 1 (row 2 minus 1):

=MOD(ROW() - 1, 3)

If our data began in row 3, then m would equal 2 (row 3 minus 1), and so on. This correction is needed to sequentially number the rows, starting with the number 1.

What the formula does is divide a relative row number by 3 and return the remainder after division. In our case, it yields zero for every third row because every third number divides by 3 without remainder (3,6,9, etc.):
Formula to identify every third row in Excel

And now, you perform the already familiar steps to filter "0" rows:

  1. Select any cell in your table and click the Filter button on the Data
  2. Filter the Helper column to show only "0" values.
  3. Select all of the visible "0" rows, right-click and choose Delete Row from the context menu.
  4. Remove the filter and delete the Helper column.

Every third row is deleted.

In a similar fashion, you can delete every 4th, 5th or any other Nth row in Excel. I thank you for reading and hope to see you on our blog again next week.

You may also be interested in:

3 Responses to "How to delete every other row or every Nth row in Excel"

  1. Pieter says:

    Very useful article, particularly 'How to delete alternate rows in Excel with VBA'.

    How do I add a form (and any additional code) that allows me to change the set 'alternate rows' to 'delete every Nth row or N Rows'. Other than going into the VBA editor For every new requirement.

    What I have in mind is say a button that on click calls a simple form that allows me to change the Nth Row or and N Rows parameters or confirm the last entered values. Press OK, Then Runs the dialog that prompt me to select a range.

    Thanks

    also 'How to delete alternate rows in Excel with VBA' might be better at the end of the Article so that all the 'filtering' non VBA subjects were together.

  2. Ash says:

    I love you so much for this!! You literally saved me hours.

  3. Raj says:

    Thanks for the precious information..
    Will seek for other informations also.

Post a comment



Unfortunately, due to the volume of comments received we cannot guarantee that we will be able to give you a timely response. When posting a question, please be very clear and concise. We thank you for understanding!
Excel add-ins and Outlook tools - Ablebits.com
Ultimate Suite 2018.3 Summer Offer