Search : in
By :

Delete all rows except first and last row

Last answer on Nov 14, 2008 4:15:11 am GMT urgentMe, on Nov 14, 2008 3:56:40 am GMT 
 Report this message to moderators

Hello,

I have an excel file, I need to delete all rows in this file except for the first and second row.
First Row = header row
last row = contains total value of the items in header row

thanks

Configuration: Windows XP
Firefox 3.0.4

Best answers for « delete all rows except first and last row » in :
Deleting your skyblog ShowDeleting your skyblog More info Below is a tip on how to delete your skyblog. First of all, sign in on the website Skyrock at the top right of your window. Then choose My account. Click on the Remove tab. Enter your...
[Sed] Delete one or more lines from a file Show[Sed] Delete one or more lines from a file Removing one (or several) line (s) of a file Syntax: sed '{[/]||[/]}d' sed '{[/][,][/]d' /.../=delimiters n = line number...
[Ubuntu]Preventing recovery of deleted files Show[Ubuntu]Preventing recovery of deleted files Here below is a simple method, on how preventing the recovery of deleted files: First, make sure the recycle bin of Nautilus (the file browser) is empty. Right click on it and choose the...
The keyboard ShowIntroduction to the keyboard The keyboard, like a typewriter, is used for entering characters (such as letters, numbers, and symbols). It is an essential input device for a computer, as it is what lets us enter commands. The term "QWERTY" (after...
ASCII Code ShowData coding Morse code was the first code used for long-distance communication. Samuel F.B. Morse invented it in 1844. This code is made up of dots and dashes (a sort of binary code). It was used to carry out communication much faster than could...

1

 urgentMe, on Nov 14, 2008 4:15:11 am GMT
  • +2

I just have this code that will return no. of row of the first and last column. now, I want to delete other rows. Maybe someone could help me manipulate/ edit this code:

Sub Test_xlFirstLastRows()
     
     '       Target Application:  MS Excel
     '       Demonstration:  display first and last non-blank rows in the active sheet
     '                       and one target sheet
     
    Dim SheetName As String
     '
     '           display sheet name and results from xlFirstRow and xlLastRow
     '           for the active sheet.  Since activesheet is assumed if procs are called
     '           without a passed arguement, use that method here
     '
    MsgBox "Worksheet name = " & ActiveSheet.Name & vbCrLf & _
    "First non-blank row = " & xlFirstRow & vbCrLf & _
    "Last non-blank row = " & xlLastRow, vbInformation, _
    "Active Sheet Demonstration"
     '
     '           display sheet name and results from xlFirstRow and xlLastRow
     '           for "Sheet4".  Since this is not the active sheet, the sheet must
     '           be defined via the passed arguement.
     '
    SheetName = "Sheet4"
    MsgBox "Worksheet name = " & SheetName & vbCrLf & _
    "First non-blank row = " & xlFirstRow(SheetName) & vbCrLf & _
    "Last non-blank row = " & xlLastRow(SheetName), vbInformation, _
    "Passed Sheet Name Demonstration"
     
     
End Sub

Function xlFirstRow(Optional WorksheetName As String) As Long
     
     '    find the first populated row in a worksheet
     
    If WorksheetName = vbNullString Then WorksheetName = ActiveSheet.Name
    With Worksheets(WorksheetName)
        On Error Resume Next
        xlFirstRow = .Cells.Find("*", .Cells(.Cells.Count), xlFormulas, _
        xlWhole, xlByRows, xlNext).Row
        If Err <> 0 Then xlFirstRow = 0
    End With
     
End Function
 
Function xlLastRow(Optional WorksheetName As String) As Long
     
     '    find the last populated row in a worksheet
     
    If WorksheetName = vbNullString Then WorksheetName = ActiveSheet.Name
    With Worksheets(WorksheetName)
        On Error Resume Next
        xlLastRow = .Cells.Find("*", .Cells(1), xlFormulas, _
        xlWhole, xlByRows, xlPrevious).Row
        If Err <> 0 Then xlLastRow = 0
    End With
     
End Function

Reply to urgentMe