+ Reply to Thread
Results 1 to 8 of 8

Named range self-referencing offset

  1. #1
    Registered User
    Join Date
    07-09-2010
    Location
    Toronto
    MS-Off Ver
    Excel 2007
    Posts
    5

    Named range self-referencing offset

    Hi all,

    I'm trying to figure out how to create a formula for a named range that returns a value a constant offset from wherever the named range is called.

    Assume a worksheet with the following data:

    Please Login or Register  to view this content.
    I'm looking to make a named range that returns an offset value using the cell in which the range is called as the offset function's reference.

    For example, if my offset is [rows]0 [columns]-1, and my range is named 'OffsetReturn', when I put the formula =OffsetReturn in cell C1 I'll get the value Bob. In C2 I'll get Sue and in C3 I'll get Joe.

    If my offset is [rows]1 [columns]-2, when I put the formula =OffsetReturn in cell C1 I'll get the value 42, in cell C2 I'll get 99 and in cell C3 I'll get 0 (or an error, since there's no data in A4 to be returned by OffsetReturn).

    I've tried this formula in a named range: =offset(indirect(cell("address")),0,-1) but the cell function is volatile and is based on whatever the active cell is when the book re-calculates (usually on change).

    Anyone have any ideas? For my context I can't use VBA, it's gotta be a function (that won't trigger security errors).

    I'd appreciate any help!

    Thanks,
    Keith
    Last edited by kmacd; 03-11-2011 at 12:14 PM.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Named range self-referencing offset

    On Sheet1, select C1 and do Insert > Name > Define Sheet1!relLeft refers to: Sheet1!B1 (no $ signs).

    Enter =relLeft in in any cell on Sheet1 and it will return the value of the cell to the left.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Forum Contributor bentleybob's Avatar
    Join Date
    02-27-2009
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2010
    Posts
    644

    Re: Named range self-referencing offset

    I'd modify your last formula (for cell C1) to be:

    =offset(indirect(cell("address",C1)),0,-1)

    to get "Bob" or -2 to get "25".

  4. #4
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243

    Re: Named range self-referencing offset

    hi Keith,

    Welcome to the Forum

    What about using the oldie, but still, a goody, of the Vlookup function?
    It would remove the volatility of using offset but still allow some flexibility to change your returned column.

    I've taken the liberty of suggesting a modified Layout of:
    row 1 for the sheet header,
    row 2 for parameters/subtotals etc
    row 3 for column headers
    row 4 as the first data row (the "original row 1")

    Then entering the below formulae...
    [code]cell C2 = what ever column you want returned (as a number)
    cell C4 (& copied down) =VLOOKUP($A4,$A$4:$B$6,$C$2,0) [code]

    If you wanted to be slightly fancier, you could use data validation to build a list of column headers to choose from which gives a dropdown in cell C2, then replace the "$C$2" in the vlookup with a Match function* that converts the selected text from the C2 dropdown into a column number.
    *Personally, I would put the Match function in a separate cell (such as c1 or swap so it's in c2 (with the list in C1)) or in a named range and then refer to this cell/named range, this approach means it would only be calculated once instead of once for every cell with the vlookup formula.

    Of course the above approach could also be modified to work within in named range like Shg's suggestion...

    hth
    Rob
    Rob Brockett
    Kiwi in the UK
    Always learning & the best way to learn is to experience...

  5. #5
    Registered User
    Join Date
    07-09-2010
    Location
    Toronto
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Named range self-referencing offset

    Hi all,

    Wow, thanks so much for all the replies! Very much appreciated.

    @shg - this solves the problem exactly, thanks so much. I didn't realise that you could use relative reference in named ranges which would be relative to where the named range is called (seems kinda obvious now). Thanks again!

    @bentleybob - I tried playing around with your suggestion but the cell function evaluates based on the cell that's selected at the time of calculation, *not* based on the cell where the named range is called.

    @broro183 - vlookup isn't an option for my particular problem, meaning this is a small piece of a bigger question and rearranging my data to make vlookup happy isn't really possible, but thanks for the suggestion.

    Thank you all! Not sure exactly how to mark this [solved]...

    Keith

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Named range self-referencing offset

    I didn't realise that you could use relative reference in named ranges
    I use a bunch of standard names ranges in my template sheets Book.xlt and Sheet.xlt. Here are two:

    Me (refers to the cell in which the reference appears). Suppose you have a named range tbl that starts in A2, and you want to show the sum of the column where the formula appears (the formula is not in the table). Then you can use this draggable formula: =INDEX(tbl, 0, COLUMNS($A$2:Me))

    relAbv refers to the cell above, so you can do =SUM(A1:relAbv). You can insert rows immediately above the formula and they will always be captured in the sum.

  7. #7
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243

    Re: Named range self-referencing offset

    hi Keith,

    The FAQ section mentions how to mark threads as Solved (http://www.excelforum.com/faq.php).

    Shg's got you sorted for your current issue but if you are interested in learning an alternative to Vlookup, have a read of the below link on Charles' site, esp the section titled "VLOOKUP versus INDEX and MATCH or OFFSET".
    http://www.decisionmodels.com/optspeede.htm
    (in fact, I recommend reading the whole site!)

    These pages may explain the Index/Match concept more clearly: http://www.mrexcel.com/articles/exce...ndex-match.php or http://www.ozgrid.com/Excel/left-lookup.htm

    Rob

  8. #8
    Registered User
    Join Date
    07-09-2010
    Location
    Toronto
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Named range self-referencing offset

    Hi again!

    Thanks shg, some excellent suggestions. I'll play with these over the next few sheets I deal with.

    Thanks also broro183, I'm already familiar with the index/match combo and using offset for lookups, very handy in certain circumstances.

    Thanks again, very very much appreciated!
    Keith
    Last edited by kmacd; 03-11-2011 at 12:36 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1