#1   Report Post  
Posted to microsoft.public.excel.programming
DF DF is offline
external usenet poster
 
Posts: 1
Default delete row

Is there a way to automatically locate the last row with
data and delete it?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default delete row

Hi DF

This will delete the last row on the activesheet
Copy the macro and the function in a normal module

Sub test()
Dim Lr As Long
Lr = LastRow(ActiveSheet)
ActiveSheet.Rows(Lr).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


"DF" wrote in message ...
Is there a way to automatically locate the last row with
data and delete it?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default delete row

The following code will delete the last row that has data in
column A. Change the column reference to suit your needs.

Cells(Rows.Count, "A").End(xlUp).EntireRow.Delete



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"DF" wrote in message
...
Is there a way to automatically locate the last row with
data and delete it?



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default delete row

Dim rng as Range, lastrow as Range
set rng = Activesheet.UsedRange
lastrow = rng.rows(rng.rows.count).row
Cells(lastRow,1).EntireRow.Delete

would be a possibility.

or

Dim rng as Range
set rng = Activesheet.usedRange
rng.rows(rng.rows.count).EntireRow.Delete

--
Regards,
Tom Ogilvy

"DF" wrote in message
...
Is there a way to automatically locate the last row with
data and delete it?



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
How can I delete a macro when the Delete button is not active? FCR Excel Worksheet Functions 0 March 9th 06 09:43 AM
How to Delete a Range in Closed Workbook (to Replace Delete Query) [email protected] Excel Discussion (Misc queries) 1 March 8th 06 10:10 AM
How do i delete a macro in Excel 2003 when delete isn't highlight Abel Excel Discussion (Misc queries) 2 September 13th 05 04:09 AM
How to delete rows when List toolbar's "delete" isnt highlighted? Linda Excel Worksheet Functions 1 May 26th 05 08:39 PM


All times are GMT +1. The time now is 12:50 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"