Excel averageifs by looking up column for criteria
<p>I have a spreadsheet that looks like this:
<a href="https://i.stack.imgur.com/rbNHP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rbNHP.png" alt="enter image description here"></a></p>

<p>The data is in the coloured section, to the right of that is a table that shows the average of the result column when the data under ABC, XYZ, or GGG is inbetween the Max and Min Value.</p>

<p>This was done with this formula: <code>=AVERAGEIFS($D$4:$D$27,A$4:A$27,"&lt;"&amp;$F5,A$4:A$27,"&gt;"&amp;$G5)</code></p>

<p>What I want to do is have that formula reference the heading and then lookup the appropriate column in the data table to apply the averageif criteria to.</p>

<p>The formula I have now works fine but as I add more columns and the data table that may be out of order it would be much better if I was able to incorporate a lookup or match into the averageifs formula.</p>