在VBA中无缘无故地跳过循环 [英] For loops being skipped without cause in VBA
问题描述
要清楚,我有一个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屋!