有条件的For循环逃逸Sub

我的代码如下:

sub main() '''some more code''' For j = InStr(1, stext, " ") To Len(stext) If 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 

当我走过macros,当它到达这一行:

 If IsNumeric(Mid(stext, j, 1)) Or IsAlpha(Mid(stext, j, 1)) Then 

它逃脱了整个分!

我做错了什么,我该如何解决?

我认为这可能有帮助。

ISALPHA,ISNUMERIC? – Microsoft Access / VBA答案

这通常发生在您有错误时。 在这种情况下,它可能是一个越界的错误。 你可能在stext的末尾有一个空格,这会导致这个问题。