PDA

View Full Version : Excel VBA - Delete last row containing data



Vlad25
02-25-2014, 07:24 AM
Hello,

I would like to delete the last non-empty row on a worksheet - seems quite simple but I haven't managed to make it work !

Using the Record Macro function, I get this :


Sub Macro6()
Rows("63:63").Select
Selection.Delete Shift:=xlUp
End Sub

In my exemple, the row I want to delete is 63, so I'd need to replace it by the actual last row number...how can I do that ?

Thanks !

DeadKing
02-25-2014, 08:03 AM
Hi,

if you can tell which column will contain data at the last row, you can do something like this this:


Sub Macro()
Dim lastRow as integer
lastRow = Worksheets(1).Range("A65536").End(xlUp).Row
Worksheets(1).Rows(lastRow & ":" & lastRow).Delete shift:=xlUp
end sub

Ago
02-25-2014, 08:18 AM
LastRow = Range("A" & Rows.Count).End(xlUp).Row
Is better as it doesn't limit you to 65536 rows.

In older versions of Excel it was enough, but now sheets can be longer.

mancubus
02-25-2014, 08:59 AM
http://www.vbaexpress.com/forum/content.php?143-The-Last-Row

snb
02-25-2014, 09:15 AM
sub M_snb()
sheets("feuille1").cells(rows.count,1).end(xlup).entirerow.delete
end sub