Conditional In For-Loop Escapes Sub
My code is as follows:
sub main()
'''some more code'''
For j = InStr(1, stext, " ") To Len(stext)
I开发者_运维知识库f IsNumeric(Mid(stext, j, 1)) Or IsAlpha(Mid(stext, j, 1)) Then
letter1 = Mid(stext, j, Len(stext))
Exit For
End If
Next j
'''some more code'''
end sub
As I walk through the macro, when it gets to this line:
If IsNumeric(Mid(stext, j, 1)) Or IsAlpha(Mid(stext, j, 1)) Then
it escapes the entire sub!
What am I doing wrong, and how do I resolve it?
This typically happens when you have an error. In this case, it could be an out of bounds error. You could have a space at the end of stext
, which would cause this problem.
I think this might help.
ISALPHA, ISNUMERIC? - Microsoft Access / VBA Answers
精彩评论