Delete List Row

Papi

Well-known Member
Joined
May 22, 2007
Messages
1,592
When I use a list in 2003 I use the shortcut Alt > E > W to delete one row. When I record the same keystrokes it converts that to
Selection.ListObject.ListRows(14).Delete
. That unfortunately is row specific. Any idea how to delete a row using a list (or selected rows) using VBA?
Thanks
 
Last edited:

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Thanks Al Chara,

Unfortunately the section is inside a 2003 workbook and there is data to the left that cannot be deleted.
 
Upvote 0
The following code will delete the selected row of a table. If more than one row is selected, only the first row of the selection will be deleted.

Code:
Dim MySelection As Range
Dim MyList As ListObject

Set MySelection = Selection
Set MyList = MySelection.ListObject
MySelection.ListObject.ListRows(MySelection.Row - MyList.Range.Row).Delete

Let me know if this doesn't work in Excel 2003 and I'll try to make the necessary modifications.
 
Last edited:
Upvote 0
Code:
Dim MySelection As RangeDim MyList As ListObject
Dim MyRow As ListRow


Set MySelection = Selection
With MySelection
    Set MyList = .ListObject
    Set MyRow = .ListObject.ListRows(.Row - MyList.Range.Row)
    If MyRow.Index <> .ListObject.ListRows.Count Then MyRow.Delete
End With
 
Upvote 0
Hello Allan,

This is great. Sorry to bother you on this last point. The delete works great but if the list expands by one row waiting for the next row then it will not delete the last row (which is exactly what I asked for). Can it go down one more row? If not, no worries, we can do it manually.
 
Upvote 0
Hello Allan,

This is great. Sorry to bother you on this last point. The delete works great but if the list expands by one row waiting for the next row then it will not delete the last row (which is exactly what I asked for). Can it go down one more row? If not, no worries, we can do it manually.

Not sure I'm following you on this last point. What do you mean by "Can it go down one more row?"
 
Upvote 0
The macro does exactly what I asked but I was not thinking about the filter (not sure what they call it) but when the list is on and the cursor is placed at the bottom of the list, the list carries on with formulas etc. If we get to the last row with data it will not delete that row as that is the last row. Does this make sense?
 
Upvote 0

Forum statistics

Threads
1,215,338
Messages
6,124,360
Members
449,155
Latest member
ravioli44

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