VBA Solver Loop

smide

Board Regular
Joined
Dec 20, 2015
Messages
164
Office Version
  1. 2016
Platform
  1. Windows
Hello.

I'm using Solver optimisation to find mean in Poisson distribution (POISSON.DIST(x,mean,TRUE)), for expected probability which is known value.
In my case x is also fixed value, always equal to 2.

I carry out the following calculation process:

- in cell H3 there is a formula: =POISSON.DIST(2,I3,TRUE)
- in cell I3 there is (pre-Solver run) value of 1
- in cell J3 there is a known expected probability
- finally in cell K3 there is a difference (formula) =H3-J3

When I open my Solver window, my Set objective is cell $K$3, To: Value of 0 (zero), By Changing Variable Cells: $I$3.

So for example if I set my cell I3=1, J3=0.51 and run my Solver, result in cell I3 is 2.65.

I should repeat somehow this calculation solving process (loop - VBA) for each row from 3 to 1000.

example.

pre Solver

H​
I​
J​
K​
1​
2​
3​
0.92​
1.0​
0.507​
0.413​
4​
0.92​
1.0​
0.432​
0.488​
5​
0.92​
1.0​
0.654​
0.265​
6​
...............

after Solver run

H​
I​
J​
K​
1​
2​
3​
0.507​
2.647
0.507​
0​
4​
0.432​
2.962
0.432​
0​
5​
0.654​
2.082
0.654​
0​
6​
...............
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
VBA Code:
Sub Macro1()
    Dim r As Integer
    
    For r = 3 To 1000
        Range("K" & r).GoalSeek Goal:=0, ChangingCell:=Range("I" & r)
    Next r
End Sub
 
Upvote 0
Solution
VBA Code:
Sub Macro1()
    Dim r As Integer
   
    For r = 3 To 1000
        Range("K" & r).GoalSeek Goal:=0, ChangingCell:=Range("I" & r)
    Next r
End Sub
Splendid!
Thank you so much for your assistance.
 
Upvote 0

Forum statistics

Threads
1,224,868
Messages
6,181,483
Members
453,046
Latest member
Excelvbaexpert

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