I am creating a program which will find a function maximum to give a profit. This profit function is equiped with an error function to prevent ordering more stock than can be obtained.
The function itself is in excel and is only used as a value in VB.
The underlined section is where the debug is showing a problem.
Any help would be greatly appreciated
The function itself is in excel and is only used as a value in VB.
Code:
xa = 90
xb = 90
Cells(6, 5).Value = xa
Cells(7, 5).Value = xb
Profit = Cells(4, 9).Value
For i = 1 To 1000
xan = xa + dxa * (2 * Rnd() - 1)
Cells(6, 5).Value = xan
xbn = xb + dxb * (2 * Rnd() - 1)
Cells(7, 5).Value = xbn
[U]Profitn = Cells(4, 9).Value[/U]
If (xan >= xlow) And (xan <= xahi) And (xb <= xbhi) And (xb >= xlow) And (Profitn > Profit) Then
xa = xan
xb = xbn
Profit = Profitn
Cells(6, 9).Value = xa
Cells(7, 9).Value = xb
Cells(5, 9).Value = Profit
End If
Next
Any help would be greatly appreciated
Comment