作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在运行一个 Do Until 循环,该循环降低了目标单元格中的值,从 0.99 (x=.99) 开始,然后使用这些值来完成计算。如果满足 2 个条件中的 1 个,我需要停止此循环。
Do Until
(Workbooks("Group 4 Correlation Solver").Sheets("STRUCTURETOOL").Range("J23").Value * -1 >= Workbooks("Group 4 Correlation Solver").Sheets("STRUCTURETOOL").Range("U28").Value * 0.9 And Workbooks("Group 4 Correlation Solver").Sheets("STRUCTURETOOL").Range("J23").Value * -1 <= Workbooks("Group 4 Correlation Solver").Sheets("STRUCTURETOOL").Range("U28").Value * 1.1) Or (x = 0.75)
Deal_ID = VBA.Right(Workbooks("Weekly Option Update (Master).xlsm").Sheets("GDD Group").Cells(i, "G").Value, 7)
Sheets("Correlation").Range("E7").Value = x
Workbooks("Group 4 Correlation Solver").Sheets("Correlation").Range("F8").Value = x
Workbooks("Group 4 Correlation Solver").Sheets("Correlation").Range("C9").Value = x
Workbooks("Group 4 Correlation Solver").Sheets("Correlation").Range("D10").Value = x
Workbooks("Group 4 Correlation Solver").Sheets("STRUCTURETOOL").Calculate
x = x - 0.005
Workbooks("Weekly Option Update (Master).xlsm").Sheets("GDD Group").Cells(i, "H") = x + 0.005
Loop
最佳答案
真是个嘴巴的小伙子!提取局部变量,无需每次都反复取消引用相同的对象!
局部变量也使事情更容易调试。
Dim solverBook As Workbook
Set solverBook = Application.Workbooks("Group 4 Correlation Solver")
Dim weeklyOptionBook As Workbook
Set weeklyOptionBook = Application.Workbooks("Weekly Option Update (Master).xlsm")
Dim gddGroupSheet As Worksheet
Set gddGroupSheet = weeklyOptionBook.Worksheets("GDD Group")
Dim structureSheet As Worksheet
Set structureSheet = solverBook.Worksheets("STRUCTURETOOL")
Dim currentValue As Double
currentValue = structureSheet.Range("J23").Value ' CAUTION: possible type mismatch here
Dim targetValue As Double
targetValue = structureSheet.Range("U28").Value ' CAUTION: possible type mismatch here
Const threshold As Double = 0.1
Const limit As Double = 0.75
Dim correlationSheet As Worksheet
Set correlationSheet = solverBook.Worksheets("Correlation")
Do Until (currentValue * -1 >= targetValue * (1 - threshold) _
And currentValue * -1 <= targetValue * (1 + threshold)) _
Or x <= limit
Deal_Id = Right$(gddGroupSheet.Cells(i, "G").Value, 7)
correlationSheet.Range("E7,F8,C9,D10").Value = x
structureSheet.Calculate
gddGroupSheet.Cells(i, "H") = x
x = x - 0.005
currentValue = structureSheet.Range("J23").Value ' CAUTION: possible type mismatch here
targetValue = structureSheet.Range("U28").Value ' CAUTION: possible type mismatch here
Loop
=
在处理浮点数时。
Or x <= limit
可能是您当前问题的解决方案。
关于excel - 将 "Do Until"与 "And, Or"结合使用,不寻找第二个条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56449670/
我是一名优秀的程序员,十分优秀!