vba to delete last row from a table

dpaton05

Well-known Member
Joined
Aug 14, 2018
Messages
2,352
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
What is the vba code I can add to a button to delete last row from a table?
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Without details (Sheet name, address of start cell of table etc) and unable to see your PC screen as you see it, try adjusting following:
Rich (BB code):
Sub DelLR()

Dim x as Long

With Sheets("Sheet1")
'Assumes last row of data found in column A (1)
  x = .Cells(.Rows.Count, 1).End(xlUp).Row
  .Cells(x, 1).EntireRow.Delete
End With

End Sub
 
Upvote 0
Just assign a button to below code

Code:
Sub lastrowdel()
Dim lastrow As Long
Dim sht As Worksheet


Set sht = ActiveSheet


lastrow = sht.ListObjects("Table1").Range.Rows.Count
Rows(lastrow).Delete
End Sub
 
Last edited:
Upvote 0
Just assign a button to below code

Code:
Sub lastrowdel()
Dim lastrow As Long
Dim sht As Worksheet


Set sht = ActiveSheet


lastrow = sht.ListObjects("Table1").Range.Rows.Count
Rows(lastrow).Delete
End Sub
And change the "Table1" name to your table.
 
Upvote 0
Try this:
Code:
Sub Delete_Table_Lastrow()
'Modified  8/29/2018  8:49:18 AM  EDT
Dim ans As Long
    With ActiveSheet.ListObjects("Table1").Range
        ans = .Rows.Count
        .Rows(ans).Delete
    End With
End Sub
 
Upvote 0
When you find code works, I'm glad someone here could help and come back to Mr. Excel next time you need additional assistance :)
 
Upvote 0
Deleting cells from the bottom of a table

I have a table in excel and a button to delete rows from the table. Rows get deleted from the top of the table but I want rows from the bottom of the table to be deleted. How can I change this code so rows will get deleted from the bottom?

Private Sub CommandButton2_Click()
Dim ws As Worksheet
Set ws = ActiveSheet
Dim tbl As ListObject
Set tbl = ws.ListObjects("npss_quote")
tbl.ListRows(1).Delete
End Sub


Thanks,
Dave
 
Upvote 0
Re: Deleting cells from the bottom of a table

In case anyone finds this thread looking for the answer, I found it. This is it:

Private Sub CommandButton2_Click()

Dim oLst As ListObject

If ActiveSheet.ListObjects.Count > 1 Then
For Each oLst In ActiveSheet.ListObjects
With oLst
If .Name = "npss_quote" Then
If oLst.ListRows.Count > 1 Then
number_of_columns = .ListColumns.Count
oLst.ListRows(oLst.ListRows.Count).Delete
End If
End If
End With
Next

End If

End Sub
 
Last edited:
Upvote 0
Re: Deleting cells from the bottom of a table

Try this:
Code:
Private Sub CommandButton2_Click()
'Modified  8/30/2018  7:27:44 PM  EDT
    
    With ActiveSheet.ListObjects("npss_quote").DataBodyRange
        ans = .Rows.Count
        .Rows(ans).Delete
    End With
End Sub
 
Upvote 0
Re: Deleting cells from the bottom of a table

Thankyou, that code works perfectly :)
 
Upvote 0

Forum statistics

Threads
1,215,348
Messages
6,124,425
Members
449,157
Latest member
mytux

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top