【发布时间】:2018-02-08 09:16:39
【问题描述】:
我正在尝试编辑一些当前循环的 VBA 代码,直到满足某个测试。我想做的是循环直到满足两个条件。我很难做到这一点。这是原始代码,它可以工作。
Loop
For j = 1 To 29
Increment = Worksheets("Price & Energy Curve").Cells(8 + Start + j, 3).Value
l = Int((Worksheets("Capacity").Cells(57 + j, 12).Value) * (-1) / Increment)
k = WorksheetFunction.Max((l + 1) * Increment, 0)
Worksheets("Capacity").Activate
ActiveSheet.Cells(56 + j, 17).Value = k
test = ActiveSheet.Cells(57 + j, 13).Value
Do While test <> True
k = k + Increment
ActiveSheet.Cells(56 + j, 17).Value = k
test = ActiveSheet.Cells(57 + j, 13).Value
Loop
Next j
我想添加额外的测试
test = ActiveSheet.Cells(57 + j, 37).Value
所以当
test = ActiveSheet.Cells(57 + j, 13).Value
和
test = ActiveSheet.Cells(57 + j, 37).Value
为真,循环退出。
【问题讨论】:
-
你已经在你的问题中写下了答案`if test = ActiveSheet.Cells(57 + j, 13).Value and test = ActiveSheet.Cells(57 + j, 37).Value then exit do