在Excel中使用For和Next循环存储解算器结果 [英] Store Solver Result with For and Next loop in Excel

查看:123
本文介绍了在Excel中使用For和Next循环存储解算器结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用重复求解器51次,并将每个求解器计算的结果存储在Excel中的单独单元格中。下面是我的VBA脚本但是,我遇到了脚本的问题。存储结果只显示第51个,最后的计算结果。这是一个简单的脚本,但我可以弄清楚我做错了什么。感谢您的帮助!

I want to use repeat solver for 51 times and store the result from each computation of solver in a separate cell in Excel. Here is my VBA script below; however, I run into a problem with the script. The stored result only shows the 51st, the last computation result. It is a simple script but I could figure out where I did wrong. Thank you for the help!

Private Sub Button1_Click()
Dim j As Integer
For j = 1 To 51
Range("m4") = j
solversolve UserFinish:=True
solversolve(UserFinish:=True) = Range("Q" & j + 3)
Next j
End Sub


推荐答案

p>假设目标函数在Range(m4)中,并且要解决从Range(Q4)开始的解决方案,请尝试:

Assuming the objective function is in Range ("m4") and you want to solve the solutions beginning at Range ("Q4") then try:

Private Sub Button1_Click()`  
  Dim j As Integer
  For j = 1 To 51
    solversolve UserFinish:=True
    Range("Q" & j + 3).value=Range("m4").value
  Next j
End Sub

但是,您不要对模型进行更改以重新运行它?有任何随机值吗?

But, you don't make changes to the model to re-run it? Have any random values?

这篇关于在Excel中使用For和Next循环存储解算器结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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