1

Is it possible in VBA to DELETE all the rows meeting condition from Excel ListObject table? I am looking for something similar to SQL statement:

DELETE FROM MyListObjectTable WHERE MyColumn='Some Condition'

6
  • Is it connected to a source? Do you want to delete them from the source? If not I'd use the condition <> in the sql for the table. Have you tried anything? Commented Mar 28, 2017 at 11:05
  • It it connected to SQL, however I can break that connection, if necessary. I tried to make it through ADO Connection similar to the idea you can find here: stackoverflow.com/a/33807584/1903793 Commented Mar 28, 2017 at 11:28
  • use the listobject.querytable.connection to create the ado and execute the sql you have, then refresh the table. Commented Mar 28, 2017 at 11:33
  • if some condition exists in C3 then Set listObj = ActiveSheet.ListObjects("Table1") -next line - listObj.ListRows(3).Delete Commented Mar 28, 2017 at 13:50
  • @JohnMuggins I have a huge table. I would like make bulk deletes, not single or looplike. Better from your proposal would be deleting with auto-filter. However SQL-like statements are much more superior for the sake of clarity. Commented Mar 28, 2017 at 14:03

1 Answer 1

1

Try this:

.- Break the connection,

.- Sort the ListObject as per condition (Optional just to have the results of the condition in one Range.Area for the deletion),

.- AutoFilter the ListObject as per condition,

.- Delete visible rows of the ListObject.DataBodyRange

.- Clear AutoFilter

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.