Finding and Deleting last row

B

Bourbon

Hi, I'm learning VB and have a problem. It is very simple: I have
spread sheet for which I am writing a macro to 1) Delete the content
of the first row...this is done and then 2) find the last row wit
content and delete the content. I am having trouble writing the cod
for 2....

I have : lastrow.select
selection.clearcontents

Can anyone help?

Regard
 
T

Trevor Shuttleworth

Sub ClearLastRow()
' assuming column A has data in all rows ...
Range("A65536").End(xlUp).EntireRow.ClearContents
End Sub

Regards

Trevor
 
R

Ron de Bruin

Examples that are working for the activesheet

If you can check one column you can use this example for column A

Sub test()
Dim LR As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
Cells(LR, "A").EntireRow.Delete
End Sub

If you want to delete the last row with data on the sheet use this
example with the function

Sub testing()
Cells(LastRow(ActiveSheet), "A").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
 

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

Top