VBA Optimization for step function

rpaolillo

New Member
Joined
Dec 13, 2005
Messages
20
I use solver a lot in my career. However, solver breakdowns when the function is a step function. I am attempting to write an optimization for a step function (a function that increases or decreases abruptly from one constant value to another.) and need some help with the loop.

Function_Range = A2
Variable_Range = B2
Start_Range = C2
Width_Range = D2

I manually created a solution using excel formulas but need to transition this to VBA. I'll use an example where the function is "=B2*100-B2^2" (This is not a step function but just for example).

I then change the variable using a starting point and width. Start_Range = 100 and Width_Range = 9 I will then create a table where I go down from 100 with intervals of 9 tens times below and ten times above. 10, 19, 28, 37....100....172,181,190. I then find the maximum function and identify that variable. In this case, it is 46. I then take 46 and now bump the table up and down by 1/5 the original width. (9/5=1.8) (e.g. Start_Range = 46, Width_Range = 1.8) for a new table 28,29.8,31.6,...,46,60.4,62.2,64. Identify the maximum function. In this case, it is 49.6. Redo table with Start_Range =49.6, Width_Range = 0.36 (1.8/5).

I repeat this process 5 times arriving at very close to the maximum point. The output of the model is the variable input to the latest run where the function is maximized. Can someone help me get this coded in VBA?

Excel example: https://www.dropbox.com/s/2ospmmsikym75nd/Solver_DM.xlsx?dl=0
Thanks
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.

Forum statistics

Threads
1,223,931
Messages
6,175,465
Members
452,645
Latest member
Tante

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