try this array formula:
=MAX(IF($A$2:$A$794=G2,IF($C$2:$C$794=H2,$D$2:$D$794)))-MIN(IF($A$2:$A$794=G2,IF($C$2:$C$794=H2,$D$2:$D$794)))
Array Formulae are a little different from ordinary formulae in that they MUST be confirmed by pressing CTRL+SHIFT+ENTER to activate the array, not just ENTER.
You will know the array is active when you see curly brackets { } - or "curly braces" for those of you in the USA, or "flower brackets" for those of you in India - appear around the outside of your formula. If you do not use CTRL+SHIFT+ENTER you will (almost always) get an error message or an incorrect answer. Press F2 on that cell and try again.
Don't type the curly brackets yourself - it won't work...
Bookmarks