+ Reply to Thread
Results 1 to 3 of 3

macro to delete last 5 rows

Hybrid View

  1. #1
    Registered User
    Join Date
    10-01-2004
    Location
    London
    Posts
    8

    macro to delete last 5 rows

    hi

    every week I get a new spreadsheet created by CRM software. The CRM adds 5 superfluous lines at the foot of the sheet, in column A. I'm trying to automate removal of these 5 lines.

    I created a simple macro to do this as the footer text is the same every week, so is easy enough to locate. The issue is that the size of the spreadsheet varies from week to week. Does anyone have any code to automate the removal of the last n rows of a sheet?

    many thanks.

    Julian

  2. #2
    Forum Contributor
    Join Date
    12-12-2005
    Posts
    667
    Function LastRow()
    If WorksheetFunction.CountA(Cells) > 0 Then
    LastRow = Cells.Find(What:="*", After:=[A1], _
    SearchOrder:=xlByRows, _
    SearchDirection:=xlPrevious).Row
    End If
    End Function

    Sub DeleteRows()
    Rows(LastRow - 4 & ":" & LastRow).Select
    Selection.Delete Shift:=xlUp
    Range("A1").Select
    End Sub
    Best regards,

    Ray

  3. #3
    Registered User
    Join Date
    10-01-2004
    Location
    London
    Posts
    8
    Thanks Ray, that works a treat though not sure why or how; I've got a lot to learn about VBA.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1