在VBA中无缘无故地跳过循环 [英] For loops being skipped without cause in VBA

查看:898
本文介绍了在VBA中无缘无故地跳过循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码如书面所作,适用于我测试过的所有方法。我有两个问题。首先,为什么在蓝色的blazes中,我是否需要在我的代码中使用Do While循环而不是For循环?我已经搜索过,我可以帮助我解决这个问题。我不能重新安装excel,但我已经重置了尽可能多的设置,但是,总是,编译器跳过每个for循环,我不是每个循环...除了第一个for循环在我的编程...这是我见过的最奇怪和最奇怪的行为。我已经使用了一步(F8)10000次来尝试找出为什么它不断跳过。但是每一次我做一个循环,它甚至没有运行它的第一行。



要清楚,我有一个Do While .. 。Loop,it SHOULD be a For Next。但是,由于每次改变的地点都会改变代码,所以每次都会跳过代码,代码将被完全跳过。即使我将i值重置为0.即使每个循环都有不同的迭代器,问题也会发生。



在带有Office 2010的Intel i5上运行w8。

  i = 1 To i = 100 
If(i> = startRow And i< = stopRow而不是rowDone(i)而不是i = colFocus)然后
colCurPayAmounts(i)= S_Debt.Cells我,5)
Else
colCurPayAmounts(i)= 0
End If i = i + 1
Next i


解决方案

问题是应该是对于i = 1 To 100而不是For i = 1 To i = 100 @Rory


My code, as written, works for all the ways I've tested it. I have two questions though. First, Why in the blue blazes do I HAVE to use Do While loops instead of For loops in my code? I've searched Everywhere I can to help me on this issue. I can't reinstall excel, but I've reset as many of the settings as I can, but, invariably, the compiler skips over every for loop I have that isn't a for each loop... Except the first for loop in my programming... It is the weirdest and most bizarre behavior I have ever seen. I have used step through (F8) 10000 times to try and figure out why it keeps skipping. But every single time i make a for loop, it doesn't even run the first line of it.

To be clear, every place I have a Do While ... Loop, it SHOULD be a For Next. But making this change breaks the code every time because every spot the do while is changed to for, the code is skipped entirely. Even if I reset the i value to 0. The issue happens even if I have a different iterator for each loop.

Running w8 on an Intel i5 with Office 2010.

For i=1 To i = 100 
    If (i >= startRow And i <= stopRow And Not rowDone(i) And Not i = colFocus) Then
        colCurPayAmounts(i) = S_Debt.Cells(i, 5) 
    Else 
        colCurPayAmounts(i) = 0 
    End If i = i + 1 
Next i 

解决方案

The problem is it should be For i = 1 To 100 and not For i = 1 To i = 100 @Rory

这篇关于在VBA中无缘无故地跳过循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆