Excel: delete every second line - is that possible?
With Microsoft Excel you can automatically delete every second line. In this practical tip, we will explain how this works.
Preliminary: Show developer tools to delete every two lines
- Click the Office button in the top left, then select "Excel Options".
- Go to "Frequently used". Under "The most common options when working with Excel", enable the option "Show developer tab in the ribbon".
- Confirm the change with "Save".
Excel: Have every second line deleted with program code
Microsoft has released a program code for this purpose, which you can use. Proceed as follows:
- Open the file in which the corresponding table data is located.
- Now click on "Developer Tools" and under "Code" go to "Visual Basic".
- The Visual Basic Editor now opens. Here click on "Insert" and there on "Module".
- Copy the following code (without the quotation marks) into the module: "Sub Delete_Every_Other_Row () 'Dimension variables. Y = False' Change this to True if you want to 'delete rows 1, 3, 5, and so on. I = 1 Set xRng = Selection 'Loop once for every row in the selection. For xCounter = 1 To xRng.Rows.Count' If Y is True, then ... If Y = True Then '... delete an entire row of cells. xRng.Cells (I) .EntireRow.Delete 'Otherwise ... Else' ... increment I by one so we can cycle through range. I = I + 1 End If 'If Y is True, make it False; if Y is False, make it True. Y = Not Y Next xCounter End Sub "
- Now go back to your Excel file and mark the columns from which every second row should be deleted.
- Then click on "Macros" under "Developer" in the "Code" area. There you will see the macro "Delete_Every_Other_Row", which you start with "Execute".
This practical tip was realized with Excel 2007. With Excel you can also calculate the compound interest or a three-rate rate.