Ran into an unexpected issue with conditional Table row delete. I have two tables with each checking the other for contents (with ISNUMBER & MATCH formula). I'm trying to delete all table rows from Table MASTER where ID value doesn't exist in Table QUERY - easy enough.
After launching the code to do this (filtering "FALSE" and deleting the visible table area), I get an error message "This won't work because it would move cells in a table on your worksheet".
The code will run in case I position those tables on top of each other (or split them over to different worksheets). Neither is great for readability (but doable). It just feels a little bogus error message as I still try to delete rows within the single table.
Do you guys have any suggestions how to handle this better or should I just re-position those tables? On the flip side, keeping the code relatively simple is important too. Are there any good alternatives to ditching the autofilter and running some sort of a loop that deletes rows based on condition? Given it's a piece of a bit more extensive code, I'll probably just re-position tables instead of running the loop with the aim to skip autofilter (to keep the code relatively easy).
After launching the code to do this (filtering "FALSE" and deleting the visible table area), I get an error message "This won't work because it would move cells in a table on your worksheet".
The code will run in case I position those tables on top of each other (or split them over to different worksheets). Neither is great for readability (but doable). It just feels a little bogus error message as I still try to delete rows within the single table.
Do you guys have any suggestions how to handle this better or should I just re-position those tables? On the flip side, keeping the code relatively simple is important too. Are there any good alternatives to ditching the autofilter and running some sort of a loop that deletes rows based on condition? Given it's a piece of a bit more extensive code, I'll probably just re-position tables instead of running the loop with the aim to skip autofilter (to keep the code relatively easy).
Code:
Sub DeleteRows()
Dim Tbl As ListObject
Set Tbl = ActiveSheet.ListObjects("MASTER")
Application.DisplayAlerts = False
Tbl.Range.AutoFilter Field:=2, Criteria1:="FALSE"
Tbl.DataBodyRange.SpecialCells(xlCellTypeVisible).Delete
End Sub
Last edited: