Averaging Elements of Non-Contiguous Columns in a Named Range

studious

New Member
Joined
Aug 23, 2015
Messages
11
  • I have thousands of columns.
  • I want to average over some of them.
  • They are not adjacent.

I have created named ranges using concatenate because the column headers have an easy-to-follow structure. So, I have narrowed the column combinations to 19 named ranges, which contain the columns that I need and all rows. I am trying to average the values of the columns for each row like so:

Code:
AVERAGE(INDEX(HORRIBLE_RANGE_1,2,))

What I thought this means is, average the second row of HORRIBLE_RANGE_1. But, I think what it does is to just give me the very first value instead of the average of all the values for the columns in that HORRIBLE_RANGE_1.

I have seen suggestions with wretched formulas the length of newspaper articles.

Can anyone offer an elegant solution?

Thank you!
 
Last edited:

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
If you're using NamedRanges, you should be able to use the Average Worksheet function like this:


Excel 2010
BCDEF
21055.6
3103
426
578
6104
729
845
991
1076
1131
Sheet1
Cell Formulas
RangeFormula
F2=AVERAGE(Range1,Range2)
Named Ranges
NameRefers ToCells
Range1=Sheet1!$B$2:$B$11
Range2=Sheet1!$D$2:$D$11
 
Upvote 0
Thanks for the reply. Maybe I didn't explain it well, but here it is. My named range contains, say columns B D F and I would like to get the average for B D F for each row. In reality it is more tedious because I have literally a thousand columns, which I have neatly covered in 19 named ranges. However, I can't seem to use the named ranges to do what I aim to.
 
Upvote 0
Excel really does not handle multi-area selections well. Some functions will handle the whole range OK "SUM(Horrible_Range_1)" and some, like INDEX, make an attempt to reference the different areas, but overall it just doesn't work well. I tried for a bit to come up with something but came up short.

However, I did create a UDF (User-Defined Function) that does the ticket, and it's pretty simple.

1) Open your workbook.
2) Right click on the sheet tab on the bottom and select View Code.
3) From the VBA menu, click Insert > Module.
4) Paste the following code into the window that opens:
Code:
Public Function AvgRangeRow(ByRef rng As Range, ByVal r As Long) As Double

    AvgRangeRow = WorksheetFunction.Average(Intersect(rng, ActiveSheet.Rows(r)))
    
End Function
5) Press Alt-Q to close the editor.

Now just enter your function like this:

=AvgRangeRow(Horrible_Range_1,2)

Your ranges and formulas should be on the same sheet.

It's just a 1-line UDF, pretty simple. If the Intersect command were available in native Excel, a native formula would be easy. Hope this helps.
 
Upvote 0
Thanks, Eric. That's genius!

I've been banging my head over this for two days and nothing worked. I was just in the process of replacing my formulas with rather large AVERAGEIFS.

Never imagined it would be so hard. I am incredibly grateful for your solution, but I think I am staying away from multi-area selections from now on.
 
Upvote 0

Forum statistics

Threads
1,223,275
Messages
6,171,126
Members
452,381
Latest member
Nova88

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top