I have what I thought would be a simple issue to solve. A client has a very complicated spreadsheet that calculates (among other things) IRR on an investment property. They want to set a target IRR, and determine how much they should pay for the property in order to achieve that IRR.
Within a single sheet, there is a table of inputs (including the property purchase price) for multiple scenarios (the user selects one of these scenarios). There is a cell showing the resulting IRR (for whichever scenario is selected), to which I assigned the range name CurrentIRR.
I added a cell for Target IRR (range name = TargetIRR). I then set up a short macro to run Solver to find the purchase price that results in the target IRR. Because there are multiple scenarios, the macro has to set a Range variable (PurchasePriceCell) to whichever cell has the purchase price for the currently-selected scenario. My macro code basically looks like this:
When I run this as is, the SolverOK command writes the cell address ($H$43) into the PurchasePriceCell, rather than a numerical value ($H$43 is indeed the PurchasePriceCell address). I thought perhaps Solver wanted the "ByChange" reference as an address, so I tried:
But when I run that, the original (numerical) value remains unchanged in the PurchasePriceCell (i.e. Solver appears to do nothing). So I tried:
But then I get a compile error "Argument not optional" (????)
I also tried:
But then Solver gives a "solution" of zero (which is incorrect).
What am I doing wrong? If I run Solver manually it works fine (and gives a correct result).
Bookmarks