This article was written by Darlene Antonelli, MA. Darlene Antonelli is a Technology Writer and Editor for wikiHow. Darlene has experience teaching college courses, writing technology-related articles, and working hands-on in the technology field. She earned an MA in Writing from Rowan University in 2012 and wrote her thesis on online communities and the personalities curated in such communities.
This article has been viewed 1,508 times.
This wikiHow will teach you how to use a macro with Microsoft Visual Basic for Applications to delete every other row in an Excel worksheet.
Steps
Method 1
Method 1 of 2:Using a Formula and Filter
-
1Open a project in Excel. This method works for the current Excel as well as previous versions.
- You can either click on an Excel file to open it or create a new one.
-
2Select a column after your data. If you have data in cells A1-A9 and B1-B-9, you'll want to use column C to insert your formula.Advertisement
-
3Enter the following code into cell C1: "=ISEVEN(ROW())." As you type that into the function bar, you'll see suggestions pop-up for the formula; selecting one of these ensures you're spelling it correctly.
- You'll see that every even row is labeled "True" and every false row comes back "False" so you can quickly determine which rows to delete.
-
4Drag and drop the formula from C1 to C9. You want to make sure your entire range is covered.
-
5Click the Data tab. You'll see this at the top of your worksheet.
-
6Click Filter. You'll see this with an icon of a filter in the Sort & Filter grouping.
-
7
-
8Click to uncheck "True" or "False." Hiding one of these will display every other column of information. You'll want to display the rows that you're going to delete.
- Click Ok to continue.
-
9Select all the visible data. You can drag and drop around the range of data or press Ctrl + A (Windows) or Cmd + A (Mac).
-
10Right-click the selected data and select Delete Row. All that data will be deleted, and the other rows are hidden.[1]
-
11Unhide your data. Go back to the Data tab and click Filter and your filters will be removed, displaying your original data.
- Delete column C to remove that data and label.
Advertisement
Method 2
Method 2 of 2:Using Visual Basic for Applications
-
1Open a project in Excel. This method works for the current MS Excel to Excel 2007 and you can use a saved project or create a new one and enter data into some cells.
-
2Click Tools. For certain older versions of Excel, you'll access the "Developer" tab instead.
-
3Click Visual Basic Editor. You should see this as the leftmost icon in the menu.
-
4Right-click a sheet. In the vertical menu on the left side of the window, you'll see a list of your workbook's sheets. Right-click on any of these to get another drop-down menu.
-
5Hover your cursor over Insert and click Module. When you hover over Insert, a menu will pop-out to the right of the menu. Clicking on Module will create a space for you to enter a VBA code and run it.
-
6Enter the following in your VBA window:
Sub Delete_Every_Other_Row() Dim Rng As Range Set Rng = Application.InputBox("Select the Range (Excluding headers)", "Range Selection", Type:=8) For i = Rng.Rows.Count To 1 Step -2 If i Mod 2 = 0 Then Rng.Rows(i).Delete End If Next i End Sub -
7Press F5. This will run the code and another window will pop-up.
-
8Select the range of data and click OK. If you have data in cells ranging from A1-B9, you can drag and drop over those cells to select them. [2]Advertisement
About This Article
1. Open a project in Excel.
2. Select a column after your data.
3. Enter the following code into cell C1: "=ISEVEN(ROW())".
4. Drag and drop the formula from C1 to C9.
5. Click the Data tab.
6. Click Filter.
7. Click the arrow next to the column header in column C.
8. Click to uncheck either "True" or "False."
9. Select all the visible data.
10. Right-click the selected data and select Delete Row.
11. Unhide your data.




























































