Does anyone know if this formula is worth pursuing in a spreadsheet or things vary too much between banks to get a generalized solution?
Others have noted that in many cases, there's enough consistency to use a spreadsheet or even a simple direct (closed form equation) calculation. But this is not true for all cases.
In particular, be aware that variable rate mortgages and loans are much more varied than fixed-rate ones. Here a spreadsheet may not suffice.
You can sometimes benefit from splitting a loan into multiple parts. In the US, at least, though, it's common for secondary loans (e.g., a 2nd mortgage) to have significantly worse terms than primary loans (the first mortgage), even if both loans are fixed-rate. (This happens for numerous reasons, including the fact that the primary mortgage holder is first in line in the case of a default.)
For my first house, in the 1990s, I went with an "80-10-10" plan: I put 10% down, got a conventional 80% mortgage at the then-great-rate of around 8%, and a 10% secondary mortgage at a double-digit rate, though I forget now what it was (11 to 12% perhaps?). The secondary mortgage used a daily interest accrual based on the date they received payment, so that the amount that went to principal vs the amount that went to interest was unpredictable. Remember that at this time all payments went via US mail, with variable delay in the postal system. I made extra principal payments and these were frequently somehow—"accidentally" of course—credited as interest prepayments, requiring followups with the bank to correct this. I paid this secondary mortgage off as quickly as possible. This arrangement also allowed avoiding PMI payments,1 and given that I expected to be able to pay off the secondary mortgage within a few years, saved quite a bit overall.
(Due to an overall housing-market rise and changes in interest rates, I was able to refinance into a substantially lower-rate fixed-rate mortgage within a few years as well. That would probably have been roughly equivalent, but that was not knowable at the time I got the 80-10-10 arrangement.)
1PMI, or Private Mortgage Insurance, are payments you make on your mortgage for insurance that covers the lender's loss in case you default. The exact details get complicated here; see the link if you're in the US.