Zend certified PHP/Magento developer

How to do a reverse goal seek formula in order to solve this equation?

I have created a model whereby I’ve got the following: Cost (column P) Dealer price (Column S) Current List price (Column T)

I’ve then done some market research and have adjusted List pricing (RRP) in accordance with the market research. If market research was not conducted for the part, I’ve kept the original List price.

I’ve then worked out Our Margin and the Dealer Margin, Our Margin being the profit between Dealer and Cost Price and the Dealer Margin being the profit between List and Dealer Price.

I’ve then attempted to optimise the Margins, by manually inputting the Goal Margins in Columns AM and AN. I’m happy with the way Column AM is reflected in column AT, however, I cannot work out how to correctly get Column AN to be reflected in the Dealer Margin (Column AU).

Any help on how to fix my model so that the input value in AN is correctly reflected in Column AU would be greatly appreciated.

Also, any advice on how to simplify and clean up my template would also be appreciated.

enter link description here