Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.newusers
|
|||
|
|||
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 |
#2
Posted to microsoft.public.excel.newusers
|
|||
|
|||
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 |
#3
Posted to microsoft.public.excel.newusers
|
|||
|
|||
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 |
#4
Posted to microsoft.public.excel.newusers
|
|||
|
|||
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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
easy way to delete all rows with no text in them? | New Users to Excel | |||
resetting last cell | Excel Discussion (Misc queries) | |||
Question regarding how to search a column and print a row(s) | Excel Discussion (Misc queries) | |||
Inserting Rows w/formulas question | Excel Worksheet Functions | |||
easy question .... i think | Excel Discussion (Misc queries) |