VB find (true false)

  • Thread starter Thread starter Wildman
  • Start date Start date
W

Wildman

I'm trying to mix in some VB in a macro I made that
looks for a particular word in a cell. If the word
exist, continue the macro. If it does not end the Macro.
any Ideas?

Cells to search for word a2:a30000
word can be mixed in with other characters.

Thanks in advance
Wildman
 
Try...
On Error Resume Next
x = Cells.Find(What:= myval, LookAt:=xlPart)
If Err.Number = 91 Then Exit Sub
 
For Each cell In Range(A2:A30000")
iPos = Instr(1,cell.Value,"the_word")
If iPos > 0 Then
'continue code
End If
Next cell

--

HTH

RP
(remove nothere from the email address if mailing direct)
 
Bob Phillips wrote...
For Each cell In Range(A2:A30000")
iPos = Instr(1,cell.Value,"the_word")
If iPos > 0 Then
'continue code
End If
Next cell

Alternatively, could use Like.

For Each c In SomeRange
If c.Value Like "*" & your_word_here & "*" Then
'continue
End If
Next c

Sometimes exact text matching (InStr) is more useful, other times
pattern matching (Like) is.
 
Yep, I agree, that is better

Harlan Grove said:
Bob Phillips wrote...

Alternatively, could use Like.

For Each c In SomeRange
If c.Value Like "*" & your_word_here & "*" Then
'continue
End If
Next c

Sometimes exact text matching (InStr) is more useful, other times
pattern matching (Like) is.
 
so what your saying is....
give my column a range name="test"

and say I'm searching for the word "Wildman"
then in my macro add...

If test.Value like "*"&"wildman"&"*" then
else
exit sub
End If





Thanks again
Wildman
 
even simpler

test.Value like "*wildman*"

--

HTH

RP
(remove nothere from the email address if mailing direct)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top