2010-06-11 114 views
0

我的代碼如下:條件在for循環逍遙子

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 

當我通過宏行走,當它到達這條線:

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

逃離了整個子!

我在做什麼錯,我該如何解決?

回答

3

這通常發生在出現錯誤時。在這種情況下,它可能是一個超出界限的錯誤。您可能在stext的末尾留出空間,這會導致此問題。

+0

其逃脫了第一循環嘗試 – 2010-06-11 18:46:01

+1

穿上錯誤轉到前0語句循環,它會告訴你一個錯誤 – volody 2010-06-11 18:47:45

+1

可能是ISALPHA,我不認爲這是在VBA構建功能。 – 2010-06-11 18:56:44