Sunday, February 20, 2011

How to Delete Every Other Row Automatically in Excel 2003


1. Open a new workbook in Excel and type the number '1' in cell A1. Skip cell A2 and type '2' in cell A3. Repeat this process until you have the numbers 1 through 5 entered in cells A1 through A9. The following cells should have the following numbers: '1' for A1, '2' for A3, '3' for A5, '4' for A7 and '5' for A9.
2. Click 'Tools' and select 'Macro.' Click on 'Visual Basic Editor.'
3. Select the 'Insert' tab and click 'Module.'
4. Copy the following macro and paste it in the Visual Basic sheet: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 = 1Set 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 1End If' If Y is True, make it False; if Y is False, make it True.Y = Not YNext xCounterEnd Sub
5. Click 'Close and Return to Microsoft Excel' to exit, then test the macro by highlighting rows A1 through A9 on the Excel spreadsheet you made earlier. Click 'Tools,' then 'Macro' and then click 'Macros.'
6. Select 'Delete_Every_Other_Row' from the Macro menu and click 'Run.' The alternate rows will be deleted and numbers 1 through 5 will now be displayed in cells A1 through A5.

Blogger news