Instr function problem
Did for me. Run-time error '5': Invalid procedure call or argument.
on "If InStr(Len(fruitName) - t, LCase(fruitName), "a") Then "
"Stuart" wrote in message
...
Not finding the characture does not cause an error!
Trevor Shuttleworth wrote in message
...
Ross
unless you can guarantee that the cell/string will contain what you are
looking for, you may need to modify the code slightly:
Sub InstrTest()
'fruitName = "Bananas"
fruitName = "Melon"
For t = 0 To Len(fruitName)
On Error Resume Next
If InStr(Len(fruitName) - t, LCase(fruitName), "a") Then Exit For
On Error GoTo 0
Next t
If t = Len(fruitName) Then
MsgBox "Not found"
Else
MsgBox Len(fruitName) - t
End If
End Sub
And you probably need to check the case if it's an alpha character
you're
looking for.
Regards
Trevor
"Ross Withey" wrote in message
...
Stuart,
Thanks -that looks elegant!
Ross
"Stuart" wrote in message
...
fruitName = "Bananas"
For t = 0 To Len(fruitName)
If InStr(Len(fruitName) - t, fruitName, "a") Then Exit For
Next t
MsgBox Len(fruitName) - t
Ross Withey wrote in message
...
Hello,
If cell A1 has the string value "Bananas"
Instr(1,"Range("A1"), "a") finds the first "a". My problem is, I
want
to
find the final "a".
Can you suggest the right code? I know I can increase the "1", but
I
need
to
find the final "a" at the first attempt in a loop. Can you help
please?
Thanks,
Ross
|