2016-11-18 1 views
0

vba에서 Excel solver를 제어하려고합니다. 입력 값 (i, 8)을 조정하여 대상 셀 (i, 10)의 값을 최소화하는 데 사용합니다. 또한 셀 (i, 8)을 입력으로 사용하여 일부 계산을 위해 외부 응용 프로그램을 호출하는 사용자 정의 함수가 있습니다. 대상 셀은 UDF 출력과 다른 고정 값의 차이입니다.vba solver - 반복에 지연 추가

솔버가 주기적으로 문제를 설정하고 건너 뛴다는 것을 알았습니다. 값을 수동으로 조정하여 더 나은 솔루션을 얻을 수 있으므로 UDF가 값을 반환하는 것보다 빠르게 새로운 반복을 건너 뛴다 고 생각합니다.

솔버 반복 속도를 늦출 수있는 방법이 있습니까? 도움이된다면 아래 코드 ...

Sub Main() 

Dim Msg As String, MyString As String 
Dim Style As Variant, Response As Variant 

Application.ScreenUpdating = False 
Application.EnableEvents = False 

'Define a confirmation message due to long duration of calculations 
Msg = "This calculation takes long. Do you want to proceed?" 

'Define message box style 
Style = vbOKCancel + vbCritical + vbDefaultButton2 

'Record the user response 
Response = MsgBox(Msg, Style) 

If Response = vbOK Then 
     Call RateTool.RateSolver 
    End If 

Application.ScreenUpdating = True 
Application.EnableEvents = True 

End Sub 

그리고 해결사 스크립트

Sub RateSolver() 

Dim First As Integer, Last As Integer 
Dim i As Integer 

First = Cells(2, 4).Value 
Last = Cells(3, 4).Value 

For i = First To Last 

    SolverReset 

    'Define parameters for the solver: Minimise target cell (i,8) by changing input cell (i,6) 
    SolverOk SetCell:=Cells(i, 10), MaxMinVal:=2, ByChange:=Cells(i, 8), Engine:=1 

    SolverSolve UserFinish:=True 

Next i 

End Sub 
+0

죄송합니다, 나는 몇 가지 긴 지루한 코드를했다 Main()은 RateTool을 시작하는 버튼을 설정합니다 .... 따라서 if 응답 = vbOK 문. – bwindi

답변

2
Application.Wait Now + TimeValue("00:00:02") 

위는 2 초 일시 중지

+0

감사. 이로 인해 지연이 생겼습니다. 불행히도 여전히 문제를 해결하지 못했기 때문에 시간 지연이 내 UDF에서 문제가되지 않는 것 같습니다. 이것은 간단한 방정식으로 작동하지만 외부 응용 프로그램을 제어하는 ​​UDF를 도입 할 때 부드럽게 실행되지 않습니다. 내가 생각하기에 처음으로. – bwindi