Hello all,
As the title says, I'm trying to modify a macro that was originally used to remove all rows containing a set of strings in specific columns, to now remove all rows except those with a specific string in a specific column.
I have the following, which doesn't give any error but does not seem to do anything:
Sub RemoveAllExcept()
Dim p, r As Range
Application.ScreenUpdating = False
p = "sup":
With Sheets("sheet1") 'Applies to this Sheet Name
If .FilterMode Then .ShowAllData
Set r = .[f1:f2]
r(2).Formula = "=(a2<>" & p & " )" 'A2 i.e. this must be the column which contains the "except" text
With .Cells(1).CurrentRegion
.AdvancedFilter 1, r
.Offset(1).EntireRow.Delete
End With
If .FilterMode Then .ShowAllData
r.Clear
.ListObjects(1).ShowAutoFilter = True
End With
Application.ScreenUpdating = True
MsgBox ("Done")
End Sub
I have attached a sample workbook with the original sheet ("Sheet1"), and a results sheet, along with the macro. Simply click on the button to run the macro, though as I said earlier, it won't do anything other than show a message.
Thanks for any help.
Bookmarks