Problem with named ranges

JenniferMurphy

Well-known Member
Joined
Jul 23, 2011
Messages
2,546
Office Version
  1. 365
Platform
  1. Windows
I swear I've done this before, but it's not working today and I cannot figure out why.

In the table below, I have assigned the name "Header" to row 6 and "Footer" to row 12. In C12, I calculate the average of the ratings in C7:C11. In C13, I try to do the same thing, but using the named ranges. Why isn't it working?
C/RCD
Header->6Rating
75
84
93
102
111Formula
Footer->123.00C12: =AVERAGE(C7:C11)
134.00C13: =AVERAGE(OFFSET(Header,1,0):OFFSET(Footer,-1,0))
146C14: =ROW(Header)
1512C15: =ROW(Footer)
165C16: =OFFSET(Header,1,0)
171C17: =OFFSET(Footer,-1,0)
187C18: =ROW(OFFSET(Header,1,0))
191C19: =COLUMN(OFFSET(Header,1,0))
2011C20: =ROW(OFFSET(Footer,-1,0))
211C21: =COLUMN(OFFSET(Footer,-1,0))

<tbody>
</tbody>
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
it is Ok if range is not blank

Code:
Sub MakeRange()
Cells.Clear
    ThisWorkbook.Names.Add Name:="Header", RefersTo:="=Sheet1!$C$1:$C$6"
    ThisWorkbook.Names.Add Name:="Footer", RefersTo:="=Sheet1!$C$7:$C$12"
    T = Split(",5,4,3,2,1", ",")
    For R = LBound(T) + 6 To UBound(T) + 6
    Cells(R, 3) = T(R - 6)
    Next
    [C12] = "=AVERAGE(C7:C11)"
    [C13] = "=AVERAGE(OFFSET(Header,1,0):OFFSET(Footer,-1,0))"
    [C14] = "=ROW(Header)"
    [C15] = "=ROW(Footer)"
    [C16] = "=OFFSET(Header,1,0)" '????
    [C17] = "=OFFSET(Footer,-1,0)" ' ????
    [C18] = "=ROW(OFFSET(Header,1,0))"
    [C19] = "=COLUMN(OFFSET(Header,1,0))"
    [C20] = "=ROW(OFFSET(Footer,-1,0))"
    [C21] = "=COLUMN(OFFSET(Footer,-1,0))"


End Sub
 
Last edited:
Upvote 0
Hi Jennifer Murphy,
are you sure you understood the meaning of namedranges?
If yes, isn't it easier to name range C7:C11 as myaverage and then use in C13 =AVERAGE(MYAVERAGE) ?
 
Upvote 0
... I have assigned the name "Header" to row 6 and "Footer" to row 12. In C12, I calculate the average of the ratings in C7:C11. In C13, I try to do the same thing, but using the named ranges. Why isn't it working?..
Because =AVERAGE(OFFSET(Header,1,0):OFFSET(Footer,-1,0)) is equivalent to =AVERAGE(7:11)

If you want to get =AVERAGE(C7:C11), try =AVERAGE(OFFSET(Header,1,0):OFFSET(Footer,-1,0) C:C)
 
Upvote 0
Because =AVERAGE(OFFSET(Header,1,0):OFFSET(Footer,-1,0)) is equivalent to =AVERAGE(7:11)
That was an interesting puzzle. It took me awhile to figure out that average(7:11) is the average of all the numeric values in rows 7 thru 11, right?

In that case, what would the expression be for the average of all of the numeric values in columns 7 to 11?

If you want to get =AVERAGE(C7:C11), try =AVERAGE(OFFSET(Header,1,0):OFFSET(Footer,-1,0) C:C)
That works. Amazing. This is the Space operator, right? I keep forgetting that one. So it's the average of the intersection of rows 7-11 and column C, right?

In the table below, I applied your formula in C13 and it works perfectly. But I am puzzled as to why my formula fails. In C14 & C15, I put the two arguments and they return the correct values. In C16:C19, I calculate the row and column values for these two arguments. The rows are correct (7 & 11), but the columns are not (1). Why is that?

C/RCDEF
Header->6RatingWeightRatingFormula
750.000.00E7: =Rating*Weight
840.251.00E8: =Rating*Weight
930.501.50E9: =Rating*Weight
1020.751.50E10: =Rating*Weight
1111.001.00E11: =Rating*Weight
Footer->123.002.502.00C12: =AVERAGE(C7:C11)
133.00C13: =AVERAGE(OFFSET(Header,1,0):OFFSET(Footer,-1,0) C:C)
145C14: =OFFSET(Header,1,0)
151C15: =OFFSET(Footer,-1,0)
167C16: =ROW(OFFSET(Header,1,0))
171C17: =COLUMN(OFFSET(Header,1,0))
1811C18: =ROW(OFFSET(Footer,-1,0))
191C19: =COLUMN(OFFSET(Footer,-1,0))

<tbody>
</tbody>

I have assigned the name Rating to Column C and Weight to Column D. This makes the formulas in Column E work perfectly. Why does this work and the Average formula does not?

Thanks
 
Upvote 0
I regret I cannot help further as I do not understand [C12] = "=AVERAGE(C7:C11)"

The values in Column D are the formulas in Column C. I have a little UDF that will return the expression in any cell. It prefixes the result with the cell address. So, "[C12] =AVERAGE(C7:C11)" simply means that cell C12 contains the expression "=AVERAGE(C7:C11)".
 
Upvote 0
Hi Jennifer Murphy,
are you sure you understood the meaning of namedranges?
Yes, I think so.
If yes, isn't it easier to name range C7:C11 as myaverage and then use in C13 =AVERAGE(MYAVERAGE) ?
I don't know if it's easier or not, but it doesn't do what I want. If I name C7:C11, then I have to be careful when I add or delete rows or the range will not change accordingly. If I name the row above the range (Header) and the one below (Footer), then I can add or delete rows anywhere in between and the formula will continue to work correctly.

Do you understand the meaning of that?
 
Upvote 0
So, "[C12] =AVERAGE(C7:C11)" simply means that cell C12 contains the expression "=AVERAGE(C7:C11)".

as I said, I am on a learning curve here.

If you add 100 rows between rows 8 and 9 how does this work, please ?
 
Upvote 0

Forum statistics

Threads
1,216,211
Messages
6,129,528
Members
449,515
Latest member
lukaderanged

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