简体   繁体   中英

How can i speed up my Goal Seek code?

Trying to learn new tricks so bear with me here, I'm trying to optimize capacity by using up all my daily capacity without running out of yearly capacity. so there's a lot of goal seeking. The code below works but it's slow especially when i'm doing a months of stuff. Is there a way i can speed this up? what common noob mistake am i making?

Sub cashPark()


Set enddate = Sheets("Cash").Range("E4")
Set Window = Sheets("Cash").Range("D8")
Set TargetWindow = Sheets("Cash").Range("D9")
Set datecount = Sheets("Cash").Range("E4")
Set cashParkVol = Sheets("Inventory").Range("BW1")
Set Repeat = Sheets("Cash").Range("E5")

cashParkVol.Offset(datecount, -2).GoalSeek _
 Goal:=0 And Window.Value > 0, _
 ChangingCell:=cashParkVol.Offset(datecount, 0)


Let x = 0
Do While x < Repeat
cashParkVol.Offset(datecount + x, -2).GoalSeek _
    Goal:=0 And Window.Value > TargetWindow, _
    ChangingCell:=cashParkVol.Offset(datecount + x, 0)
x = x + 1
Loop

End Sub

I know this is old, but I stumbled on this problem and am staying to answer in the hope the perspective here might be helpful.

It's hard to say without seeing your actual excel model, but as is partially alluded to in Doug's comment, this sounds like a problem that would benefit from an alternative approach. My guess is that your goal seeking is actually something that can be accomplished via Linear Programming , where in a simplified sense you would be solving something like the following:

在此处输入图片说明

Essentially you're optimizing your use of daily capacity based on the value of using that capacity at every point throughout the year. Your actual problem is certainly different but I hope its enough of a start.

In this case Excel's built-in solver will not solve a problem of that size, instead Open Solver will work, or for more complex or non-linear problems, Solver Studio .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM