+2  A: 

=MAX( MAX( sum(A1:A5), sum(A7:A11) ) - sum(A13:A17), 0)

Jimmy
Thanks. It seems to work mauch faster than may array.
A: 
This should have been an edit to your orignial post, or a comment to Jimmy's answer
Draemon
A: 

You may want to look into the VB Macro editor. In the Tools Menu, go to Macros and select Visual basic Editor. This gives a whole programming environment where you can write your own function.

VB is a simple programming language and google has all the guidebooks you need.

There, you can write a function like MySum() and have it do whatever math you really need it to, in a clear way written by yourself.

I pulled this off google, and it looks like a good guide to setting this all up. http://office.microsoft.com/en-us/excel/HA011117011033.aspx

Karl
A: 

This seems to work:

{=SUM(IF(A1:A5>A7:A11,A1:A5-A13:A17,A7:A11-A13:A17))}

EDIT - doesn't handle cases where subtraction ends up negative

This works - but is it more efficient???

{=SUM(IF(IF(A1:A5>A7:A11,A1:A5,A7:A11)>A13:A17,IF(A1:A5>A7:A11,A1:A5,A7:A11)-A13:A17,0))}
DJ
It is pretty much the same as my original formula
True - but I only do the subtract once
DJ
A: 
Sorry 190 is correct! - your original is wrong. 120-50 = 70, 40 - 50 = -10, (70 - 10 + 70 - 10 + 70) = 190
DJ
oops - I guess you are throwing out negative values
DJ
This should have been an edit to your orignial post, or a comment to DJ's answer
Draemon
A: 

What about this?

=MAX(SUM(IF(A1:A5>A7:A11, A1:A5, A7:A11))-SUM(A13:A17), 0)

Edit:

Woops - Missed the throwing out negatives part. What about this? Not sure it it's faster...

=SUM((IF(A1:A5>A7:A11,IF(A1:A5>A13:A17,A1:A5,A13:A17),IF(A7:A11>A13:A17,A7:A11,A13:A17))-A13:A17))

Edit 2:

How does this perform for you?

=SUM((((A1:A5>A13:A17)+(A7:A11>A13:A17))>0)*(IF(A1:A5>A7:A11,A1:A5,A7:A11)-A13:A17))
Nathaniel Reinhart
Thanks for the suggestion. I tested the formula you suggested using a worksheet profiler, and it showed marginal difference between the two formulas in relation to calculation speed.
+1  A: 

A more calculation-efficient (and especially re-calculation efficient) way is to use helper columns instead of array formulae:

C1: =MAX(A1,A7)-A13

D1: =IF(C1>0,C1,0)

copy both these down 5 rows

E1: =SUM(D1:D5)

Excel will then only recalculate the formulae dependent on any changed value, rather than having to calculate all the virtual columns implied by the array formula every time any single number changes. And its doing less calculations even if you change all the numbers.