Here's a possible function only solution. The final result will look like:

We will use four(4) primary functions:
- ADDRESS
- INDIRECT
- MATCH
- LEFT
Note: Just follow the link if you have question on how to use these functions
The formula: This is in cell C4 Above
=AVERAGE(
INDIRECT(
"'"& C$3 & "'!" &
LEFT(ADDRESS(1,MATCH($E$2,INDIRECT("'"&C$3&"'!1:1"),0),4,1),1)
& ":" &
LEFT(ADDRESS(1,MATCH($E$2,INDIRECT("'"&C$3&"'!1:1"),0),4,1),1)
)
)
Edit1: To handle the comment below for headers beyond 26, change this
LEFT(ADDRESS(1,MATCH($E$2,INDIRECT("'"&C$3&"'!1:1"),0),4,1),1)
to this:
SUBSTITUTE(ADDRESS(1,MATCH($E$2,INDIRECT("'"&C$3&"'!1:1"),0),4,1),"1","")
Basically what is does is:
Find where the header Bean
is located using MATCH
function. To do that, you will have to incorporate the use of INDIRECT
since your sheet name is dynamic (in this example, your sheet name is in C3 - Data1
). (I assumed all your headers are in 1st row, I use 1:1
in there). Note: In this example, Bean
is in column H of Data1 sheet
MATCH($E$2,INDIRECT("'"&C$3&"'!1:1"),0) <~~ returns 8
After finding where it is, we need to get the entire column address so we can apply counting and summing functions (e.g. SUM,COUNT,AVERAGE
etc...). To do that we use the ADDRESS
function combined with LEFT
to get the column letter.
LEFT(ADDRESS(1,MATCH($E$2,INDIRECT("'"&C$3&"'!1:1"),0),4,1),1) <~~ returns H
Then we just repeat that formula and connect it with :
to get H:H
Now that we have the column address, we simply connect it again with the sheet name and apply the final INDIRECT
function plus the counting and/or summing function of your choice.
Sample formula of Total in C5
:

Sample formula of Max in C6
:

Finally, all you have to do is copy the formula across all columns with sheet name.
Just add sheet names beside the last one and copy formula. That's it. I hope this is close to what you want and I hope that all the functions I used are available in Excel 2000.