VBA - why does goal seek give marginally different answer to VBA for a simple (single cell optimization) problem?

31 Views Asked by At

I have two questions:

Question 1:

I am working on a financial model where a $0.05 difference in price when applied to multiple quantities gives a difference of thousands of dollars in the revenue.

Below is the solver and goal seek code for comparison

'Solver code

For x = Range("L1").Column To Range("L1").End(xlToRight).Column

SolverOk SetCell:=Cells(42, x), MaxMinVal:=3, ValueOf:=Range("c146").Value, ByChange:=Cells(134, x)
SolverSolve userFinish:=True
    
Next x

'Goal Seek code

For x = Range("L1").Column To Range("L1").End(xlToRight).Column

Cells(42, x).GoalSeek Goal:=Range("c146"), ChangingCell:=Cells(134, x)

Next x

Question 2:

Goal seek gives me an error 1004: reference isn't valid. But when i replace the .End(xlToRight).Column with Range ("W1").Column where W1 is the last column, then the error disappears.

I compared the results of Solver and Goal Seek. Both solve to the optimization (which is the gross margin in Range("c146") and is set to 0.08 meaning 8%) by changing the price (cells 134,x). But the results (prices) are different when rounded to more than 2 d.p. Hence the revenues differ by tens of thousands of dollars (because quantities sold are high).

0

There are 0 best solutions below