Delete row from table

swas

New Member
Joined
Jun 11, 2020
Messages
2
Office Version
  1. 2016
  2. 2013
  3. 2010
Platform
  1. Windows
Hi,

I am very new to Excel vba but comfortable with Access vba.

I'm trying to search for a value in MyLookupColumn then delete the entire row in a named table in a worksheet. I have tried several methods but for some reason the delete doesn't complete - it executes but nothing happens.

Sample code is here:

Dim tbl As ListObject
Dim lr as ListRow

Worksheets("Data").Activate
Set tbl = ActiveSheet.ListObjects("DataT")

For Each lr In tbl.ListRows
If lr.Range(MyLookupColumn) = 35 Then '35 is a hard coded example for here. Exists in table.
'Delete - this code executes for 35
'lr.Delete 'Executes but doesn't delete row (Or anything from what I can see)
'Or
tbl.ListRows(35).Delete 'Executes but doesn't delete row (Or anything from what I can see)
Exit For
End If
Next

I've also tried some code that selects ranges etc... but I struggle with Excel vba referencing for the moment, and don't see it necessary to go that path.

This strikes me as pretty straight forward code, and there are lots of examples about (Inc here) but alas no result.

Appreciate any help.

swas
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Selection.EntireRow.Delete
or
lr.EntireRow.Delete

should work
 
Upvote 0
Thanks for the response but no good.

Selection.EntireRow.Delete
or
lr.EntireRow.Delete

Neither lr or Selection have a method / property .EntireRow

Selection = nothing (No properties / methods).

tbl.selection doesn't exist.

Thanks

swas
 
Upvote 0

Forum statistics

Threads
1,214,593
Messages
6,120,435
Members
448,961
Latest member
nzskater

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