Delete Rows

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have this code for deleting the last row inserted from a form. I need to
edit this so as to ignore the first row. How could I do this?
Private Sub CommandButton6_Click()
Dim LastRowOnSheet As Long

LastRowOnSheet = Sheets("Sheet1").UsedRange.Rows.Count +
Sheets("Sheet1").UsedRange.row - 1
Sheets("Sheet1").Cells(LastRowOnSheet, 1).EntireRow.Delete


End Sub
 
Hi Enyaw,

Try:

'=============>>
Private Sub CommandButton6_Click()
Dim LastRowOnSheet As Long

With ActiveWorkbook.Sheets("Sheet1")
LastRowOnSheet = .UsedRange.Rows.Count _
+ .UsedRange.Row - 1
If LastRowOnSheet > 1 Then _
Rows(LastRowOnSheet).Delete
End With

End Sub
'<<=============
 

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