VBA to Delete Cells that Does Not Meet Condition in Microsoft Excel: Using For Each Loop
If you came across a situation in which you do not want to delete all the cells instead you want to delete cells that does not contain specific text then you should read this article.
In this article we will learn how to delete cells using wildcard that does not contain the criteria text.
Question: I want a macro to help me in deleting the cells in cases wherein the cell contains anything except “ABC” should be deleted.
Following is the snapshot of data:
We need to follow the below steps:
Enter the following code in the standard module
Dim criteriarange As Range
Dim criteriacell As Range
Set criteriarange = Range(“A1:B5″)
For Each criteriacell In criteriarange
If Not criteriacell.Value Like “*ABC*” Then
Conclusion: In this way using for each loop in VBA we can easily delete cells that does not contain the criteria information.
The applications/code on this site are distributed as is and without warranties or liability. In no event shall the owner of the copyrights, or the authors of the applications/code be liable for any loss of profit, any problems or any damage resulting from the use or evaluation of the applications/code.