VBC 'Contains' Check

M

msnyc07

Apologies gain, still trying to hack this coders VBA as a non-coder so I can
fix as he is AWOL.

Anyway part of the code was supposed to see if a cell contained specific
text but as I test it it only works on a complete match. This is the line of
code:

ElseIf InStr(UCase(CStr(wsCert.Cells(targetCertRowNumber, 1).Value)),
UCase("TEXT")) And Len(CStr(wsCert.Cells(targetCertRowNumber, 2).Value)) = 0
Then

Do I need to change something so it is finding "TEXT Anything" as right now
it is just finding "TEST"

Thanks in advance
 
M

Mike H

Hi,

Because you posted such a small snippet it's difficult to recreate you code
so here's a general example of how to construct a test with INSTR which
ignores case and finds the text within a longer string.


If InStr(1, "a bit if TEXT to test", "text", vbTextCompare) > 0 Then
MsgBox "Found it"
End If
--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.
 
D

Don Guillett

Without seeing all of it, it appears that the test for instr is missing the

ElseIf InStr(UCase(CStr(wsCert.Cells(targetCertRowNumber, 1).Value)),
UCase("TEXT"))
And Len(CStr(wsCert.Cells(targetCertRowNumber, 2).Value)) = 0
Then
 

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

Top