delete row

  • Thread starter Thread starter DF
  • Start date Start date
D

DF

Is there a way to automatically locate the last row with
data and delete it?
 
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
 
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
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top