As requested, here are some rough notes on the previous formula construction, maybe Hui can incorporate in a format suited to FF.
In another post, Narayan has spoken of compiling formula patterns for solving problems. The key patterns needed here are arrays of running sums together with combinations of constraints.
1. For the constraints, results need to be positive, less than row and column limits as well as less than cumulative row and column limits.
This led to the second formula from the previous post entered into F10 and filled over the range. One can see the row and column symmetry in the formula, I'll leave details to readers or others with better explanatory skills.
2. Normally, I would be more than happy to have got this far! The real challenge is in making suitable modifications to support arrays of running sums and constraints by making the changes:
$B10 -> $B10:$B31
$C10 -> $C10:$C31
For this purpose, we can break down the formula into pairs of inputs:
=MAX(0,MIN(r,MIN(c,MIN(x,y))))
Here, r and c are row and column quantities and x and y are the overlapping totals in the row and column quantities.
3. Consider first MAX(0,z) where z=MIN(...) is a long formula.
The trouble with the obvious IF alternative is repeating this long formula twice, i.e. IF(z>0,z,0).
A second way, used above by John, is to find an expression that errors for negative values like EXP(LN(z)) or z^0.5^2 or EFFECT(z,1), and then pass to IFERROR.
A third slightly less obvious alternative which ties in with methods in the next section is to use ABS(z) = z^2^0.5 as in:
=(z+ABS(z))/2
=MMULT(z^{1,2}^{1,0.5},{1;1}/2)
4. For MIN(x,y) the obvious replacement =IF(x<y, x, y) again results in formula duplication. Instead we can use:
=(x+y-ABS(x-y))/2
=MMULT((x+{1,-1}*y)^{1,2}^{1,0.5},{1;-1}/2)
5. This method can also be applied to MIN(c,.) and MIN(r,.). Since r and c are both positive the formula can be rewritten:
=MIN(r,MIN(c,MAX(0,MIN(x,y))))
and then the exponents ^{1,2}^{1,0.5} can be replaced by ABS for the r and c parts.
At each step of this formula conversion process, results were checked by filling over the whole range. Last working versions were stored in a text file which proved far too useful!