How to Delete every other row or every Nth row in ExcelIn your Excel life, many situations occur when you want to delete alternate rows or every other row in your worksheets. For example, you have been asked to share the data of every alternate month (rows carrying data for Jan, Mar, May, Jul, Sep, and Nov) and want to shift the remaining data to another worksheet. The easy way to get this done is to select every alternate row in your worksheet and delete them with a single click. Though this method generally works, in this tutorial, we will also cover other techniques that will quickly select and delete every alternate or every nth row. Topics Covered:
Delete every other row in Excel using filtering methodThe quick and easy method to delete every other row is to filter the alternate rows, select them and delete them together. Perform the following steps to delete every other row in Excel using the filtering method:
The explanation of above formula is very easy. The Excel ROW function yields the current row number, the MOD function divides the row number by 2 and returns the remainder rounded to the integer.
Select '0 to delete every row' option.
Note: Once you unfiltered the rows, you may get the sequence of 0 and 1 again, as the formula applied in column C recalculates the mod for the remaining rows, but our job is done, so we don't require it anymore.
Simple, isn't it? Let's move to the next technique, where we will delete every alternative row using VBA coding. How to delete alternate rows in Excel with VBAIf you are someone interested in coding and love to work on advanced Excel, you can also work on Excel VBA and create your form using macro. It also benefits when you create a table for someone else; your users may not know where to look for the Form button. Moreover, many people still don't know that something like that exists in Microsoft Excel. To put more focus on this feature, you can directly code it on VBA macro, and put a special button directly on the Excel worksheet to run that macro. Follow the below steps.
CODE: Once you are done, writing the program, the next step is to run the VBA code. Let's have a look how to run the created macro in Excel worksheet. How to delete every other row in Excel using the macroFollowing are steps to insert the macro in your Excel worksheet with the help of VBA editor:
Quick and easy, right! so far in this tutorial we covered different methods to delete every other row, what if we want to delete Nth row in Excel worksheet. Steps to delete every Nth row in ExcelDeleting every Nth row, is an updated version of the filtering technique to delete every other row. With a little twist in the above mod formula, we can expand the filtering technique to delete every nth row. The formula is shown below: Where:
Example 1: Let's say you have the following data (starting from row 2) and you are asked to delete every 4rd row. We will use the above formula, wherein n will be equal to 4 and m will be equal to 1. Therefore, the formula becomes: Following are steps to insert the macro in your Excel worksheet with the help of VBA editor:
The above formula will divide the row number by four and return the remainder in the selected cell after every division. For example, in our case, it returns zero after dividing every fourth row because every 4th row divides by four without remainder (4,8,12, etc.).
Following the similar technique, you can delete every 6th, 5=7th or any other Nth row in Microsoft Excel. Next TopicHow to extract text from Excel cells |