VBA : help with a loop in order to delete values

Hello Experts,

I have the following code:

    With .Cells(Lrow, "A")

    If .Value Like "*YNERSI.*" Or .Value Like "*NPT.OCP*" Then .EntireRow.Delete
                    
            End With

Open in new window

I have some values with the following information in column A:

-NPT.NAP projects.Portfolio Management
-NPT.NAP projects.Portfolio Management.Breakers
-NPT.NAP projects.Portfolio Management.TII
-NPT.NAP projects.Portfolio Management.SO
-NPT.NAP projects.Portfolio Management.Supply Chain
.....

I would like to include the following condition in order to keep the values of  NPT.NAP projects.Portfolio Management.Supply Chain and remove the rest of the values of NPT.NAP projects

I am aware that I can do the following:
    If .Value Like "*YNERSI.*" Or .Value Like "*NPT.OCP*" or .Value like "NPT.NAP projects.Portfolio Management.Breakers" etc... Then .EntireRow.Delete

Open in new window



However I would like to simplify this by adding a Not condition or and additional loop.

The order problem is that if I do like this:

   
 If not  (.Value Like "*NPT.NAP projects.Portfolio Management.Supply Chain*") Then .EntireRow.Delete

Open in new window


I just keep the values NPT.NAP projects.Portfolio Management.Supply Chain and the idea is  to remove the values of NPT.NAP projects which have a third level different of Supply chain such as:
-NPT.NAP projects.Portfolio Management
-NPT.NAP projects.Portfolio Management.Breakers
-NPT.NAP projects.Portfolio Management.TII
...

Thank you very much for your help.
LVL 1
LD16Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
you can also try to use the instr function, like this:

if instr(.Value, "NPT.NAP projects.Portfolio Management.Supply Chain") = 0 then .EntireRow.Delete

would this help?
LD16Author Commented:
Hello Ryan Chong,

Do you mean to add  to the current code like this :

 If .Value Like "*YNERSI.*" Or .Value Like "*NPT.OCP*" or  instr(.Value, "NPT.NAP projects.Portfolio Management.Supply Chain") = 0 Then .EntireRow.Delete

The problem is that I have some values that I want to keep:

NPT.ECOB.
NPT.RETAIL
....

That I want to keep and I don't want to complexity the code by adding a if not.

If apply if instr(.Value, "NPT.NAP projects.Portfolio Management.Supply Chain") = 0 I remove the values above.
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
just try to get it right... is that mean:

1. if the value contains "NPT.NAP projects.Portfolio Management.Supply Chain" (with other text), you want to replace it with "NPT.NAP projects.Portfolio Management.Supply Chain" ?

2. if the value does not contains "NPT.NAP projects.Portfolio Management.Supply Chain", delete the whole row?
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

LD16Author Commented:
Thank  you for your feedback:

1-If the value contains "NPT" keep it
2-If the value contains "NPT.NAP projects.Portfolio Management.Supply Chain" keep the entire line.
3-If the value contains "NPT.NAP projects.Portfolio Management" or another value at forth level different as "Supply chain" such as "NPT.NAP projects.Portfolio Management.BEE", "NPT.NAP projects.Portfolio Management.Breakers" remove it.
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
try this?

if instr(.Value, "NPT.NAP") > 0 then
      if instr(.Value, "NPT.NAP projects.Portfolio Management.Supply Chain") = 0 then .EntireRow.Delete
end if

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
LD16Author Commented:
It works perfectly. Thank you very much!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.