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
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