Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.newusers
SITCFanTN
 
Posts: n/a
Default 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   Report Post  
Posted to microsoft.public.excel.newusers
Ron de Bruin
 
Posts: n/a
Default 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   Report Post  
Posted to microsoft.public.excel.newusers
Chip Pearson
 
Posts: n/a
Default 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   Report Post  
Posted to microsoft.public.excel.newusers
Don Guillett
 
Posts: n/a
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
easy way to delete all rows with no text in them? george edgar New Users to Excel 2 May 13th 06 07:54 PM
resetting last cell jagdish.eashwar Excel Discussion (Misc queries) 11 March 31st 06 02:06 AM
Question regarding how to search a column and print a row(s) PegL Excel Discussion (Misc queries) 0 July 15th 05 03:15 PM
Inserting Rows w/formulas question Buckwheat Excel Worksheet Functions 4 May 7th 05 10:05 PM
easy question .... i think Dean Excel Discussion (Misc queries) 1 January 6th 05 06:31 PM


All times are GMT +1. The time now is 12:09 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"