|
Answer» Is there a way to delete everyother line of excel data containing about 1000+ lines...instead of individually going through and clicking every other row??There are a couple of ways to approach this. You could write a macro (VBA) that is stored and run from within the Excel application. You could write a script (VBS) that is stored and run external to the Excel application.
External script Code: [Select]Const xlUp = -4162 xlsPath = "c:\temp\test.xls" 'spreadsheet name
Set xlApp = CreateObject("Excel.Application") xlApp.Workbooks.Open xlsPath Set xlSheet = xlApp.ActiveWorkbook.Worksheets(1)
For i = 2 To xlSheet.UsedRange.Rows.Count xlSheet.Rows(i).Delete xlUp Next
With xlApp .DisplayAlerts = False .ActiveWorkbook.Save .ActiveWorkbook.Close .Quit End With
Be SURE to change xlsPath for your machine.
Save script with a vbs extension and run from the command prompt: cscript scriptname.vbs
As written, all even numbered rows will be deleted. Initialize i to 1 to delete odd number rows.
Warning: Script overwrites the source spreadsheet, you may want to change this.Hm, that may work, but probably looks pretty daunting if the questionner isn't facile with scripts and such. Often, in Excel, there is a simpler way to do things using the spreadsheet commands themselves.
Try this:
1. Save the FILE someplace under a different name, in CASE something goes awry. 2. Create two new columns. 3. In the first, put a series of numbers from 1 to the total N. You can type 1, 2, 3, 4 in the first four cells, highlight them, then grab the LITTLE + at the lower right of the cells to drag them down. Excel will continue the number sequence for you. Do NOT use formulas in the cells for numbers. We need these to be actual numbers that will stay what they are even when sorted.
4. In the second blank column, put this equation. I will pretend the first new column was C and this one is D. =iseven(C1). This should return "FALSE" for "1". Copy/paste the equation down the column. It now shows "FALSE" and "TRUE" alternately. It just asks if the number in the column to the left "is even" or not!
5. Highlight (Select) the entire file. All lines and columns with data.
6. Sort by the column with true false in it. You now have all the false lines first, then all the true lines.
7. Delete either the true lines or the false ones.
8. Select the entire file again.
9. Sort by the ID we created in step 3.
Voila, half the lines are gone and your file is back in the original order.
Let us know which of these solutions (if either) you used!
Ed
|