Macro with Solver

yichuansancun

Board Regular
Joined
Feb 7, 2011
Messages
123
Hi All,

I tried to record a macro for Solver in Excel. After recording the macro, I
ran it and the message was that the "SolverOK" which is the first word in the
body is not a defined Sub or function.

Sub Calculate()
'
' Calculate Macro
'

'
SolverOk SetCell:="$N$7", MaxMinVal:=2, ValueOf:="0", ByChange:="$N$3"
SolverSolve
End Sub


How to solve this problem?

I am using excel 2007

Thanks,
Perri
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
I need to correct my question, the macro for solver works, but it doesn't complete the entire step. When I run the macro, the Solver Results window will pop up and I have to click "ok" to complete the steps.

How can I incorporate the clicking "ok" into the macro?

Thanks,
Perri
 
Upvote 0
Try

Code:
SolverSolve UserFinish:=True
 
Upvote 0
You're welcome.

Help is your friend.
 
Upvote 0
Wait... I said too early :(

Once I added
moz-screenshot-2.png
moz-screenshot-3.png
userfinish=true, the macro will work only the first time but won't work the 2nd and after...

Why is that?



Perri
 
Upvote 0
Can you post the code as you have it now, and explain exactly what you do that results in an error?

You might start the code with SolverReset to clear out any prior model (not the Set and Changing cells so much as prior constraints).
 
Upvote 0
Sub Macro8()
'
' Macro8 Macro
'

'
SolverOk SetCell:="$N$7", MaxMinVal:=2, ValueOf:="0", ByChange:="$N$3"
SolverSolve userFinish:=True

End Sub

When I run the macro, the solver results "#num!".

Is there a way for me to upload this file somewhere on this board?

Thanks,
Perri
 
Upvote 0
No, but you can store it on box.net and post a link.
 
Upvote 0

Forum statistics

Threads
1,224,531
Messages
6,179,379
Members
452,907
Latest member
Roland Deschain

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top