• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

delete cell contents with certain words

Marco1975

New Member
hi,
delete cell contents with certain words

I'm trying to make a macro that in a column clears the contents of all the cells that don't contain the word "presso".

example :
in G5 : presso
in G6 : pressoxxx
in G7 : xxxx presso xxxx

I tried using this macro but doesn't work

Code:
Sub Prova()

Dim cella As Range

For Each cella In [G5:G10000]

If cella.Value <> "*presso*" Then cella.ClearContents

Next cella

End Sub

how can I solve the situation?
Thank you.
 
Change this & check.


If not cella.Value like "*presso*" Then cella.ClearContents

Or

If not instr(cella.Value, "presso" ) Then cella.ClearContents
 
Hi,

Try Instr command:

Code:
Dim cella As Range

For Each cella In [G5:G10000]

If InStr(1, cella, "presso", vbTextCompare) > 0 Then cella.ClearContents

Next cella

Regards,
 
Thanks for your answers.
The solutions are all good ... there was only a problem in the Somendra solution:
this line:
Code:
 If InStr(1, cella, "presso", vbTextCompare) > 0 Then cella.ClearContents

I modified it so:
Code:
If InStr(1, cella, "presso", vbTextCompare) = 0 Then cella.ClearContents
and now it works.

Excellent I have 2 solutions.
Thanks.:)
 
Back
Top