What I'm trying to do is the following:
Once 'Cell B19:B20' and 'Row 21' have a value, 'Row 22' divides 'Cell B19:B20' between the amount of columns that have a cost value ('Row 21').
For example:
if only D21 has a value the D22=B19:B20
if D21 AND F21 have values then D22=(B19:B20/2)
if D21 AND F21 AND H21 have values then D22=(B19:B20/3)
Basically calculate regardless of the order of columns but only accounting for the number of columns that have a value.
These are the formulas I have so far but they only calculate if the columns are in order (A, B, C, D) not random (A, C, H):
=IF((D21>0)*AND(E21>0)*AND(F21>0)*AND(G21>0)*AND(H21>0)*AND(I21>0),(B19/6),IF((D21>0)*AND(E21>0)*AND(F21>0)*AND(G21>0)*AND(H21>0),(B19/5),IF((D21>0)*AND(E21>0)*AND(F21>0)*AND(G21>0),(B19/4),IF((D21>0)*AND(E21>0)*AND(F21>0),(B19/3),IF((D21>0)*AND(E21>0),(B19/2),IF((D21>0),B19,0))))))
=IF((E21=0),0,IF((D22>0),D22,IF((E21>0)*AND(F21>0)*AND(G21>0)*AND(H21>0)*AND(I21>0),(B19/5),IF((E21>0)*AND(F21>0)*AND(G21>0)*AND(H21>0),(B19/4),IF((E21>0)*AND(F21>0)*AND(G21>0),(B19/3),IF((E21>0)*AND(F21>0),(B19/2),IF((E21>0),B19,0)))))))
=IF((F21=0),0,IF((D22>0),D22,IF((E22>0),E22,IF((F21>0)*AND(G21>0)*AND(H21>0)*AND(I21>0),(B19/4),IF((F21>0)*AND(G21>0)*AND(H21>0),(B19/3),IF((F21>0)*AND(G21>0),(B19/2),IF((F21>0),B19,0)))))))
=IF((G21=0),0,IF((D22>0),D22,IF((E22>0),E22,IF((F22>0),F22,IF((G21>0)*AND(H21>0)*AND(I21>0),(B19/3),IF((G21>0)*AND(H21>0),(B19/2),IF((G21>0),B19,0)))))))
=IF((H21=0),0,IF((D22>0),D22,IF((E22>0),E22,IF((F22>0),F22,IF((G22>0),G22,IF((H21>0)*AND(I21>0),(B19/2),IF((H21>0),B19,0)))))))
=IF((I21=0),0,IF((D22>0),D22,IF((E22>0),E22,IF((F22>0),F22,IF((G22>0),G22,IF((H22>0),H22,IF((I21>0),B19,0)))))))