Fair point Arno, should probably have been clearer and a missing bracket
doesn't help

=if(sum("data range")=0,"your error value",yourformula)
In this case the error is caused by having no data in the "data range" so by
just checking for the existence of data to average it is possible to reduce
the length of the formula.
My suggestion is to check for the cause of the error at the basest level and
deal with it there. I have inherited some horrendous formulas that cover 4-5
rows on the screen and 60% of it can be removed by a simple error check like
the one above.
It will be different cases as with your lookup example. In your second
example I could go back to the formula being used in B1 and deal with the
cause of the error there. But the example is so short it probably wouldn't be
worth the effort.
But faced with (simplified):
=IF(ISERROR(IF((IF(($B$1>=CM$7),VLOOKUP($A27,'[Flows Data Sheet.xls]1105
Inv'!$A$4:$HH$1000,'TS'!CM$8,0),(CM36-CM31+CM40+CM41)))<0,0,(IF(($B$1>=CM$7),VLOOKUP($A27,'[Flows
Data Sheet.xls]1105
Inv'!$A$4:$HH$1000,'TS'!CM$8,0),(CM36-CM31+CM40+CM41))))),0,(IF((IF(($B$1>=CM$7),VLOOKUP($A27,'[Flows
Data Sheet.xls]1105
Inv'!$A$4:$HH$1000,'TS'!CM$8,0),(CM36-CM31+CM40+CM41)))<0,0,(IF(($B$1>=CM$7),VLOOKUP($A27,'[Flows
Data Sheet.xls]1105 Inv'!$A$4:$HH$1000,'TS'!CM$8,0),(CM36-CM31+CM40+CM41))))))
Which can be reduced to:
=IF(ISNA(VLOOKUP($A27,'[Flows Data Sheet.xls]1105
Inv'!$A$4:$HH$1000,'TS'!CM$8,0)),0,(IF((IF(($B$1>=CM$7),VLOOKUP($A27,'[Flows
Data Sheet.xls]1105
Inv'!$A$4:$HH$1000,'TS'!CM$8,0),(CM36-CM31+CM40+CM41)))<0,0,(IF(($B$1>=CM$7),VLOOKUP($A27,'[Flows
Data Sheet.xls]1105 Inv'!$A$4:$HH$1000,'TS'!CM$8,0),(CM36-CM31+CM40+CM41)))))
by simply testing the root of an error, you can why I suggest that approach.
Giz