VBA to delete the last row in a table if the value in column a is blank

alisser

New Member
Joined
Jan 10, 2009
Messages
12
Help! I am trying to find a VBA solution to allow users to delete one or more rows at the bottom of an excel table (preferrably one row at a time); i.e. users may have inadvertently added new rows that they now want to delete before finalizing the report. The worksheet is protected.

Below is the VBA I am using (a VBA newbie) to allow users to add a new row.

Sub AddRows()
Dim oListCol As ListRow
Dim x As Integer, i As Integer

'check if any lists on this sheet
x = ActiveSheet.ListObjects.Count
If x > 0 Then
For i = 1 To x
'Add new row to list
Set oListCol = ActiveSheet.ListObjects(i).ListRows.Add
Next i
End If
End Sub

Any help or suggestions are appreciated.
Thanks!
-Alisser
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Try this:
Code:
Sub StripLastRwOneAtATime()
Dim oLst As ListObject

Application.ScreenUpdating = False
ActiveSheet.Unprotect Password:="your pswd"
If ActiveSheet.ListObjects.Count > 0 Then
    For Each oLst In ActiveSheet.ListObjects
        If oLst.ListRows.Count > 0 Then
          oLst.ListRows(oLst.ListRows.Count).Delete
        End If
    Next oLst
End If
ActiveSheet.Protect Password:="your pswd"
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,368
Messages
6,124,523
Members
449,169
Latest member
mm424

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