![]() |
Easy Question for deleting rows.
I have a report that varies in length each day. I have information at the
end of the report I want to program to delete in an existing macro. What code would I use to delete the last 5 lines at the end of the report. The code would go in the active sheet in an existing macro. Thanks so much |
Easy Question for deleting rows.
One way to do this
This example find the last row with data on the sheet with the function Sub test() Range("A" & LastRow(ActiveSheet) - 4).Resize(5).EntireRow.Delete End Sub Function LastRow(sh As Worksheet) On Error Resume Next LastRow = sh.Cells.Find(What:="*", _ After:=sh.Range("A1"), _ Lookat:=xlPart, _ LookIn:=xlFormulas, _ SearchOrder:=xlByRows, _ SearchDirection:=xlPrevious, _ MatchCase:=False).Row On Error GoTo 0 End Function -- Regards Ron De Bruin http://www.rondebruin.nl "SITCFanTN" wrote in message ... I have a report that varies in length each day. I have information at the end of the report I want to program to delete in an existing macro. What code would I use to delete the last 5 lines at the end of the report. The code would go in the active sheet in an existing macro. Thanks so much |
Easy Question for deleting rows.
Try
Dim LastRow As Long LastRow = Cells(Rows.Count, "A").End(xlUp).Row Range(Cells(LastRow - 4, "A"), Cells(LastRow, "A")).EntireRow.Delete -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com "SITCFanTN" wrote in message ... I have a report that varies in length each day. I have information at the end of the report I want to program to delete in an existing macro. What code would I use to delete the last 5 lines at the end of the report. The code would go in the active sheet in an existing macro. Thanks so much |
Easy Question for deleting rows.
or
Sub deletelast5rows() lr = Cells(Rows.Count, "a").End(xlUp).Row Rows(lr - 4).Resize(5).Delete End Sub -- Don Guillett SalesAid Software "SITCFanTN" wrote in message ... I have a report that varies in length each day. I have information at the end of the report I want to program to delete in an existing macro. What code would I use to delete the last 5 lines at the end of the report. The code would go in the active sheet in an existing macro. Thanks so much |
All times are GMT +1. The time now is 04:00 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com