VBA - 如何有条件地跳过for循环迭代 [英] VBA - how to conditionally skip a for loop iteration
本文介绍了VBA - 如何有条件地跳过for循环迭代的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在一个数组上有一个 for 循环.我想要做的是测试循环中的某个条件,如果为真则跳到下一次迭代:
I have a for loop over an array. What I want to do is test for a certain condition in the loop and skip to the next iteration if true:
For i = LBound(Schedule, 1) To UBound(Schedule, 1)
If (Schedule(i, 1) < ReferenceDate) Then
PrevCouponIndex = i
Continue '*** THIS LINE DOESN'T COMPILE, nor does "Next"
End If
DF = Application.Run("SomeFunction"....)
PV = PV + (DF * Coupon / CouponFrequency)
Next
我知道我能做到:
If (Schedule(i, 1) < ReferenceDate) Then Continue For
但我希望能够在 PrevCouponIndex 变量中记录 i 的最后一个值.
but I want to be able to record the last value of i in the PrevCouponIndex variable.
有什么想法吗?
谢谢
推荐答案
你就不能做这样简单的事情吗?
Couldn't you just do something simple like this?
For i = LBound(Schedule, 1) To UBound(Schedule, 1)
If (Schedule(i, 1) < ReferenceDate) Then
PrevCouponIndex = i
Else
DF = Application.Run("SomeFunction"....)
PV = PV + (DF * Coupon / CouponFrequency)
End If
Next
这篇关于VBA - 如何有条件地跳过for循环迭代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文